Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Core\EventSubscriber; | 3 namespace Drupal\Core\EventSubscriber; |
4 | 4 |
5 use Drupal\Core\Cache\Cache; | 5 use Drupal\Core\Cache\Cache; |
6 use Drupal\Core\Database\ReplicaKillSwitch; | |
6 use Drupal\Core\Lock\LockBackendInterface; | 7 use Drupal\Core\Lock\LockBackendInterface; |
7 use Drupal\Core\Menu\MenuLinkManagerInterface; | 8 use Drupal\Core\Menu\MenuLinkManagerInterface; |
8 use Drupal\Core\Routing\RoutingEvents; | 9 use Drupal\Core\Routing\RoutingEvents; |
9 use Symfony\Component\EventDispatcher\Event; | 10 use Symfony\Component\EventDispatcher\Event; |
11 use Drupal\Core\Database\Connection; | |
10 use Symfony\Component\EventDispatcher\EventSubscriberInterface; | 12 use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
11 | 13 |
12 /** | 14 /** |
13 * Rebuilds the default menu links and runs menu-specific code if necessary. | 15 * Rebuilds the default menu links and runs menu-specific code if necessary. |
14 */ | 16 */ |
25 * @var \Drupal\Core\Menu\MenuLinkManagerInterface | 27 * @var \Drupal\Core\Menu\MenuLinkManagerInterface |
26 */ | 28 */ |
27 protected $menuLinkManager; | 29 protected $menuLinkManager; |
28 | 30 |
29 /** | 31 /** |
32 * The replica kill switch. | |
33 * | |
34 * @var \Drupal\Core\Database\ReplicaKillSwitch | |
35 */ | |
36 protected $replicaKillSwitch; | |
37 | |
38 /** | |
39 * The database connection. | |
40 * | |
41 * @var \Drupal\Core\Database\Connection | |
42 */ | |
43 protected $connection; | |
44 | |
45 /** | |
30 * Constructs the MenuRouterRebuildSubscriber object. | 46 * Constructs the MenuRouterRebuildSubscriber object. |
31 * | 47 * |
32 * @param \Drupal\Core\Lock\LockBackendInterface $lock | 48 * @param \Drupal\Core\Lock\LockBackendInterface $lock |
33 * The lock backend. | 49 * The lock backend. |
34 * @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager | 50 * @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager |
35 * The menu link plugin manager. | 51 * The menu link plugin manager. |
52 * @param \Drupal\Core\Database\Connection $connection | |
53 * The database connection. | |
54 * @param \Drupal\Core\Database\ReplicaKillSwitch $replica_kill_switch | |
55 * The replica kill switch. | |
36 */ | 56 */ |
37 public function __construct(LockBackendInterface $lock, MenuLinkManagerInterface $menu_link_manager) { | 57 public function __construct(LockBackendInterface $lock, MenuLinkManagerInterface $menu_link_manager, Connection $connection, ReplicaKillSwitch $replica_kill_switch) { |
38 $this->lock = $lock; | 58 $this->lock = $lock; |
39 $this->menuLinkManager = $menu_link_manager; | 59 $this->menuLinkManager = $menu_link_manager; |
60 $this->connection = $connection; | |
61 $this->replicaKillSwitch = $replica_kill_switch; | |
40 } | 62 } |
41 | 63 |
42 /** | 64 /** |
43 * Rebuilds the menu links and deletes the local_task cache tag. | 65 * Rebuilds the menu links and deletes the local_task cache tag. |
44 * | 66 * |
53 /** | 75 /** |
54 * Perform menu-specific rebuilding. | 76 * Perform menu-specific rebuilding. |
55 */ | 77 */ |
56 protected function menuLinksRebuild() { | 78 protected function menuLinksRebuild() { |
57 if ($this->lock->acquire(__FUNCTION__)) { | 79 if ($this->lock->acquire(__FUNCTION__)) { |
58 $transaction = db_transaction(); | 80 $transaction = $this->connection->startTransaction(); |
59 try { | 81 try { |
60 // Ensure the menu links are up to date. | 82 // Ensure the menu links are up to date. |
61 $this->menuLinkManager->rebuild(); | 83 $this->menuLinkManager->rebuild(); |
62 // Ignore any database replicas temporarily. | 84 // Ignore any database replicas temporarily. |
63 db_ignore_replica(); | 85 $this->replicaKillSwitch->trigger(); |
64 } | 86 } |
65 catch (\Exception $e) { | 87 catch (\Exception $e) { |
66 $transaction->rollBack(); | 88 $transaction->rollBack(); |
67 watchdog_exception('menu', $e); | 89 watchdog_exception('menu', $e); |
68 } | 90 } |