Problem/Motivation
The problem is that if $data['invalidations'] does not have an element at index 0, the token replacement will not work, even if there are other elements in $data['invalidations'].
Steps to reproduce
- Add an HTTP Bundled Purger -> then set the Type to Tag -> set the body to [invalidations:separated_comma]
- Add an HTTP Bundled Purger again -> then set the Type to Path -> set the body to [invalidations:separated_comma]
Proposed resolution
We need to use reset($data['invalidations']) instead of $data['invalidations'][0] for the condition.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3484260.patch | 726 bytes | hoanglv |
Issue fork purge-3484260
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
hoanglv commentedComment #3
divyansh.gupta commentedComment #5
divyansh.gupta commentedHello @hoanglv,
Applied your patch and the changes looks good to me because this can solve the error as by using reset($data['invalidations']), the code will check if there is at least one element in $data['invalidations'], regardless of the key structure.
Please review.
Comment #6
dhruv.mittal commentedThe issue occurs when $data['invalidations'] doesn't have an element at index 0, causing the token replacement to fail. By using reset($data['invalidations']) instead of $data['invalidations'][0], we ensure the first element (or default value if the array is empty) is accessed correctly. This change resolves the issue and improves the robustness of the functionality.
So changes looks good to me so moving it to RTBC.
Comment #7
nkind commentedIn trying this patch on our site with two servers it, for some reason, caused our purge cronjob to error with the following message:
Drupal\purge\Plugin\Purge\Purger\Exception\BadPluginBehaviorException: Only NOT_SUPPORTED, PROCESSING, SUCCEEDED and FAILED are valid outbound states. in Drupal\purge\Plugin\Purge\Invalidation\InvalidationBase->setStateContext()Site is on 10.4.6 with all modules up to date including ultimate cron.
Comment #9
liam morlandI have added the solution written for #3520488: [warning] Undefined array key "invalidation" purge_tokens.module:64. This just removes the error with no side-effects.