Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,18 +2,17 @@
/**
* ShellDispatcher file
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://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)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
@ -44,16 +43,14 @@ class ShellDispatcher {
* a status code of either 0 or 1 according to the result of the dispatch.
*
* @param array $args the argv from PHP
* @param boolean $bootstrap Should the environment be bootstrapped.
* @param bool $bootstrap Should the environment be bootstrapped.
*/
public function __construct($args = array(), $bootstrap = true) {
set_time_limit(0);
$this->parseParams($args);
if ($bootstrap) {
$this->_initConstants();
}
$this->parseParams($args);
if ($bootstrap) {
$this->_initEnvironment();
}
}
@ -66,7 +63,7 @@ class ShellDispatcher {
*/
public static function run($argv) {
$dispatcher = new ShellDispatcher($argv);
$dispatcher->_stop($dispatcher->dispatch() === false ? 1 : 0);
return $dispatcher->_stop($dispatcher->dispatch() === false ? 1 : 0);
}
/**
@ -82,9 +79,11 @@ class ShellDispatcher {
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('DS', DIRECTORY_SEPARATOR);
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))));
define('CAKEPHP_SHELL', true);
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('CORE_PATH')) {
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
@ -115,18 +114,33 @@ class ShellDispatcher {
}
/**
* Initializes the environment and loads the Cake core.
* Initializes the environment and loads the CakePHP core.
*
* @return boolean Success.
* @return bool Success.
*/
protected function _bootstrap() {
define('ROOT', $this->params['root']);
define('APP_DIR', $this->params['app']);
define('APP', $this->params['working'] . DS);
define('WWW_ROOT', APP . $this->params['webroot'] . DS);
if (!is_dir(ROOT . DS . APP_DIR . DS . 'tmp')) {
if (!defined('ROOT')) {
define('ROOT', $this->params['root']);
}
if (!defined('APP_DIR')) {
define('APP_DIR', $this->params['app']);
}
if (!defined('APP')) {
define('APP', $this->params['working'] . DS);
}
if (!defined('WWW_ROOT')) {
if (!$this->_isAbsolutePath($this->params['webroot'])) {
$webroot = realpath(APP . $this->params['webroot']);
} else {
$webroot = $this->params['webroot'];
}
define('WWW_ROOT', $webroot . DS);
}
if (!defined('TMP') && !is_dir(APP . 'tmp')) {
define('TMP', CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Console' . DS . 'Templates' . DS . 'skel' . DS . 'tmp' . DS);
}
// $boot is used by Cake/bootstrap.php file
$boot = file_exists(ROOT . DS . APP_DIR . DS . 'Config' . DS . 'bootstrap.php');
require CORE_PATH . 'Cake' . DS . 'bootstrap.php';
@ -138,7 +152,9 @@ class ShellDispatcher {
$this->setErrorHandlers();
if (!defined('FULL_BASE_URL')) {
define('FULL_BASE_URL', 'http://localhost');
$url = Configure::read('App.fullBaseUrl');
define('FULL_BASE_URL', $url ? $url : 'http://localhost');
Configure::write('App.fullBaseUrl', FULL_BASE_URL);
}
return true;
@ -168,12 +184,15 @@ class ShellDispatcher {
}
set_exception_handler($exception['consoleHandler']);
set_error_handler($error['consoleHandler'], Configure::read('Error.level'));
App::uses('Debugger', 'Utility');
Debugger::getInstance()->output('txt');
}
/**
* Dispatches a CLI request
*
* @return boolean
* @return bool
* @throws MissingShellMethodException
*/
public function dispatch() {
@ -197,12 +216,11 @@ class ShellDispatcher {
if ($Shell instanceof Shell) {
$Shell->initialize();
$Shell->loadTasks();
return $Shell->runCommand($command, $this->args);
}
$methods = array_diff(get_class_methods($Shell), get_class_methods('Shell'));
$added = in_array($command, $methods);
$private = $command[0] == '_' && method_exists($Shell, $command);
$private = $command[0] === '_' && method_exists($Shell, $command);
if (!$private) {
if ($added) {
@ -238,6 +256,11 @@ class ShellDispatcher {
App::uses('AppShell', 'Console/Command');
App::uses($class, $plugin . 'Console/Command');
if (!class_exists($class)) {
$plugin = Inflector::camelize($shell) . '.';
App::uses($class, $plugin . 'Console/Command');
}
if (!class_exists($class)) {
throw new MissingShellException(array(
'class' => $class
@ -276,7 +299,11 @@ class ShellDispatcher {
if (isset($params['working'])) {
$params['working'] = trim($params['working']);
}
if (!empty($params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0]{0} !== '.')) {
if (!empty($params['working']) && (!isset($this->args[0]) || isset($this->args[0]) && $this->args[0][0] !== '.')) {
if ($params['working'][0] === '.') {
$params['working'] = realpath($params['working']);
}
if (empty($this->params['app']) && $params['working'] != $params['root']) {
$params['root'] = dirname($params['working']);
$params['app'] = basename($params['working']);
@ -285,34 +312,55 @@ class ShellDispatcher {
}
}
if ($params['app'][0] == '/' || preg_match('/([a-z])(:)/i', $params['app'], $matches)) {
if ($this->_isAbsolutePath($params['app'])) {
$params['root'] = dirname($params['app']);
} elseif (strpos($params['app'], '/')) {
$params['root'] .= '/' . dirname($params['app']);
}
$isWindowsAppPath = $this->_isWindowsPath($params['app']);
$params['app'] = basename($params['app']);
$params['working'] = rtrim($params['root'], '/');
if (!$isWin || !preg_match('/^[A-Z]:$/i', $params['app'])) {
$params['working'] .= '/' . $params['app'];
}
if (!empty($matches[0]) || !empty($isWin)) {
if ($isWindowsAppPath || !empty($isWin)) {
$params = str_replace('/', '\\', $params);
}
$this->params = array_merge($this->params, $params);
$this->params = $params + $this->params;
}
/**
* Checks whether the given path is absolute or relative.
*
* @param string $path absolute or relative path.
* @return bool
*/
protected function _isAbsolutePath($path) {
return $path[0] === '/' || $this->_isWindowsPath($path);
}
/**
* Checks whether the given path is Window OS path.
*
* @param string $path absolute path.
* @return bool
*/
protected function _isWindowsPath($path) {
return preg_match('/([a-z])(:)/i', $path) == 1;
}
/**
* Parses out the paths from from the argv
*
* @param array $args
* @param array $args The argv to parse.
* @return void
*/
protected function _parsePaths($args) {
$parsed = array();
$keys = array('-working', '--working', '-app', '--app', '-root', '--root');
$keys = array('-working', '--working', '-app', '--app', '-root', '--root', '-webroot', '--webroot');
$args = (array)$args;
foreach ($keys as $key) {
while (($index = array_search($key, $args)) !== false) {
$keyname = str_replace('-', '', $key);
@ -335,7 +383,7 @@ class ShellDispatcher {
}
/**
* Shows console help. Performs an internal dispatch to the CommandList Shell
* Shows console help. Performs an internal dispatch to the CommandList Shell
*
* @return void
*/
@ -347,7 +395,7 @@ class ShellDispatcher {
/**
* Stop execution of the current script
*
* @param integer|string $status see http://php.net/exit for values
* @param int|string $status see http://php.net/exit for values
* @return void
*/
protected function _stop($status = 0) {