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

[MediaBundle]: bulk move media in folders #1882

Merged
merged 1 commit into from Apr 5, 2018

Conversation

sandergo90
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets #1333

This PR adds to possibility to move media in bulk to another folder.

screen shot 2018-03-30 at 15 53 19
screen shot 2018-03-30 at 15 53 26
screen shot 2018-03-30 at 15 53 35


foreach ($mediaIds as $mediaId) {
/** @var Media $media */
$media = $mediaRepo->getMedia($mediaId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fetching from database in a loop? Not a good idea. A simple UPDATE query would do fine here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlebkowski Correct! Changed ;)

$mediaIds = explode(',', $form->getData()['media']);

foreach ($mediaIds as $mediaId) {
$mediaRepo->moveToFolder($mediaId, $folder->getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still executing queries in a loop. I was thinking more like:

$mediaRepo->createQueryBuilder('media')
    ->update()
    ->set('media.folder', $folder->getId())
    ->where('media.id in (:mediaIds)')
    ->setParameter('mediaIds', $mediaIds)
    ->getQuery()
    ->execute();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, didn't see that ;) I've changed it now.

Change save to update query

Change to one update query

Remove moveToFolder action
@Numkil Numkil merged commit 11f8f78 into Kunstmaan:master Apr 5, 2018
@sandergo90 sandergo90 deleted the feature/media-move branch April 5, 2018 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants