Chris@0: lock = $lock; Chris@0: $this->menuLinkManager = $menu_link_manager; Chris@18: $this->connection = $connection; Chris@18: $this->replicaKillSwitch = $replica_kill_switch; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Rebuilds the menu links and deletes the local_task cache tag. Chris@0: * Chris@0: * @param \Symfony\Component\EventDispatcher\Event $event Chris@0: * The event object. Chris@0: */ Chris@0: public function onRouterRebuild(Event $event) { Chris@0: $this->menuLinksRebuild(); Chris@0: Cache::invalidateTags(['local_task']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Perform menu-specific rebuilding. Chris@0: */ Chris@0: protected function menuLinksRebuild() { Chris@0: if ($this->lock->acquire(__FUNCTION__)) { Chris@18: $transaction = $this->connection->startTransaction(); Chris@0: try { Chris@0: // Ensure the menu links are up to date. Chris@0: $this->menuLinkManager->rebuild(); Chris@0: // Ignore any database replicas temporarily. Chris@18: $this->replicaKillSwitch->trigger(); Chris@0: } Chris@0: catch (\Exception $e) { Chris@0: $transaction->rollBack(); Chris@0: watchdog_exception('menu', $e); Chris@0: } Chris@0: Chris@0: $this->lock->release(__FUNCTION__); Chris@0: } Chris@0: else { Chris@0: // Wait for another request that is already doing this work. Chris@0: // We choose to block here since otherwise the router item may not Chris@0: // be available during routing resulting in a 404. Chris@0: $this->lock->wait(__FUNCTION__); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getSubscribedEvents() { Chris@0: // Run after CachedRouteRebuildSubscriber. Chris@0: $events[RoutingEvents::FINISHED][] = ['onRouterRebuild', 100]; Chris@0: return $events; Chris@0: } Chris@0: Chris@0: }