Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Closed
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! 👍

@spatie spatie locked and limited conversation to collaborators Jun 17, 2024
@freekmurze freekmurze converted this issue into discussion #3644 Jun 17, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants