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.

CommentFileSizeAuthor
#2 3484260.patch726 byteshoanglv

Issue fork purge-3484260

Command icon 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

hoanglv created an issue. See original summary.

hoanglv’s picture

StatusFileSize
new726 bytes
divyansh.gupta’s picture

Assigned: Unassigned » divyansh.gupta

divyansh.gupta’s picture

Assigned: divyansh.gupta » Unassigned
Status: Active » Needs review

Hello @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.

dhruv.mittal’s picture

Status: Needs review » Reviewed & tested by the community

The 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.

nkind’s picture

Status: Reviewed & tested by the community » Needs work

In 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.

liam morland made their first commit to this issue’s fork.

liam morland’s picture

Version: 8.x-3.6 » 8.x-3.x-dev
Status: Needs work » Needs review

I 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.