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

@ -1,28 +1,27 @@
<?php
/**
* File Storage engine for cache. Filestorage is the slowest cache storage
* to read and write. However, it is good for servers that don't have other storage
* File Storage engine for cache. Filestorage is the slowest cache storage
* to read and write. However, it is good for servers that don't have other storage
* engine available, or have content which is not performance sensitive.
*
* You can configure a FileEngine cache, using Cache::config()
*
* 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 1.2.0.4933
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
/**
* File Storage engine for cache. Filestorage is the slowest cache storage
* to read and write. However, it is good for servers that don't have other storage
* File Storage engine for cache. Filestorage is the slowest cache storage
* to read and write. However, it is good for servers that don't have other storage
* engine available, or have content which is not performance sensitive.
*
* You can configure a FileEngine cache, using Cache::config()
@ -43,7 +42,7 @@ class FileEngine extends CacheEngine {
*
* - path = absolute path to cache directory, default => CACHE
* - prefix = string prefix for filename, default => cake_
* - lock = enable file locking on write, default => false
* - lock = enable file locking on write, default => true
* - serialize = serialize the data, default => true
*
* @var array
@ -54,7 +53,7 @@ class FileEngine extends CacheEngine {
/**
* True unless FileEngine::__active(); fails
*
* @var boolean
* @var bool
*/
protected $_init = true;
@ -65,7 +64,7 @@ class FileEngine extends CacheEngine {
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
* @return boolean True if the engine has been successfully initialized, false if not
* @return bool True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
$settings += array(
@ -94,8 +93,8 @@ class FileEngine extends CacheEngine {
/**
* Garbage collection. Permanently remove all expired and deleted data
*
* @param integer $expires [optional] An expires timestamp, invalidataing all data before.
* @return boolean True if garbage collection was successful, false on failure
* @param int $expires [optional] An expires timestamp, invalidating all data before.
* @return bool True if garbage collection was successful, false on failure
*/
public function gc($expires = null) {
return $this->clear(true);
@ -106,11 +105,11 @@ class FileEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @param mixed $data Data to be cached
* @param integer $duration How long to cache the data, in seconds
* @return boolean True if the data was successfully cached, false on failure
* @param int $duration How long to cache the data, in seconds
* @return bool True if the data was successfully cached, false on failure
*/
public function write($key, $data, $duration) {
if ($data === '' || !$this->_init) {
if (!$this->_init) {
return false;
}
@ -133,7 +132,7 @@ class FileEngine extends CacheEngine {
}
$expires = time() + $duration;
$contents = $expires . $lineBreak . $data . $lineBreak;
$contents = implode(array($expires, $lineBreak, $data, $lineBreak));
if ($this->settings['lock']) {
$this->_File->flock(LOCK_EX);
@ -166,7 +165,7 @@ class FileEngine extends CacheEngine {
$this->_File->rewind();
$time = time();
$cachetime = intval($this->_File->current());
$cachetime = (int)$this->_File->current();
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
if ($this->settings['lock']) {
@ -201,7 +200,7 @@ class FileEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
* @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
* @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
if ($this->_setKey($key) === false || !$this->_init) {
@ -209,60 +208,104 @@ class FileEngine extends CacheEngine {
}
$path = $this->_File->getRealPath();
$this->_File = null;
return unlink($path);
//@codingStandardsIgnoreStart
return @unlink($path);
//@codingStandardsIgnoreEnd
}
/**
* Delete all values from the cache
*
* @param boolean $check Optional - only delete expired cache items
* @return boolean True if the cache was successfully cleared, false otherwise
* @param bool $check Optional - only delete expired cache items
* @return bool True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
if (!$this->_init) {
return false;
}
$dir = dir($this->settings['path']);
$this->_File = null;
$threshold = $now = false;
if ($check) {
$now = time();
$threshold = $now - $this->settings['duration'];
}
$this->_clearDirectory($this->settings['path'], $now, $threshold);
$directory = new RecursiveDirectoryIterator($this->settings['path']);
$contents = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
$cleared = array();
foreach ($contents as $path) {
if ($path->isFile()) {
continue;
}
$path = $path->getRealPath() . DS;
if (!in_array($path, $cleared)) {
$this->_clearDirectory($path, $now, $threshold);
$cleared[] = $path;
}
}
return true;
}
/**
* Used to clear a directory of matching files.
*
* @param string $path The path to search.
* @param int $now The current timestamp
* @param int $threshold Any file not modified after this value will be deleted.
* @return void
*/
protected function _clearDirectory($path, $now, $threshold) {
$prefixLength = strlen($this->settings['prefix']);
if (!is_dir($path)) {
return;
}
$dir = dir($path);
while (($entry = $dir->read()) !== false) {
if (substr($entry, 0, $prefixLength) !== $this->settings['prefix']) {
continue;
}
if ($this->_setKey($entry) === false) {
try {
$file = new SplFileObject($path . $entry, 'r');
} catch (Exception $e) {
continue;
}
if ($check) {
$mtime = $this->_File->getMTime();
if ($threshold) {
$mtime = $file->getMTime();
if ($mtime > $threshold) {
continue;
}
$expires = (int)$this->_File->current();
$expires = (int)$file->current();
if ($expires > $now) {
continue;
}
}
$path = $this->_File->getRealPath();
$this->_File = null;
if (file_exists($path)) {
unlink($path);
if ($file->isFile()) {
$filePath = $file->getRealPath();
$file = null;
//@codingStandardsIgnoreStart
@unlink($filePath);
//@codingStandardsIgnoreEnd
}
}
$dir->close();
return true;
}
/**
* Not implemented
*
* @param string $key
* @param integer $offset
* @param string $key The key to decrement
* @param int $offset The number to offset
* @return void
* @throws CacheException
*/
@ -273,8 +316,8 @@ class FileEngine extends CacheEngine {
/**
* Not implemented
*
* @param string $key
* @param integer $offset
* @param string $key The key to decrement
* @param int $offset The number to offset
* @return void
* @throws CacheException
*/
@ -287,8 +330,8 @@ class FileEngine extends CacheEngine {
* for the cache file the key is referring to.
*
* @param string $key The key
* @param boolean $createKey Whether the key should be created if it doesn't exists, or not
* @return boolean true if the cache key could be set, false otherwise
* @param bool $createKey Whether the key should be created if it doesn't exists, or not
* @return bool true if the cache key could be set, false otherwise
*/
protected function _setKey($key, $createKey = false) {
$groups = null;
@ -298,7 +341,7 @@ class FileEngine extends CacheEngine {
$dir = $this->settings['path'] . $groups;
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
mkdir($dir, 0775, true);
}
$path = new SplFileInfo($dir . $key);
@ -327,10 +370,16 @@ class FileEngine extends CacheEngine {
/**
* Determine is cache directory is writable
*
* @return boolean
* @return bool
*/
protected function _active() {
$dir = new SplFileInfo($this->settings['path']);
if (Configure::read('debug')) {
$path = $dir->getPathname();
if (!is_dir($path)) {
mkdir($path, 0775, true);
}
}
if ($this->_init && !($dir->isDir() && $dir->isWritable())) {
$this->_init = false;
trigger_error(__d('cake_dev', '%s is not writable', $this->settings['path']), E_USER_WARNING);
@ -350,24 +399,51 @@ class FileEngine extends CacheEngine {
return false;
}
$key = Inflector::underscore(str_replace(array(DS, '/', '.'), '_', strval($key)));
$key = Inflector::underscore(str_replace(array(DS, '/', '.', '<', '>', '?', ':', '|', '*', '"'), '_', strval($key)));
return $key;
}
/**
* Recursively deletes all files under any directory named as $group
*
* @return boolean success
**/
* @param string $group The group to clear.
* @return bool success
*/
public function clearGroup($group) {
$this->_File = null;
$directoryIterator = new RecursiveDirectoryIterator($this->settings['path']);
$contents = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($contents as $object) {
$containsGroup = strpos($object->getPathName(), DS . $group . DS) !== false;
if ($object->isFile() && $containsGroup) {
unlink($object->getPathName());
$hasPrefix = true;
if (strlen($this->settings['prefix']) !== 0) {
$hasPrefix = strpos($object->getBaseName(), $this->settings['prefix']) === 0;
}
if ($object->isFile() && $containsGroup && $hasPrefix) {
$path = $object->getPathName();
$object = null;
//@codingStandardsIgnoreStart
@unlink($path);
//@codingStandardsIgnoreEnd
}
}
return true;
}
/**
* Write data for key into cache if it doesn't exist already.
* If it already exists, it fails and returns false.
*
* @param string $key Identifier for the data.
* @param mixed $value Data to be cached.
* @param int $duration How long to cache the data, in seconds.
* @return bool True if the data was successfully cached, false on failure.
*/
public function add($key, $value, $duration) {
$cachedValue = $this->read($key);
if ($cachedValue === false) {
return $this->write($key, $value, $duration);
}
return false;
}
}