Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear menu caches on content delete. Log delete event. #1824

Merged
merged 3 commits into from
Sep 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/Event/Subscriber/ContentSaveSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(TagAwareCacheInterface $cache)

public function postSave(ContentEvent $event): ContentEvent
{
// Make sure we flush the cache for the menu's
// Make sure we flush the cache for the menus
$this->cache->invalidateTags(['backendmenu', 'frontendmenu']);

// Saving an entry in the log.
Expand All @@ -39,10 +39,34 @@ public function postSave(ContentEvent $event): ContentEvent
return $event;
}

public function preDelete(ContentEvent $event): ContentEvent
{
// Saving an entry in the log now. post_delete doesn't have content anymore.
$context = [
'content_id' => $event->getContent()->getId(),
'content_type' => $event->getContent()->getContentType(),
'title' => $event->getContent()->getExtras()['title'],
];

$this->logger->info('Deleted content "{title}" ({content_type} № {content_id})', $context);

return $event;
}

public function postDelete(ContentEvent $event): ContentEvent
{
// Make sure we flush the cache for the menus
$this->cache->invalidateTags(['backendmenu', 'frontendmenu']);

return $event;
}

public static function getSubscribedEvents()
{
return [
ContentEvent::POST_SAVE => ['postSave', self::PRIORITY],
ContentEvent::PRE_DELETE => ['preDelete', self::PRIORITY],
ContentEvent::POST_DELETE => ['postDelete', self::PRIORITY],
];
}
}