Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folders: Fix Folders appear empty but cannot be deleted due to old file revisions remaining #2790

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/Controller/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@
$playlist = $this->playlistFactory->getById($parsedBody->getInt('playlistId'));

if ($playlist->isDynamic === 1) {
throw new InvalidArgumentException(__('This Playlist is dynamically managed so cannot accept manual assignments.'), 'isDynamic');

Check warning on line 1175 in lib/Controller/Library.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 145 characters
}
}

Expand Down Expand Up @@ -2731,6 +2731,10 @@

$media->save(['saveTags' => false]);

if ($media->parentId != 0) {
$this->updateMediaRevision($media, $folderId);
}

// Return
$this->getState()->hydrate([
'httpStatus' => 204,
Expand Down Expand Up @@ -2901,4 +2905,19 @@
{
return $this->layoutFactory->getLinkedFullScreenLayout('media', $media->mediaId)?->campaignId;
}

/**
* Update media files with revisions
* @param Media $media
* @param $folderId
*/
private function updateMediaRevision(Media $media, $folderId)
{
$oldMedia = $this->mediaFactory->getParentById($media->mediaId);
$oldMedia->folderId = $folderId;
$folder = $this->folderFactory->getById($oldMedia->folderId);
$folder->permissionsFolderId = ($folder->getPermissionFolderId() == null) ? $folder->id : $folder->getPermissionFolderId();

$oldMedia->save(['saveTags' => false, 'validate' => false]);
}
}
Loading