Example #1
0
 /**
  * {@inheritdoc}
  */
 public function rebuild()
 {
     if ($this->building) {
         throw new \RuntimeException('Recursive router rebuild detected.');
     }
     if (!$this->lock->acquire('router_rebuild')) {
         // Wait for another request that is already doing this work.
         // We choose to block here since otherwise the routes might not be
         // available, resulting in a 404.
         $this->lock->wait('router_rebuild');
         return FALSE;
     }
     $this->building = TRUE;
     $collection = new RouteCollection();
     foreach ($this->getRouteDefinitions() as $routes) {
         // The top-level 'routes_callback' is a list of methods in controller
         // syntax, see \Drupal\Core\Controller\ControllerResolver. These methods
         // should return a set of \Symfony\Component\Routing\Route objects, either
         // in an associative array keyed by the route name, which will be iterated
         // over and added to the collection for this provider, or as a new
         // \Symfony\Component\Routing\RouteCollection object, which will be added
         // to the collection.
         if (isset($routes['route_callbacks'])) {
             foreach ($routes['route_callbacks'] as $route_callback) {
                 $callback = $this->controllerResolver->getControllerFromDefinition($route_callback);
                 if ($callback_routes = call_user_func($callback)) {
                     // If a RouteCollection is returned, add the whole collection.
                     if ($callback_routes instanceof RouteCollection) {
                         $collection->addCollection($callback_routes);
                     } else {
                         foreach ($callback_routes as $name => $callback_route) {
                             $collection->add($name, $callback_route);
                         }
                     }
                 }
             }
             unset($routes['route_callbacks']);
         }
         foreach ($routes as $name => $route_info) {
             $route_info += array('defaults' => array(), 'requirements' => array(), 'options' => array());
             $route = new Route($route_info['path'], $route_info['defaults'], $route_info['requirements'], $route_info['options']);
             $collection->add($name, $route);
         }
     }
     // DYNAMIC is supposed to be used to add new routes based upon all the
     // static defined ones.
     $this->dispatcher->dispatch(RoutingEvents::DYNAMIC, new RouteBuildEvent($collection));
     // ALTER is the final step to alter all the existing routes. We cannot stop
     // people from adding new routes here, but we define two separate steps to
     // make it clear.
     $this->dispatcher->dispatch(RoutingEvents::ALTER, new RouteBuildEvent($collection));
     $this->checkProvider->setChecks($collection);
     $this->dumper->addRoutes($collection);
     $this->dumper->dump();
     $this->lock->release('router_rebuild');
     $this->dispatcher->dispatch(RoutingEvents::FINISHED, new Event());
     $this->building = FALSE;
     $this->rebuildNeeded = FALSE;
     return TRUE;
 }
Example #2
0
 /**
  * Deletes data from the store for a given key and releases the lock on it.
  *
  * @param string $key
  *   The key of the data to delete.
  */
 public function delete($key)
 {
     if (!$this->lockBackend->acquire($key)) {
         $this->lockBackend->wait($key);
         if (!$this->lockBackend->acquire($key)) {
             throw new TempStoreException("Couldn't acquire lock to delete item '{$key}' from {$this->storage->getCollectionName()} temporary storage.");
         }
     }
     $this->storage->delete($key);
     $this->lockBackend->release($key);
 }
 /**
  * Deletes data from the store for a given key and releases the lock on it.
  *
  * @param string $key
  *   The key of the data to delete.
  */
 public function delete($key)
 {
     if (!$this->lockBackend->acquire($key)) {
         $this->lockBackend->wait($key);
         if (!$this->lockBackend->acquire($key)) {
             throw new TempStoreException(String::format("Couldn't acquire lock to delete item %key from %collection temporary storage.", array('%key' => $key, '%collection' => $this->storage->getCollectionName())));
         }
     }
     $this->storage->delete($key);
     $this->lockBackend->release($key);
 }
 /**
  * Perform menu-specific rebuilding.
  */
 protected function menuLinksRebuild()
 {
     if ($this->lock->acquire(__FUNCTION__)) {
         $transaction = db_transaction();
         try {
             // Ensure the menu links are up to date.
             $this->menuLinkManager->rebuild();
             // Ignore any database replicas temporarily.
             db_ignore_replica();
         } catch (\Exception $e) {
             $transaction->rollback();
             watchdog_exception('menu', $e);
         }
         $this->lock->release(__FUNCTION__);
     } else {
         // Wait for another request that is already doing this work.
         // We choose to block here since otherwise the router item may not
         // be available during routing resulting in a 404.
         $this->lock->wait(__FUNCTION__);
     }
 }
Example #5
0
 /**
  * Deletes data from the store for a given key and releases the lock on it.
  *
  * @param string $key
  *   The key of the data to delete.
  *
  * @return bool
  *   TRUE if the object was deleted or does not exist, FALSE if it exists but
  *   is not owned by $this->owner.
  */
 public function delete($key)
 {
     $key = $this->createkey($key);
     if (!($object = $this->storage->get($key))) {
         return TRUE;
     } elseif ($object->owner != $this->getOwner()) {
         return FALSE;
     }
     if (!$this->lockBackend->acquire($key)) {
         $this->lockBackend->wait($key);
         if (!$this->lockBackend->acquire($key)) {
             throw new TempStoreException("Couldn't acquire lock to delete item '{$key}' from '{$this->storage->getCollectionName()}' temporary storage.");
         }
     }
     $this->storage->delete($key);
     $this->lockBackend->release($key);
     return TRUE;
 }
 /**
  * Deletes data from the store for a given key and releases the lock on it.
  *
  * @param string $key
  *   The key of the data to delete.
  *
  * @return bool
  *   TRUE if the object was deleted or does not exist, FALSE if it exists but
  *   is not owned by $this->owner.
  */
 public function delete($key)
 {
     $key = $this->createkey($key);
     if (!($object = $this->storage->get($key))) {
         return TRUE;
     } elseif ($object->owner != $this->getOwner()) {
         return FALSE;
     }
     if (!$this->lockBackend->acquire($key)) {
         $this->lockBackend->wait($key);
         if (!$this->lockBackend->acquire($key)) {
             throw new TempStoreException(SafeMarkup::format("Couldn't acquire lock to delete item %key from %collection temporary storage.", array('%key' => $key, '%collection' => $this->storage->getCollectionName())));
         }
     }
     $this->storage->delete($key);
     $this->lockBackend->release($key);
     return TRUE;
 }
 /**
  * Perform menu-specific rebuilding.
  */
 protected function menuLinksRebuild()
 {
     if ($this->lock->acquire(__FUNCTION__)) {
         $transaction = db_transaction();
         try {
             // Ensure the menu links are up to date.
             menu_link_rebuild_defaults();
             // Clear the menu cache.
             menu_cache_clear_all();
             // Track which menu items are expanded.
             _menu_update_expanded_menus();
         } catch (\Exception $e) {
             $transaction->rollback();
             watchdog_exception('menu', $e);
         }
         $this->lock->release(__FUNCTION__);
     } else {
         // Wait for another request that is already doing this work.
         // We choose to block here since otherwise the router item may not
         // be available during routing resulting in a 404.
         $this->lock->wait(__FUNCTION__);
     }
 }