public MatcherDumper::dump(array $options = array())
Dumps a set of routes to the router table in the database.
Available options:
- provider: The route grouping that is being dumped. All existing routes with this provider will be deleted on dump.
- base_class: The base class name.
Parameters
array $options: An array of options.
Overrides MatcherDumperInterface::dump
File
- core/lib/Drupal/Core/Routing/MatcherDumper.php, line 87
Class
- MatcherDumper
- Dumps Route information to a database table.
Namespace
Drupal\Core\Routing
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | public function dump( array $options = array ()) { // Convert all of the routes into database records. // Accumulate the menu masks on top of any we found before. $masks = array_flip ( $this ->state->get( 'routing.menu_masks.' . $this ->tableName, array ())); // Delete any old records first, then insert the new ones. That avoids // stale data. The transaction makes it atomic to avoid unstable router // states due to random failures. $transaction = $this ->connection->startTransaction(); try { // We don't use truncate, because it is not guaranteed to be transaction // safe. try { $this ->connection-> delete ( $this ->tableName) ->execute(); } catch (\Exception $e ) { $this ->ensureTableExists(); } // Split the routes into chunks to avoid big INSERT queries. $route_chunks = array_chunk ( $this ->routes->all(), 50, TRUE); foreach ( $route_chunks as $routes ) { $insert = $this ->connection->insert( $this ->tableName)->fields( array ( 'name' , 'fit' , 'path' , 'pattern_outline' , 'number_parts' , 'route' , )); $names = array (); foreach ( $routes as $name => $route ) { /** @var \Symfony\Component\Routing\Route $route */ $route ->setOption( 'compiler_class' , '\Drupal\Core\Routing\RouteCompiler' ); /** @var \Drupal\Core\Routing\CompiledRoute $compiled */ $compiled = $route ->compile(); // The fit value is a binary number which has 1 at every fixed path // position and 0 where there is a wildcard. We keep track of all such // patterns that exist so that we can minimize the number of path // patterns we need to check in the RouteProvider. $masks [ $compiled ->getFit()] = 1; $names [] = $name ; $values = array ( 'name' => $name , 'fit' => $compiled ->getFit(), 'path' => $route ->getPath(), 'pattern_outline' => $compiled ->getPatternOutline(), 'number_parts' => $compiled ->getNumParts(), 'route' => serialize( $route ), ); $insert ->values( $values ); } // Insert all new routes. $insert ->execute(); } } catch (\Exception $e ) { $transaction ->rollback(); watchdog_exception( 'Routing' , $e ); throw $e ; } // Sort the masks so they are in order of descending fit. $masks = array_keys ( $masks ); rsort( $masks ); $this ->state->set( 'routing.menu_masks.' . $this ->tableName, $masks ); $this ->routes = NULL; } |
Please login to continue.