craftcms / craftcms/cms

[4.x]: EVENT_*_REPLACE_ASSET not Triggered on Replace Asset via GraphQL

Open
#17,645 2 comments 0 reactions 1 assignee View on GitHub

@i-just is already working on this.

Since Jul 23, 2025.

bug craft4
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

Related to https://github.com/craftcms/cms/issues/17005

We were still able to Reproduce the Bug where an Asset replaced via GraphQL does not trigger der REPLACE Event. So the ImagerX Caching is failing on our end. I was able to narrow the problem down to 'src/gql/resolvers/mutations/Asset.php' . I logged the content of the variable $triggerReplaceEvents in the Line 109( https://github.com/craftcms/cms/pull/17031/files#diff-bfc202d2c98b90d6fda74ee2101b2337b022d6b1278e8892e0ee046db6d8ecc3R109 ) , while line 110 evalutes correctly, somehow line 111 never gets evaluated to 'true'. This leads to the Situation that the Eventtrigger in if clause on Line 114 and 124 never resolves. You can easily Test this by writing some generic logmessages into the if clauses and replace an Asset via GraphQL. If needed, I can provide you with a project config, an DB dump. If you need clarification on any point I'm happy to help.

Steps to reproduce
  1. Try Log some Message in https://github.com/craftcms/cms/pull/17031/files#diff-bfc202d2c98b90d6fda74ee2101b2337b022d6b1278e8892e0ee046db6d8ecc3R114 and/or https://github.com/craftcms/cms/pull/17031/files#diff-bfc202d2c98b90d6fda74ee2101b2337b022d6b1278e8892e0ee046db6d8ecc3R114 and inspect the $triggerReplaceEvents variable
  2. Replace an Asset via GraphQL
  3. Observe the Logs are never written and the var does not evaluate to try
  4. as a result the events EVENT_BEFORE_REPLACE_ASSET & EVENT_AFTER_REPLACE_ASSET are never triggered
Expected behavior

events EVENT_BEFORE_REPLACE_ASSET & EVENT_AFTER_REPLACE_ASSET are triggered when replacing Assets via GraphQL

Craft CMS version

4.15.3 Pro

PHP version

8.2.22

Operating system and version

Linux 6.8.0-64-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

Name & Version

  • Blitz 4.23.14
  • Cloner 2.0.4
  • Control Panel CSS 2.6.0
  • Cookies 4.0.1
  • Dates & Opening Hours dev-main
  • Embedded Assets 4.2.3
  • Glossary 2.0.1
  • Hyper 1.3.7
  • Imager X 4.5.2
  • Incognito Field 1.3.0
  • Inventory 2.2.0
  • KeyChain 4.0.0
  • Matrix Colors 3.0.0
  • Minify 4.0.1
  • Neo 4.4.1
  • Publisher X 3.0.1
  • Redactor 3.1.0
  • Redactor Anchors 1.5.0
  • Relax 2.0.2
  • Sprig 2.14.1
  • SuperSort 4.0.0
  • Super Table 3.0.15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.