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
Conversation
|
||
foreach ($mediaIds as $mediaId) { | ||
/** @var Media $media */ | ||
$media = $mediaRepo->getMedia($mediaId); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mlebkowski Correct! Changed ;)
cd9f9ca
to
96a3ce4
Compare
$mediaIds = explode(',', $form->getData()['media']); | ||
|
||
foreach ($mediaIds as $mediaId) { | ||
$mediaRepo->moveToFolder($mediaId, $folder->getId()); |
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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.
96a3ce4
to
44dd3df
Compare
Change save to update query Change to one update query Remove moveToFolder action
44dd3df
to
8be5802
Compare
This PR adds to possibility to move media in bulk to another folder.