Skip to content

IBX-11776: Fixed invalidating files when the content version didn't change#80

Open
Sztig wants to merge 4 commits into
4.6from
IBX-11776-sameversion-file-cache-purge-fix
Open

IBX-11776: Fixed invalidating files when the content version didn't change#80
Sztig wants to merge 4 commits into
4.6from
IBX-11776-sameversion-file-cache-purge-fix

Conversation

@Sztig
Copy link
Copy Markdown
Contributor

@Sztig Sztig commented May 15, 2026

🎫 Issue IBX-11776

Description:

This bug happens when we have a draft and we are making changes in this draft (in our case - the image).
Since the files are served without tagging by default, regular tag invalidation that happens when publishing content is not enough to refresh the changes.
In our logic, since it is still a draft, the content version didn't change ergo the file is presented when published without any changes. Without this fix to see the changes we would need to republish the content once again.
I have added a subscriber BinaryFileHttpCachePurgeSubscriber that explicitly purges the URI for ezimage, ezbinaryfile, and ezmedia when publishing the content.

@Sztig Sztig requested a review from a team May 15, 2026 14:58
@Sztig Sztig force-pushed the IBX-11776-sameversion-file-cache-purge-fix branch from 6eb6655 to 4960e6e Compare May 15, 2026 16:31
@konradoboza
Copy link
Copy Markdown
Contributor

For browser tests to pass you most likely need to backport the following: https://github.com/ibexa/http-cache/pull/78/changes#diff-6f36e7155819d94620ee9ed91d27e6b0c5f9cc9ff1332031dd6263eb9e51d677.

Comment thread tests/lib/EventSubscriber/CachePurge/BinaryFileHttpCachePurgeSubscriberTest.php Outdated
Comment thread tests/lib/EventSubscriber/CachePurge/BinaryFileHttpCachePurgeSubscriberTest.php Outdated
@sonarqubecloud
Copy link
Copy Markdown

$purged = [];

foreach ($content->getFields() as $field) {
$value = $field->value;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use magic where possible.

Suggested change
$value = $field->value;
$value = $field->getValue();

Comment on lines +63 to +77
public function testNoFieldsDoesNotCallPurge(): void
{
$this->proxyClient->expects(self::never())->method('purge');

$this->subscriber->onPublishVersion($this->buildEvent([]));
}

public function testNonBinaryFieldIsSkipped(): void
{
$this->proxyClient->expects(self::never())->method('purge');

$this->subscriber->onPublishVersion($this->buildEvent([
new Field(['value' => new \stdClass()]),
]));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be one test with a data provider

Comment on lines +109 to +131
public function testImageValueWithNullUriIsSkipped(): void
{
$imageValue = new ImageValue();
$imageValue->uri = null;

$this->proxyClient->expects(self::never())->method('purge');

$this->subscriber->onPublishVersion($this->buildEvent([
new Field(['value' => $imageValue]),
]));
}

public function testImageValueWithEmptyUriIsSkipped(): void
{
$imageValue = new ImageValue();
$imageValue->uri = '';

$this->proxyClient->expects(self::never())->method('purge');

$this->subscriber->onPublishVersion($this->buildEvent([
new Field(['value' => $imageValue]),
]));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems these could also be attached to the mentioned data provider.

Comment on lines +79 to +107
public function testImageValueWithUriIsInvalidated(): void
{
$imageValue = new ImageValue();
$imageValue->uri = '/var/site/storage/images/foo.jpg';

$this->proxyClient
->expects(self::once())
->method('purge')
->with('/var/site/storage/images/foo.jpg', []);

$this->subscriber->onPublishVersion($this->buildEvent([
new Field(['value' => $imageValue]),
]));
}

public function testBinaryFileValueWithUriIsInvalidated(): void
{
$binaryValue = new BinaryFileValue();
$binaryValue->uri = '/var/site/storage/original/application/foo.pdf';

$this->proxyClient
->expects(self::once())
->method('purge')
->with('/var/site/storage/original/application/foo.pdf', []);

$this->subscriber->onPublishVersion($this->buildEvent([
new Field(['value' => $binaryValue]),
]));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are also candidates for another data provider + test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants