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

Probably copying from MediaCollection to singleFile MediaCollection works weird #3603

Open
drnkwtr opened this issue May 6, 2024 · 2 comments

Comments

@drnkwtr
Copy link

drnkwtr commented May 6, 2024

I registered 2 media collections:

<?php
  public function registerMediaCollections(): void
  {
      $this->addMediaCollection('images');
      $this->addMediaCollection('thumbnail')
          ->singleFile();
  }

Then uploading some images by

<?php
  public function uploadImages(Request $request, $id)
  {
      $files = $request->allFiles()['images'];
      foreach($files as $uploaded_file) {
          Modification::find($id)
              ->addMedia($uploaded_file)
              ->toMediaCollection('images');
      }

And then selecting thumbnail by this (copied image replaces thumbnail for newer)

<?php
  public function selectThumbnail($mod_id, $file_id)
  {
      Media::find($file_id)->copy(Modification::find($mod_id),'thumbnail');

      return back();
  }

But for some reason copying to another collection works weird. I can copy file with incrementing id's, but can't with decrementing id's.

Example: uploaded 4 files with id=1, id=2, id=3, id=4. Selecting thumbnail with id=1 - ok, selecting id=2 - ok, selecting id=3 - ok, but now i can't choose thumbnail with file id=1 and id=2, only higher than selected id now

Is it only my fault or actually bug?

UPD: Seems like that problem is described here: issue

@drnkwtr drnkwtr changed the title Probably copying from MediaCollection to singleFile Collection works weird Probably copying from MediaCollection to singleFile MediaCollection works weird May 6, 2024
@drnkwtr
Copy link
Author

drnkwtr commented May 7, 2024

    public function selectThumbnail($mod_id, $file_id)
    {
        $media = Media::find($file_id)->copy(Modification::find($mod_id),'thumbnail');
        $media->order_column = 1;
        $media->save();
        return back();
    }

This is the fix of this issue. I think, new media should be copied with order_column depends on count of collection medias.

@patinthehat
Copy link
Collaborator

@drnkwtr I'd be happy to take a look at a PR with failing unit tests that show the issue, as all of the tests are currently passing. Thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants