Skip to content

[FEATURE] Add event when a processed file gets invalidated - #34

Open
achimfritz wants to merge 1 commit into
mainfrom
task/after-processed-file-invalidated
Open

[FEATURE] Add event when a processed file gets invalidated#34
achimfritz wants to merge 1 commit into
mainfrom
task/after-processed-file-invalidated

Conversation

@achimfritz

Copy link
Copy Markdown
Contributor

No description provided.

@achimfritz
achimfritz force-pushed the task/after-processed-file-invalidated branch from 8c826a9 to 1e6ad3b Compare September 1, 2026 11:54
Comment thread README.md
```

**Use `getPublicUrl()` on the event, not on `getProcessedFile()`.** The file is
already deleted by the time this event fires, and `getPublicUrl()` on a deleted

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.

I think this is not quite true looking at the implementation in ProcessedFile

public function getPublicUrl(): ?string
{
    if (isset($this->processingUrl) && $this->processingUrl !== '') {
        return $this->processingUrl;   // <- before the deleted check
    }
    if ($this->deleted) {
        return null;
    }
    …

// already does internally.
$publicUrl = $processedFile->getPublicUrl();
$processedFile->delete(true);
$this->eventDispatcher->dispatch(new AfterProcessedFileInvalidatedEvent($processedFile, $publicUrl, $file));

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.

Unguarded dispatch. A throwing listener aborts the loop and the save.

// null once the file is marked deleted, which delete() itself
// already does internally.
$publicUrl = $processedFile->getPublicUrl();
$processedFile->delete(true);

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.

Maybe we should check the return here?

return $this->publicUrl;
}

public function getOriginalFile(): FileInterface

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.

getOriginalFile(): FileInterface is always a concrete File

// react to the removal, e.g. purge that same variant from a CDN.
//
// $publicUrl is captured before delete() runs, not read back from $processedFile
// here: AbstractFile::getPublicUrl() unconditionally returns null once a file is

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.

the “unconditionally null” premise is false for a processing_url variant, see comment in README

final class AfterProcessedFileInvalidatedEvent
{
public function __construct(
private readonly ProcessedFile $processedFile,

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.

Suggest to either dispatch before the delete, or pass a record instead of the deleted object.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants