-
Notifications
You must be signed in to change notification settings - Fork 672
[4.x]: Updating Assets via GraphQL does not trigger EVENT_AFTER_REPLACE_ASSET #17005
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
Comments
Hi, thanks for reaching out! The mutation that’s used to replace a file is actually a That said, you could still detect if the file is being replaced based on the asset’s scenario. If the data passed to the mutation has the file info and an ID was provided, the scenario will be set to ‘replace’. I hope this helps! I’ll close this now, but feel free to reply if you run into any further issues. |
Hi Iwona, This is related to an issue they're seeing with my plugin, where I use Assets::EVENT_AFTER_REPLACE_ASSET to remove stale transforms when an asset file is replaced. But based on what you're saying, I should be using |
Without having it verfified in detail we also believe that Blitz Cache has the same problem (it suffers from the missing event). And my opinion about closing this: It should not make a difference, if the image gets replaced via GUI or GraphQL. The event should be fired. |
@aelvan, the That said, we would like to talk about it more internally. I’ll post a reply once we had a chance to do so! |
Thanks all for your patience on this one! We discussed this internally and decided to trigger the |
Craft 4.14.14 and 5.6.16 are out with that change 🎉 |
What happened?
Description
When updating an asset via GraphQL the EVENT_AFTER_REPLACE_ASSET is not triggered.
Steps to reproduce
Upload an asset to Craft
Create a module with the EVENT_AFTER_REPLACE_ASSET and just throw an Error
Event::on( Assets::class, Assets::EVENT_AFTER_REPLACE_ASSET, function (ReplaceAssetEvent $event) { throw new Error('Some Errormsg'); } );
Create a mutation with payload that replaces the Asset
mutation AssetMutation( $id: ID, $folderId: ID, $document: FileInput, $title: String, ) { save_images_Asset( _file: $document, title: $title, id: $id newFolderId: $folderId ) { id folderId title } }
Payload is the output of the following php fun
public function assetPayload(string $fileData, array $image): String { $payload = [ 'id' => $image['id'], 'folderId' => $image['folderId'], 'title' => $image['name']', 'document' => [ 'filename' => $image['name'], 'fileData' => "data:image/jpg;base64," . $fileData ], ]; return json_encode($payload); }
Replace an Asset via Crafts native backend and observe an error is thrown
Run the mutation for the same Asset and see no Error is thrown
Expected behavior
When updating an Asset via GraphQL the EVENT_AFTER_REPLACE_ASSET and EVENT_BEFORE_REPLACE_ASSET are triggered.
Actual behavior
Said events are not triggered.
Craft CMS version
Craft CMS 4.14.11 Pro
PHP version
PHP 8.2.22
Operating system and version
Linux 6.8.0-56-generic
Database type and version
PostgreSQL 12.14
Image driver and version
Imagick 3.7.0 (ImageMagick 6.9.11-60)
Installed plugins and versions
No response
The text was updated successfully, but these errors were encountered: