From 74eccfe9199b14952a598187d2e7c29895692f78 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Sat, 3 Apr 2021 11:36:34 +0200 Subject: [PATCH] chg: [internal] Install CakePHP by Composer --- .gitmodules | 4 --- app/Console/cake.php | 45 ++++++++++++++++++++++----------- app/Lib/Tools/SecurityAudit.php | 2 +- app/Lib/cakephp | 1 - app/composer.json | 1 + app/webroot/index.php | 12 ++++++++- 6 files changed, 43 insertions(+), 22 deletions(-) delete mode 160000 app/Lib/cakephp diff --git a/.gitmodules b/.gitmodules index 49339051c..64b13d630 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "app/Lib/cakephp"] - path = app/Lib/cakephp - url = https://github.com/cakephp/cakephp.git - branch = 2.x [submodule "PyMISP"] path = PyMISP url = https://github.com/MISP/PyMISP.git diff --git a/app/Console/cake.php b/app/Console/cake.php index a98d1b421..ba8c1df3c 100644 --- a/app/Console/cake.php +++ b/app/Console/cake.php @@ -3,30 +3,45 @@ /** * Command-line code generation utility to automate programmer chores. * - * PHP 5 - * - * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) - * Copyright 2005-2012, Cake Software Foundation, Inc. + * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) + * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) * * Licensed under The MIT License + * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * - * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) - * @link http://cakephp.org CakePHP(tm) Project + * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) + * @link https://cakephp.org CakePHP(tm) Project * @package app.Console * @since CakePHP(tm) v 2.0 - * @license MIT License (http://www.opensource.org/licenses/mit-license.php) + * @license https://opensource.org/licenses/mit-license.php MIT License */ -$ds = DIRECTORY_SEPARATOR; -$dispatcher = dirname(__DIR__) . $ds . 'Lib' . $ds . 'cakephp' . $ds . 'lib' . $ds . 'Cake' . $ds . 'Console' . $ds . 'ShellDispatcher.php'; -if (function_exists('ini_set')) { - $root = dirname(dirname(dirname(__FILE__))); - ini_set('include_path', $root . $ds . 'lib' . PATH_SEPARATOR . ini_get('include_path')); + +if (!defined('DS')) { + define('DS', DIRECTORY_SEPARATOR); } -if (!include ($dispatcher)) { - trigger_error('Could not locate CakePHP core files.', E_USER_ERROR); +$dispatcher = 'Cake' . DS . 'Console' . DS . 'ShellDispatcher.php'; + +if (function_exists('ini_set')) { + $root = dirname(dirname(dirname(__FILE__))); + $appDir = basename(dirname(dirname(__FILE__))); + $install = $root . DS . 'lib'; + $composerInstall = $root . DS . $appDir . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib'; + + // the following lines differ from its sibling + // /lib/Cake/Console/Templates/skel/Console/cake.php + if (file_exists($composerInstall . DS . $dispatcher)) { + $install = $composerInstall; + } + + ini_set('include_path', $install . PATH_SEPARATOR . ini_get('include_path')); + unset($root, $appDir, $install, $composerInstall); } -unset($paths, $path, $dispatcher, $root, $ds); + +if (!include $dispatcher) { + trigger_error('Could not locate CakePHP core files.', E_USER_ERROR); +} +unset($dispatcher); return ShellDispatcher::run($argv); diff --git a/app/Lib/Tools/SecurityAudit.php b/app/Lib/Tools/SecurityAudit.php index 6a32a32c5..b775442a9 100644 --- a/app/Lib/Tools/SecurityAudit.php +++ b/app/Lib/Tools/SecurityAudit.php @@ -476,7 +476,7 @@ class SecurityAudit */ private function getCakeVersion() { - $filePath = APP . 'Lib/cakephp/lib/Cake/VERSION.txt'; + $filePath = CAKE_CORE_INCLUDE_PATH . '/Cake/VERSION.txt'; $version = file_get_contents($filePath); if (!$version) { throw new RuntimeException("Could not open CakePHP version file '$filePath'."); diff --git a/app/Lib/cakephp b/app/Lib/cakephp deleted file mode 160000 index cf14e6546..000000000 --- a/app/Lib/cakephp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cf14e6546ec44e3369e3531add11fdb946656280 diff --git a/app/composer.json b/app/composer.json index b4f89ce75..61a55a667 100644 --- a/app/composer.json +++ b/app/composer.json @@ -9,6 +9,7 @@ "ext-dom": "*", "ext-simplexml": "*", "ext-pcre": "*", + "cakephp/cakephp": "2.10.24", "kamisama/cake-resque": "4.1.2", "pear/crypt_gpg": "1.6.3", "monolog/monolog": "1.24.0" diff --git a/app/webroot/index.php b/app/webroot/index.php index da9846b6c..6ec12a60a 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -56,7 +56,17 @@ if (!defined('APP_DIR')) { * * Leaving this constant undefined will result in it being defined in Cake/bootstrap.php */ - define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . APP_DIR . DS .'Lib' . DS . 'cakephp' . DS . 'lib'); +// define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . APP_DIR . DS .'Lib' . DS . 'cakephp' . DS . 'lib'); + +/** + * This auto-detects CakePHP as a composer installed library. + * You may remove this if you are not planning to use composer (not recommended, though). + */ +$vendorPath = ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib'; +$dispatcher = 'Cake' . DS . 'Console' . DS . 'ShellDispatcher.php'; +if (!defined('CAKE_CORE_INCLUDE_PATH') && file_exists($vendorPath . DS . $dispatcher)) { + define('CAKE_CORE_INCLUDE_PATH', $vendorPath); +} /** * Editing below this line should NOT be necessary.