Skip to main content

Download events

Fired around the lifecycle of an MC\DownloadsManager\Entity\Download. The pre-* hooks run inside the entity's transactional save or delete. Throwing aborts the operation. The post-* hooks run after commit.

Events

EventSignatureWhen
mc_dm_download_pre_create(Download $download)Before INSERT, when the entity is brand new.
mc_dm_download_post_create(Download $download)After INSERT for a brand-new entity.
mc_dm_download_pre_save(Download $download)Before INSERT or UPDATE.
mc_dm_download_post_save(Download $download)After INSERT or UPDATE.
mc_dm_download_pre_delete(Download $download)Before DELETE (soft or hard).
mc_dm_download_post_delete(Download $download)After DELETE.

Pre vs post

Pre-hooks fire inside the entity's save or delete transaction. Throwing aborts the operation. Use these to validate or enrich before the write commits.

Post-hooks fire after the transaction commits. Use these for side effects: webhooks, alerts, reindexing, cache busts.

Create vs save

pre_create and post_create fire only when the entity is brand new ($download->isInsert() === true). pre_save and post_save fire on every save regardless. Use create for new-download notifications. Use save for "anything changed" handlers.

Soft vs hard delete

Both fire pre_delete and post_delete. To tell them apart, inspect $download->download_state. A deleted value indicates a soft-delete already in progress. A row that's visible going through delete is a hard delete.

Example

public static function downloadPostCreate(\MC\DownloadsManager\Entity\Download $download)
{
$download->getRepository('MC\DownloadsManager:Download')
->reindexForSearch($download);
}