From 898a526dfabf44b5b63392696d2ce22a50c47596 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 12:01:00 +0100 Subject: [PATCH 01/18] Use caching to speed up route parsing Signed-off-by: William Desportes --- index.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index c1a2273cd0..e75d71f11d 100644 --- a/index.php +++ b/index.php @@ -7,7 +7,7 @@ declare(strict_types=1); use FastRoute\Dispatcher; use PhpMyAdmin\Message; use PhpMyAdmin\Response; -use function FastRoute\simpleDispatcher; +use function FastRoute\cachedDispatcher; if (! defined('ROOT_PATH')) { // phpcs:disable PSR1.Files.SideEffects @@ -15,7 +15,7 @@ if (! defined('ROOT_PATH')) { // phpcs:enable } -global $containerBuilder, $route; +global $containerBuilder, $route, $cfg; /** @var string $route */ $route = $_GET['route'] ?? $_POST['route'] ?? '/'; @@ -41,7 +41,12 @@ if ($route === '/import-status') { require_once ROOT_PATH . 'libraries/common.inc.php'; $routes = require ROOT_PATH . 'libraries/routes.php'; -$dispatcher = simpleDispatcher($routes); +/** @var \PhpMyAdmin\Config|null $config */ +$config = $GLOBALS['PMA_Config']; +$dispatcher = cachedDispatcher($routes, [ + 'cacheFile' => $config !== null ? $config->getTempDir('routing') . '/routes.cache' : null, + 'cacheDisabled' => ($cfg['environment'] ?? '') === 'development', +]); $routeInfo = $dispatcher->dispatch( $_SERVER['REQUEST_METHOD'], rawurldecode($route) From bde3e5ae65a010cc39823aa41ce437fb45462801 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 20:26:07 +0100 Subject: [PATCH 02/18] Move all index.php code to PhpMyAdmin\Routing and change cache name Signed-off-by: William Desportes Fix some phpdoc comments Signed-off-by: William Desportes --- index.php | 53 +++-------------------- libraries/classes/Routing.php | 81 +++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 48 deletions(-) create mode 100644 libraries/classes/Routing.php diff --git a/index.php b/index.php index e75d71f11d..6383c741b1 100644 --- a/index.php +++ b/index.php @@ -4,10 +4,7 @@ */ declare(strict_types=1); -use FastRoute\Dispatcher; -use PhpMyAdmin\Message; -use PhpMyAdmin\Response; -use function FastRoute\cachedDispatcher; +use PhpMyAdmin\Routing; if (! defined('ROOT_PATH')) { // phpcs:disable PSR1.Files.SideEffects @@ -15,22 +12,9 @@ if (! defined('ROOT_PATH')) { // phpcs:enable } -global $containerBuilder, $route, $cfg; +global $route; -/** @var string $route */ -$route = $_GET['route'] ?? $_POST['route'] ?? '/'; - -/** - * See FAQ 1.34. - * - * @see https://docs.phpmyadmin.net/en/latest/faq.html#faq1-34 - */ -if (($route === '/' || $route === '') && isset($_GET['db']) && mb_strlen($_GET['db']) !== 0) { - $route = '/database/structure'; - if (isset($_GET['table']) && mb_strlen($_GET['table']) !== 0) { - $route = '/sql'; - } -} +$route = Routing::getCurrentRoute(); if ($route === '/import-status') { // phpcs:disable PSR1.Files.SideEffects @@ -40,32 +24,5 @@ if ($route === '/import-status') { require_once ROOT_PATH . 'libraries/common.inc.php'; -$routes = require ROOT_PATH . 'libraries/routes.php'; -/** @var \PhpMyAdmin\Config|null $config */ -$config = $GLOBALS['PMA_Config']; -$dispatcher = cachedDispatcher($routes, [ - 'cacheFile' => $config !== null ? $config->getTempDir('routing') . '/routes.cache' : null, - 'cacheDisabled' => ($cfg['environment'] ?? '') === 'development', -]); -$routeInfo = $dispatcher->dispatch( - $_SERVER['REQUEST_METHOD'], - rawurldecode($route) -); -if ($routeInfo[0] === Dispatcher::NOT_FOUND) { - /** @var Response $response */ - $response = $containerBuilder->get(Response::class); - $response->setHttpResponseCode(404); - Message::error(sprintf( - __('Error 404! The page %s was not found.'), - '' . $route . '' - ))->display(); -} elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) { - /** @var Response $response */ - $response = $containerBuilder->get(Response::class); - $response->setHttpResponseCode(405); - Message::error(__('Error 405! Request method not allowed.'))->display(); -} elseif ($routeInfo[0] === Dispatcher::FOUND) { - [$controllerName, $action] = $routeInfo[1]; - $controller = $containerBuilder->get($controllerName); - $controller->$action($routeInfo[2]); -} +$dispatcher = Routing::getDispatcher(); +Routing::callControllerForRoute($route, $dispatcher); diff --git a/libraries/classes/Routing.php b/libraries/classes/Routing.php new file mode 100644 index 0000000000..6f17a94b71 --- /dev/null +++ b/libraries/classes/Routing.php @@ -0,0 +1,81 @@ + ROOT_PATH . 'libraries/cache/routes.cache', + 'cacheDisabled' => ($cfg['environment'] ?? '') === 'development', + ]); + } + + public static function getCurrentRoute(): string + { + /** @var string $route */ + $route = $_GET['route'] ?? $_POST['route'] ?? '/'; + + /** + * See FAQ 1.34. + * + * @see https://docs.phpmyadmin.net/en/latest/faq.html#faq1-34 + */ + if (($route === '/' || $route === '') && isset($_GET['db']) && mb_strlen($_GET['db']) !== 0) { + $route = '/database/structure'; + if (isset($_GET['table']) && mb_strlen($_GET['table']) !== 0) { + $route = '/sql'; + } + } + return $route; + } + + /** + * Call associated controller for a route using the dispatcher + * @param string $route The current route + * @param Dispatcher $dispatcher The dispatcher + */ + public static function callControllerForRoute(string $route, Dispatcher $dispatcher): void + { + global $containerBuilder; + $routeInfo = $dispatcher->dispatch( + $_SERVER['REQUEST_METHOD'], + rawurldecode($route) + ); + if ($routeInfo[0] === Dispatcher::NOT_FOUND) { + /** @var Response $response */ + $response = $containerBuilder->get(Response::class); + $response->setHttpResponseCode(404); + Message::error(sprintf( + __('Error 404! The page %s was not found.'), + '' . $route . '' + ))->display(); + } elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) { + /** @var Response $response */ + $response = $containerBuilder->get(Response::class); + $response->setHttpResponseCode(405); + Message::error(__('Error 405! Request method not allowed.'))->display(); + } elseif ($routeInfo[0] === Dispatcher::FOUND) { + [$controllerName, $action] = $routeInfo[1]; + $controller = $containerBuilder->get($controllerName); + $controller->$action($routeInfo[2]); + } + } +} From 01f21e0fdfecc66809fc69139707fa6d87c59dc6 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 12:01:05 +0100 Subject: [PATCH 03/18] Add new cache directory Signed-off-by: William Desportes --- libraries/cache/.gitignore | 2 ++ phpcs.xml.dist | 1 + phpstan.neon.dist | 1 + phpunit.xml.dist | 1 + 4 files changed, 5 insertions(+) create mode 100644 libraries/cache/.gitignore diff --git a/libraries/cache/.gitignore b/libraries/cache/.gitignore new file mode 100644 index 0000000000..a68d087bfe --- /dev/null +++ b/libraries/cache/.gitignore @@ -0,0 +1,2 @@ +/* +!/.gitignore diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 5be43db5ff..a3f2a10055 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -74,6 +74,7 @@ */node_modules/* + */libraries/cache/* */test/sami-config.php *.twig */twig-templates/* diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 544bb6390b..490d8874a5 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -12,6 +12,7 @@ parameters: excludes_analyse: - examples/openid.php - node_modules/* + - libraries/cache/* - test/sami-config.php - tmp/* - twig-templates/* diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1b95f0ee71..db35e32a38 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -25,6 +25,7 @@ examples node_modules + libraries/cache test tmp vendor From 09d1f8636058be47dbb9cc8991608b4ff530fdd9 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 12:01:06 +0100 Subject: [PATCH 04/18] Update create-release.sh script Signed-off-by: William Desportes --- scripts/create-release.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/create-release.sh b/scripts/create-release.sh index a053322da8..3ce85a18bc 100755 --- a/scripts/create-release.sh +++ b/scripts/create-release.sh @@ -218,11 +218,8 @@ echo "* Removing unneeded files" # Remove developer information rm -rf .github -# Remove phpcs coding standard definition -rm -rf PMAStandard - # Testsuite setup -rm -f .travis.yml .coveralls.yml .scrutinizer.yml .jshintrc .weblate codecov.yml +rm -f .travis.yml .scrutinizer.yml .jshintrc .weblate codecov.yml # Remove readme for github rm -f README.rst @@ -304,6 +301,9 @@ fi # Remove Bootstrap theme rm -rf themes/bootstrap +# Warm up the routing cache +./scripts/console routing:cache:warmup + # Remove git metadata rm .git find . -name .gitignore -print0 | xargs -0 -r rm -f @@ -351,7 +351,7 @@ for kit in $KITS ; do # Testsuite rm -rf test/ rm phpunit.xml.* build.xml - rm -f .editorconfig .eslintignore .eslintrc.json .stylelintrc.json phpstan.neon.dist phpcs.xml.dist + rm -f .editorconfig .eslintignore .jshintrc .eslintrc.json .stylelintrc.json phpstan.neon.dist phpstan-baseline.neon phpcs.xml.dist # Gettext po files rm -rf po/ # Documentation source code From a06d25962a140d79b04c2d66ad49fa9099cfb387 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 12:01:06 +0100 Subject: [PATCH 05/18] Add / for branch names in create-release.sh script Signed-off-by: William Desportes --- scripts/create-release.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/create-release.sh b/scripts/create-release.sh index 3ce85a18bc..351378739f 100755 --- a/scripts/create-release.sh +++ b/scripts/create-release.sh @@ -80,7 +80,7 @@ while [ $# -gt 0 ] ; do exit 1 fi elif [ -z "$branch" ] ; then - branch=`echo $1 | tr -d -c '0-9A-Za-z_-'` + branch=`echo $1 | tr -d -c '/0-9A-Za-z_-'` if [ "x$branch" != "x$1" ] ; then echo "Invalid branch: $1" exit 1 From 24c67f46cbd720c6595d56f1e31e3b18de4e3e8e Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 12:01:06 +0100 Subject: [PATCH 06/18] Add back dev vendors in create-release script before warm up Signed-off-by: William Desportes --- scripts/create-release.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/create-release.sh b/scripts/create-release.sh index 351378739f..468edee73e 100755 --- a/scripts/create-release.sh +++ b/scripts/create-release.sh @@ -301,8 +301,10 @@ fi # Remove Bootstrap theme rm -rf themes/bootstrap +composer update # Warm up the routing cache ./scripts/console routing:cache:warmup +composer update --no-dev # Remove git metadata rm .git From 5044600e3a7b84b11d7ac824df0397bccfc5b1c6 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 12:01:07 +0100 Subject: [PATCH 07/18] Add --optimize-autoloader Ref: https://getcomposer.org/doc/articles/autoloader-optimization.md Signed-off-by: William Desportes --- scripts/create-release.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/create-release.sh b/scripts/create-release.sh index 468edee73e..c434b6288e 100755 --- a/scripts/create-release.sh +++ b/scripts/create-release.sh @@ -240,7 +240,7 @@ if [ ! -d libraries/tcpdf ] ; then cp composer.json composer.json.backup echo "* Running composer" composer config platform.php "$PHP_REQ" - composer update --no-dev + composer update --no-dev --optimize-autoloader # Parse the required versions from composer.json PACKAGES_VERSIONS='' @@ -253,7 +253,7 @@ if [ ! -d libraries/tcpdf ] ; then do PACKAGES_VERSIONS="$PACKAGES_VERSIONS $PACKAGES:`awk "/require-dev/ {printline = 1; print; next } printline" composer.json | grep "$PACKAGES" | awk -F [\\"] '{print $4}'`" done - composer require --update-no-dev $PACKAGES_VERSIONS + composer require --optimize-autoloader --update-no-dev $PACKAGES_VERSIONS mv composer.json.backup composer.json echo "* Cleanup of composer packages" @@ -304,7 +304,7 @@ rm -rf themes/bootstrap composer update # Warm up the routing cache ./scripts/console routing:cache:warmup -composer update --no-dev +composer update --no-dev --optimize-autoloader # Remove git metadata rm .git @@ -331,7 +331,7 @@ if [ $do_test -eq 1 ] ; then rm -f .phpunit.result.cache # Remove libs installed for testing rm -rf build - composer update --no-dev + composer update --no-dev --optimize-autoloader fi From c85fb43da0bcdfb4344b3e32e623958fb63e41fa Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 20:31:17 +0100 Subject: [PATCH 08/18] Create ROUTING_CACHE_DIR contstant Signed-off-by: William Desportes --- libraries/classes/Routing.php | 2 +- libraries/vendor_config.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/classes/Routing.php b/libraries/classes/Routing.php index 6f17a94b71..c83bb0d491 100644 --- a/libraries/classes/Routing.php +++ b/libraries/classes/Routing.php @@ -23,7 +23,7 @@ class Routing $routes = require ROOT_PATH . 'libraries/routes.php'; return cachedDispatcher($routes, [ - 'cacheFile' => ROOT_PATH . 'libraries/cache/routes.cache', + 'cacheFile' => ROUTING_CACHE_DIR . 'routes.cache', 'cacheDisabled' => ($cfg['environment'] ?? '') === 'development', ]); } diff --git a/libraries/vendor_config.php b/libraries/vendor_config.php index 674fedc778..ca3a7d5904 100644 --- a/libraries/vendor_config.php +++ b/libraries/vendor_config.php @@ -79,3 +79,8 @@ define('LOCALE_PATH', ROOT_PATH . 'locale/'); * is used) */ define('K_PATH_IMAGES', ROOT_PATH); + +/** + * Define the cache directory for routing + */ +define('ROUTING_CACHE_DIR', ROOT_PATH . 'libraries/cache/'); From c6301a1542f1691ada046419016053c207610fa7 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 12:01:05 +0100 Subject: [PATCH 09/18] Add routing cache warmup to warm up command Signed-off-by: William Desportes --- .../classes/Command/CacheWarmupCommand.php | 33 +++++++++++++++++++ scripts/create-release.sh | 2 +- scripts/update-po | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/libraries/classes/Command/CacheWarmupCommand.php b/libraries/classes/Command/CacheWarmupCommand.php index 87c23f9b6c..8fecf50024 100644 --- a/libraries/classes/Command/CacheWarmupCommand.php +++ b/libraries/classes/Command/CacheWarmupCommand.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin\Command; use PhpMyAdmin\Config; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Routing; use PhpMyAdmin\Tests\Stubs\DbiDummy; use PhpMyAdmin\Twig\CoreExtension; use PhpMyAdmin\Twig\I18nExtension; @@ -41,13 +42,39 @@ final class CacheWarmupCommand extends Command protected function configure(): void { $this->setDescription('Warms up the Twig templates cache'); + $this->addOption('twig', null, null, 'Warm up twig templates cache.'); + $this->addOption('routing', null, null, 'Warm up routing cache.'); $this->setHelp('The %command.name% command warms up the cache of the Twig templates.'); } protected function execute(InputInterface $input, OutputInterface $output): int + { + if ($input->getOption('twig') === true && $input->getOption('routing') === true) { + $output->writeln('Please specify --twig or --routing'); + return 1; + } elseif ($input->getOption('twig') === true) { + return $this->warmUpTwigCache($output); + } elseif ($input->getOption('routing') === true) { + return $this->warmUpRoutingCache($output); + } else { + $output->writeln('Please specify --twig or --routing'); + return 1; + } + } + + public function warmUpRoutingCache(OutputInterface $output): int + { + $output->writeln('Warming up the routing cache', OutputInterface::VERBOSITY_VERBOSE); + Routing::getDispatcher(); + $output->writeln('Warm up done.', OutputInterface::VERBOSITY_VERBOSE); + return 0; + } + + public function warmUpTwigCache(OutputInterface $output): int { global $cfg, $PMA_Config, $dbi; + $output->writeln('Warming up the twig cache', OutputInterface::VERBOSITY_VERBOSE); $cfg['environment'] = 'production'; $PMA_Config = new Config(CONFIG_FILE); $PMA_Config->set('environment', $cfg['environment']); @@ -77,12 +104,15 @@ final class CacheWarmupCommand extends Command /** @var CacheInterface $twigCache */ $twigCache = $twig->getCache(false); + $output->writeln('Searching for files...', OutputInterface::VERBOSITY_VERY_VERBOSE); + $replacements = []; $templates = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY ); + $output->writeln('Warming templates', OutputInterface::VERBOSITY_VERY_VERBOSE); foreach ($templates as $file) { // Skip test files if (strpos($file->getPathname(), '/test/') !== false) { @@ -91,6 +121,7 @@ final class CacheWarmupCommand extends Command // force compilation if ($file->isFile() && $file->getExtension() === 'twig') { $name = str_replace($tplDir . '/', '', $file->getPathname()); + $output->writeln('Loading: ' . $name, OutputInterface::VERBOSITY_DEBUG); $template = $twig->loadTemplate($name); // Generate line map @@ -101,6 +132,7 @@ final class CacheWarmupCommand extends Command } } + $output->writeln('Writing replacements...', OutputInterface::VERBOSITY_VERY_VERBOSE); // Store replacements in JSON $handle = fopen($tmpDir . '/replace.json', 'w'); if ($handle === false) { @@ -109,6 +141,7 @@ final class CacheWarmupCommand extends Command fwrite($handle, (string) json_encode($replacements)); fclose($handle); + $output->writeln('Warm up done.', OutputInterface::VERBOSITY_VERBOSE); return 0; } diff --git a/scripts/create-release.sh b/scripts/create-release.sh index c434b6288e..5b2e17e8ac 100755 --- a/scripts/create-release.sh +++ b/scripts/create-release.sh @@ -303,7 +303,7 @@ rm -rf themes/bootstrap composer update # Warm up the routing cache -./scripts/console routing:cache:warmup +./scripts/console cache:warmup --routing composer update --no-dev --optimize-autoloader # Remove git metadata diff --git a/scripts/update-po b/scripts/update-po index 411c30066a..1f8083385d 100755 --- a/scripts/update-po +++ b/scripts/update-po @@ -13,7 +13,7 @@ set -e # Generate Twig template cache in clean dir rm -rf twig-templates/ -php scripts/console cache:warmup +php scripts/console cache:warmup --twig # Update pot (template), ensure that advisor is at the end LOCS=`ls po/*.po | sed 's@.*/\(.*\)\.po@\1@'` From aed59d758c6199655e643cbd884a0b2272b13159 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 21:08:10 +0100 Subject: [PATCH 10/18] Remove a blank line Signed-off-by: William Desportes --- libraries/classes/Routing.php | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/classes/Routing.php b/libraries/classes/Routing.php index c83bb0d491..1004331fa7 100644 --- a/libraries/classes/Routing.php +++ b/libraries/classes/Routing.php @@ -16,7 +16,6 @@ use function rawurldecode; */ class Routing { - public static function getDispatcher(): Dispatcher { global $cfg; From d439fb76a7fc1ef66839d14d2742fa706a49c304 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 21:20:01 +0100 Subject: [PATCH 11/18] Add RoutingTest class Signed-off-by: William Desportes --- test/classes/RoutingTest.php | 101 +++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 test/classes/RoutingTest.php diff --git a/test/classes/RoutingTest.php b/test/classes/RoutingTest.php new file mode 100644 index 0000000000..d6860141e5 --- /dev/null +++ b/test/classes/RoutingTest.php @@ -0,0 +1,101 @@ +assertInstanceOf(Dispatcher::class, $dispatcher); + $this->assertSame([ + Dispatcher::FOUND, + [ + HomeController::class, + 'index', + ], + [], + ], $dispatcher->dispatch('GET', '/')); + } + + /** + * Test for Routing::getCurrentRoute + * + * @return void + */ + public function testGetCurrentRouteNoParams(): void + { + $this->assertSame('/', Routing::getCurrentRoute()); + } + + /** + * Test for Routing::getCurrentRoute + * + * @return void + */ + public function testGetCurrentRouteGet(): void + { + $_GET['route'] = '/test'; + $this->assertSame('/test', Routing::getCurrentRoute()); + } + + /** + * Test for Routing::getCurrentRoute + * + * @return void + */ + public function testGetCurrentRoutePost(): void + { + $_POST['route'] = '/testpost'; + $this->assertSame('/testpost', Routing::getCurrentRoute()); + } + + /** + * Test for Routing::getCurrentRoute + * + * @return void + */ + public function testGetCurrentRouteGetIsOverPost(): void + { + $_GET['route'] = '/testget'; + $_POST['route'] = '/testpost'; + $this->assertSame('/testget', Routing::getCurrentRoute()); + } + + /** + * Test for Routing::getCurrentRoute + * + * @return void + */ + public function testGetCurrentRouteRedirectDbStructure(): void + { + $_GET['db'] = 'testDB'; + $this->assertSame('/database/structure', Routing::getCurrentRoute()); + } + + /** + * Test for Routing::getCurrentRoute + * + * @return void + */ + public function testGetCurrentRouteRedirectSql(): void + { + $_GET['db'] = 'testDB'; + $_GET['table'] = 'tableTest'; + $this->assertSame('/sql', Routing::getCurrentRoute()); + } +} From d56bb6cf0030b9526b21964c290c98954844764b Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 22:20:14 +0100 Subject: [PATCH 12/18] Change ROUTING_CACHE_DIR into CACHE_DIR Ref: 4d2800daa49819b85aceba9089f6bec3da254608 Signed-off-by: William Desportes --- libraries/classes/Routing.php | 2 +- libraries/vendor_config.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/classes/Routing.php b/libraries/classes/Routing.php index 1004331fa7..fdf158bb6a 100644 --- a/libraries/classes/Routing.php +++ b/libraries/classes/Routing.php @@ -22,7 +22,7 @@ class Routing $routes = require ROOT_PATH . 'libraries/routes.php'; return cachedDispatcher($routes, [ - 'cacheFile' => ROUTING_CACHE_DIR . 'routes.cache', + 'cacheFile' => CACHE_DIR . 'routes.cache', 'cacheDisabled' => ($cfg['environment'] ?? '') === 'development', ]); } diff --git a/libraries/vendor_config.php b/libraries/vendor_config.php index ca3a7d5904..9cae9f1ebe 100644 --- a/libraries/vendor_config.php +++ b/libraries/vendor_config.php @@ -81,6 +81,6 @@ define('LOCALE_PATH', ROOT_PATH . 'locale/'); define('K_PATH_IMAGES', ROOT_PATH); /** - * Define the cache directory for routing + * Define the cache directory for routing cache an other cache files */ -define('ROUTING_CACHE_DIR', ROOT_PATH . 'libraries/cache/'); +define('CACHE_DIR', ROOT_PATH . 'libraries/cache/'); From ecba412eda2884d35e6050593e9fe7039d9654b4 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 22:23:37 +0100 Subject: [PATCH 13/18] Add a warning and exit code 1 when de-dependencies are not installed Signed-off-by: William Desportes --- scripts/console | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/console b/scripts/console index 678b7aac2d..cfdd9b80e4 100755 --- a/scripts/console +++ b/scripts/console @@ -13,6 +13,12 @@ define('PHPMYADMIN', true); require_once ROOT_PATH . 'libraries/vendor_config.php'; require_once AUTOLOAD_FILE; +if (! class_exists(Application::class)) { + echo 'Be sure to have dev-dependencies installed.' . PHP_EOL; + echo 'Command aborted.' . PHP_EOL; + exit(1); +} + $application = new Application('phpMyAdmin Console Tool'); $application->add(new AdvisoryRulesCommand()); From 105daa8584a4153125b6b04b0e94150d3027f0d7 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 22:27:20 +0100 Subject: [PATCH 14/18] Support warm up all caches Signed-off-by: William Desportes --- libraries/classes/Command/CacheWarmupCommand.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libraries/classes/Command/CacheWarmupCommand.php b/libraries/classes/Command/CacheWarmupCommand.php index 8fecf50024..263f3698a4 100644 --- a/libraries/classes/Command/CacheWarmupCommand.php +++ b/libraries/classes/Command/CacheWarmupCommand.php @@ -57,8 +57,19 @@ final class CacheWarmupCommand extends Command } elseif ($input->getOption('routing') === true) { return $this->warmUpRoutingCache($output); } else { - $output->writeln('Please specify --twig or --routing'); - return 1; + $output->writeln('Warming up all caches.', OutputInterface::VERBOSITY_VERBOSE); + $twigCode = $this->warmUptwigCache($output); + if ($twigCode !== 0) { + $output->writeln('Twig cache generation had an error.'); + return $twigCode; + } + $routingCode = $this->warmUpTwigCache($output); + if ($routingCode !== 0) { + $output->writeln('Routing cache generation had an error.'); + return $twigCode; + } + $output->writeln('Warm up of all caches done.', OutputInterface::VERBOSITY_VERBOSE); + return 0; } } From 8c7b7b10db700d929162c070852437f212cc6cf1 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 22:44:44 +0100 Subject: [PATCH 15/18] Move PMA_MINIMUM_COMMON for import-status route after auto-loader Signed-off-by: William Desportes --- index.php | 8 -------- libraries/common.inc.php | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/index.php b/index.php index 6383c741b1..6fe4765a7d 100644 --- a/index.php +++ b/index.php @@ -14,14 +14,6 @@ if (! defined('ROOT_PATH')) { global $route; -$route = Routing::getCurrentRoute(); - -if ($route === '/import-status') { - // phpcs:disable PSR1.Files.SideEffects - define('PMA_MINIMUM_COMMON', true); - // phpcs:enable -} - require_once ROOT_PATH . 'libraries/common.inc.php'; $dispatcher = Routing::getDispatcher(); diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 1117f6d1f2..500147b273 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -40,6 +40,7 @@ use PhpMyAdmin\Message; use PhpMyAdmin\MoTranslator\Loader; use PhpMyAdmin\Plugins\AuthenticationPlugin; use PhpMyAdmin\Response; +use PhpMyAdmin\Routing; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Session; use PhpMyAdmin\SqlParser\Lexer; @@ -95,6 +96,14 @@ if (! @is_readable(AUTOLOAD_FILE)) { } require_once AUTOLOAD_FILE; +$route = Routing::getCurrentRoute(); + +if ($route === '/import-status') { + // phpcs:disable PSR1.Files.SideEffects + define('PMA_MINIMUM_COMMON', true); + // phpcs:enable +} + $containerBuilder = new ContainerBuilder(); $loader = new PhpFileLoader($containerBuilder, new FileLocator(__DIR__)); $loader->load('services_loader.php'); From 225ee2b9440b8d64d3538ce906deaefa28fed387 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Wed, 18 Mar 2020 22:48:27 +0100 Subject: [PATCH 16/18] Add $route as a global variable in common.inc.php Signed-off-by: William Desportes --- libraries/common.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 500147b273..6af5caa56f 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -51,7 +51,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -global $containerBuilder, $error_handler, $PMA_Config, $server, $dbi, $lang, $cfg, $isConfigLoading, $auth_plugin; +global $containerBuilder, $error_handler, $PMA_Config, $server, $dbi, $lang, $cfg, $isConfigLoading, $auth_plugin, $route; /** * block attempts to directly run this script From c3b99d7baa2a3f91fa9828c30f06bc72fa408857 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sat, 28 Mar 2020 10:41:06 +0100 Subject: [PATCH 17/18] Change functions from public to private in CacheWarmupCommand Signed-off-by: William Desportes --- libraries/classes/Command/CacheWarmupCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/classes/Command/CacheWarmupCommand.php b/libraries/classes/Command/CacheWarmupCommand.php index 263f3698a4..a0c0ed32e3 100644 --- a/libraries/classes/Command/CacheWarmupCommand.php +++ b/libraries/classes/Command/CacheWarmupCommand.php @@ -73,7 +73,7 @@ final class CacheWarmupCommand extends Command } } - public function warmUpRoutingCache(OutputInterface $output): int + private function warmUpRoutingCache(OutputInterface $output): int { $output->writeln('Warming up the routing cache', OutputInterface::VERBOSITY_VERBOSE); Routing::getDispatcher(); @@ -81,7 +81,7 @@ final class CacheWarmupCommand extends Command return 0; } - public function warmUpTwigCache(OutputInterface $output): int + private function warmUpTwigCache(OutputInterface $output): int { global $cfg, $PMA_Config, $dbi; From 4c35ccb143bf4cfa4acbc37541e0be7e54d044b4 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Sat, 28 Mar 2020 10:50:29 +0100 Subject: [PATCH 18/18] Improve a very old comment Signed-off-by: William Desportes --- libraries/classes/Display/ImportAjax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/Display/ImportAjax.php b/libraries/classes/Display/ImportAjax.php index 476c98226d..002f84d749 100644 --- a/libraries/classes/Display/ImportAjax.php +++ b/libraries/classes/Display/ImportAjax.php @@ -45,7 +45,7 @@ class ImportAjax * list of available plugins */ $plugins = [ - // PHP 5.4 session-based upload progress is problematic, see bug 3964 + // in PHP 5.4 session-based upload progress was problematic, see closed bug 3964 //"session", 'progress', 'apc',