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

What's the easiest way to update an existing media ? #18

Closed
nicolasbinet opened this issue Sep 1, 2016 · 6 comments
Closed

What's the easiest way to update an existing media ? #18

nicolasbinet opened this issue Sep 1, 2016 · 6 comments

Comments

@nicolasbinet
Copy link

I'm trying to figure out a way to update a saved media.
Relations can be updated, but not the base file.
Am-I right ?

@frasmage
Copy link
Collaborator

frasmage commented Sep 3, 2016

Hi Nicholas,

What do you mean by update? Media is just an eloquent model, so you can
adjust any of its attributes manually, I.e. $media->mime_type = 'image/jpeg'; then call the save() method to update the records.

(On vacation so I might be slow to reply)

On Sep 1, 2016 4:19 PM, "Nicolas Binet" notifications@github.com wrote:

I'm trying to figure out a way to update a saved media.
Relations can be updated, but not the base file.
Am-I right ?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#18, or mute the thread
https://github.com/notifications/unsubscribe-auth/AA38rDxvACl4rk3pCDph0znCDRZ9aoDfks5qltD6gaJpZM4JyrmK
.

@nicolasbinet
Copy link
Author

Let me know if I'm wrong, but I'm using MediaUploader::fromSource to upload and create a new Media.
But, there is no "updateFromSource" method to update an existing one.

@frasmage
Copy link
Collaborator

frasmage commented Sep 6, 2016

Hi Nicolas,

What exactly has changed between the file on disk and the data stored in
the db record?

For the most part, the library considers media files to be constant once
uploaded, as this fits with the most common usage. That said, if you are
manipulating the file and you know what might change (e.g. size, mime,
etc.), you can update the fields manually, as described in the message
above.

You can also simply delete and reimport the media record.

Alternatively, the media:import command has a --force option, which
checks if any files in a directory no longer match their records and update
accordingly.

Finally, adding a proper MediaUploader::update() method is on my to-do
list for the next major or minor version. This would behave like
media:import --force for a single file at a time. Still in the works
though.

Hope this helps.

On Sep 3, 2016 12:56 PM, "Nicolas Binet" notifications@github.com wrote:

Let me know if I'm wrong, but I'm using MediaUploader::fromSource to
upload and create a new Media.
But, there is no "updateFromSource" method to update an existing one.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#18 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA38rNaDO92hkRe9o1Cz_9UGwq0yz_n5ks5qmVJagaJpZM4JyrmK
.

@nicolasbinet
Copy link
Author

Hi frasmage,

Thanks for your extensive answer.

In my case, I'm trying to create a mediamanager the "wordpress way". Have a centralized repositories for medias, and associate them along the way to different models.
And sometimes I will, or one of my client will, want to re-upload a new version of a file, thus updating all it's uses.
In that case I don't want to delete the file, as it would break all relations.

I hope this clarifies my need.

Nicolas

@frasmage
Copy link
Collaborator

frasmage commented Sep 7, 2016

Hi Nicolas,

OK, I see what you mean. The MediaUploader class wouldn't be able to do
that out of the box (though the update feature I'm working on would help).

In the meantime, you could use the uploader to place the file in a temp
location (for validation, media generation, etc.), then manually swap the
two files on disk and update the original record with the attributes of the
new one.

On Sep 7, 2016 7:42 AM, "Nicolas Binet" notifications@github.com wrote:

Hi frasmage,

Thanks for your extensive answer.

In my case, I'm trying to create a mediamanager the "wordpress way". Have
a centralized repositories for medias, and associate them along the way to
different models.
And sometimes I will, or one of my client will, want to re-upload a new
version of a file, thus updating all it's uses.
In that case I don't want to delete the file, as it would break all
relations.

I hope this clarifies my need.

Nicolas


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#18 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA38rGuqAEY50n-Av849m8GGpN3iSFPlks5qnk7DgaJpZM4JyrmK
.

@frasmage
Copy link
Collaborator

Hi @nicolasbinet, this is now implemented in version 2.0, see the docs for instructions on this feature.

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

No branches or pull requests

2 participants