$criteria->
setLimit(1
);
$defaultFolders =
$this->defaultFolderRepository->
search($criteria,
$context->
getContext());
if ($defaultFolders->
count() <= 0
) { return $mediaFolderId;
} /** @var MediaDefaultFolderEntity $defaultFolder */
$defaultFolder =
$defaultFolders->
first();
if ($defaultFolder->
getFolder()) { return $defaultFolder->
getFolder()->
getId();
} $mediaFolderId = Uuid::
randomHex();
$this->folderRepository->
upsert([ [ 'id' =>
$mediaFolderId,
'defaultFolderId' =>
$defaultFolder->
getId(),
'name' =>
$name,
'useParentConfiguration' => false,
'configuration' =>
$configuration,
],