Version Notes
1.6.0.0
Download this release
Release Info
Developer | Magento Core Team |
Extension | Lib_Varien |
Version | 1.6.0.0 |
Comparing to | |
See all releases |
Version 1.6.0.0
- lib/Varien/Autoload.php +170 -0
- lib/Varien/Cache/Backend/Database.php +544 -0
- lib/Varien/Cache/Backend/Eaccelerator.php +340 -0
- lib/Varien/Cache/Core.php +130 -0
- lib/Varien/Convert.php +51 -0
- lib/Varien/Convert/Action.php +38 -0
- lib/Varien/Convert/Action/Abstract.php +199 -0
- lib/Varien/Convert/Action/Interface.php +43 -0
- lib/Varien/Convert/Adapter/Abstract.php +65 -0
- lib/Varien/Convert/Adapter/Db/Table.php +54 -0
- lib/Varien/Convert/Adapter/Http.php +98 -0
- lib/Varien/Convert/Adapter/Http/Curl.php +71 -0
- lib/Varien/Convert/Adapter/Interface.php +40 -0
- lib/Varien/Convert/Adapter/Io.php +81 -0
- lib/Varien/Convert/Adapter/Soap.php +46 -0
- lib/Varien/Convert/Adapter/Std.php +53 -0
- lib/Varien/Convert/Adapter/Zend/Cache.php +56 -0
- lib/Varien/Convert/Adapter/Zend/Db.php +54 -0
- lib/Varien/Convert/Container/Abstract.php +166 -0
- lib/Varien/Convert/Container/Collection.php +73 -0
- lib/Varien/Convert/Container/Generic.php +38 -0
- lib/Varien/Convert/Container/Interface.php +38 -0
- lib/Varien/Convert/Exception.php +80 -0
- lib/Varien/Convert/Mapper/Abstract.php +38 -0
- lib/Varien/Convert/Mapper/Column.php +60 -0
- lib/Varien/Convert/Mapper/Interface.php +38 -0
- lib/Varien/Convert/Parser/Abstract.php +38 -0
- lib/Varien/Convert/Parser/Csv.php +170 -0
- lib/Varien/Convert/Parser/Interface.php +40 -0
- lib/Varien/Convert/Parser/Serialize.php +48 -0
- lib/Varien/Convert/Parser/Xml/Excel.php +228 -0
- lib/Varien/Convert/Profile.php +38 -0
- lib/Varien/Convert/Profile/Abstract.php +120 -0
- lib/Varien/Convert/Profile/Collection.php +160 -0
- lib/Varien/Convert/Validator/Abstract.php +38 -0
- lib/Varien/Convert/Validator/Column.php +38 -0
- lib/Varien/Convert/Validator/Dryrun.php +46 -0
- lib/Varien/Convert/Validator/Interface.php +38 -0
- lib/Varien/Crypt.php +49 -0
- lib/Varien/Crypt/Abstract.php +38 -0
- lib/Varien/Crypt/Mcrypt.php +138 -0
- lib/Varien/Data/Collection.php +805 -0
- lib/Varien/Data/Collection/Db.php +793 -0
- lib/Varien/Data/Collection/Filesystem.php +701 -0
- lib/Varien/Data/Form.php +258 -0
- lib/Varien/Data/Form/Abstract.php +211 -0
- lib/Varien/Data/Form/Element/Abstract.php +296 -0
- lib/Varien/Data/Form/Element/Button.php +42 -0
- lib/Varien/Data/Form/Element/Checkbox.php +79 -0
- lib/Varien/Data/Form/Element/Checkboxes.php +202 -0
- lib/Varien/Data/Form/Element/Collection.php +209 -0
- lib/Varien/Data/Form/Element/Column.php +41 -0
- lib/Varien/Data/Form/Element/Date.php +190 -0
- lib/Varien/Data/Form/Element/Editor.php +399 -0
- lib/Varien/Data/Form/Element/Fieldset.php +186 -0
- lib/Varien/Data/Form/Element/File.php +42 -0
- lib/Varien/Data/Form/Element/Gallery.php +186 -0
- lib/Varien/Data/Form/Element/Hidden.php +51 -0
- lib/Varien/Data/Form/Element/Image.php +124 -0
- lib/Varien/Data/Form/Element/Imagefile.php +45 -0
- lib/Varien/Data/Form/Element/Label.php +51 -0
- lib/Varien/Data/Form/Element/Link.php +68 -0
- lib/Varien/Data/Form/Element/Multiline.php +105 -0
- lib/Varien/Data/Form/Element/Multiselect.php +148 -0
- lib/Varien/Data/Form/Element/Note.php +49 -0
- lib/Varien/Data/Form/Element/Obscure.php +65 -0
- lib/Varien/Data/Form/Element/Password.php +48 -0
- lib/Varien/Data/Form/Element/Radio.php +42 -0
- lib/Varien/Data/Form/Element/Radios.php +86 -0
- lib/Varien/Data/Form/Element/Renderer/Interface.php +37 -0
- lib/Varien/Data/Form/Element/Reset.php +42 -0
- lib/Varien/Data/Form/Element/Select.php +123 -0
- lib/Varien/Data/Form/Element/Submit.php +48 -0
- lib/Varien/Data/Form/Element/Text.php +53 -0
- lib/Varien/Data/Form/Element/Textarea.php +59 -0
- lib/Varien/Data/Form/Element/Time.php +92 -0
- lib/Varien/Data/Form/Filter/Date.php +109 -0
- lib/Varien/Data/Form/Filter/Escapehtml.php +58 -0
- lib/Varien/Data/Form/Filter/Interface.php +52 -0
- lib/Varien/Data/Form/Filter/Striptags.php +58 -0
- lib/Varien/Data/Tree.php +225 -0
- lib/Varien/Data/Tree/Db.php +305 -0
- lib/Varien/Data/Tree/Dbp.php +394 -0
- lib/Varien/Data/Tree/Node.php +275 -0
- lib/Varien/Data/Tree/Node/Collection.php +132 -0
- lib/Varien/Date.php +182 -0
- lib/Varien/Db/Adapter/Interface.php +965 -0
- lib/Varien/Db/Adapter/Mysqli.php +283 -0
- lib/Varien/Db/Adapter/Pdo/Mysql.php +3488 -0
- lib/Varien/Db/Ddl/Table.php +694 -0
- lib/Varien/Db/Exception.php +29 -0
- lib/Varien/Db/Helper.php +110 -0
- lib/Varien/Db/Select.php +474 -0
- lib/Varien/Db/Statement/Parameter.php +248 -0
- lib/Varien/Db/Statement/Pdo/Mysql.php +113 -0
- lib/Varien/Db/Tree.php +561 -0
- lib/Varien/Db/Tree/Exception.php +31 -0
- lib/Varien/Db/Tree/Node.php +108 -0
- lib/Varien/Db/Tree/Node/Exception.php +29 -0
- lib/Varien/Db/Tree/NodeSet.php +83 -0
- lib/Varien/Db/Tree/NodeSet/Exception.php +29 -0
- lib/Varien/Debug.php +204 -0
- lib/Varien/Directory/Collection.php +461 -0
- lib/Varien/Directory/Factory.php +58 -0
- lib/Varien/Directory/IFactory.php +44 -0
- lib/Varien/Directory/a.txt +1352 -0
- lib/Varien/Event.php +122 -0
- lib/Varien/Event/Collection.php +147 -0
- lib/Varien/Event/Observer.php +115 -0
- lib/Varien/Event/Observer/Collection.php +111 -0
- lib/Varien/Event/Observer/Cron.php +158 -0
- lib/Varien/Event/Observer/Regex.php +47 -0
- lib/Varien/Exception.php +52 -0
- lib/Varien/File/Csv.php +171 -0
- lib/Varien/File/CsvMulty.php +75 -0
- lib/Varien/File/Object.php +294 -0
- lib/Varien/File/Transfer/Adapter/Http.php +153 -0
- lib/Varien/File/Uploader.php +542 -0
- lib/Varien/File/Uploader/Image.php +366 -0
- lib/Varien/Filter/Array.php +56 -0
- lib/Varien/Filter/Array/Grid.php +38 -0
- lib/Varien/Filter/Email.php +34 -0
- lib/Varien/Filter/Money.php +41 -0
- lib/Varien/Filter/Object.php +60 -0
- lib/Varien/Filter/Object/Grid.php +40 -0
- lib/Varien/Filter/Sprintf.php +51 -0
- lib/Varien/Filter/Template.php +272 -0
- lib/Varien/Filter/Template/Simple.php +44 -0
- lib/Varien/Filter/Template/Tokenizer/Abstract.php +121 -0
- lib/Varien/Filter/Template/Tokenizer/Parameter.php +98 -0
- lib/Varien/Filter/Template/Tokenizer/Variable.php +185 -0
- lib/Varien/Http/Adapter/Curl.php +238 -0
- lib/Varien/Http/Client.php +93 -0
- lib/Varien/Image.php +318 -0
- lib/Varien/Image/Adapter.php +59 -0
- lib/Varien/Image/Adapter/Abstract.php +259 -0
- lib/Varien/Image/Adapter/Gd2.php +538 -0
- lib/Varien/Io/Abstract.php +118 -0
- lib/Varien/Io/Exception.php +37 -0
- lib/Varien/Io/File.php +813 -0
- lib/Varien/Io/Ftp.php +327 -0
- lib/Varien/Io/Interface.php +114 -0
- lib/Varien/Io/Sftp.php +236 -0
- lib/Varien/Object.php +918 -0
- lib/Varien/Object/Cache.php +457 -0
- lib/Varien/Object/Mapper.php +120 -0
- lib/Varien/Pear.php +297 -0
- lib/Varien/Pear/Frontend.php +127 -0
- lib/Varien/Pear/Package.php +221 -0
- lib/Varien/Pear/Registry.php +73 -0
- lib/Varien/Profiler.php +185 -0
- lib/Varien/Simplexml/Config.php +604 -0
- lib/Varien/Simplexml/Config/Cache/Abstract.php +98 -0
- lib/Varien/Simplexml/Config/Cache/File.php +110 -0
- lib/Varien/Simplexml/Element.php +631 -0
- package.xml +18 -0
lib/Varien/Autoload.php
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Varien
|
22 |
+
* @package Varien_Autoload
|
23 |
+
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Classes source autoload
|
29 |
+
*/
|
30 |
+
class Varien_Autoload
|
31 |
+
{
|
32 |
+
const SCOPE_FILE_PREFIX = '__';
|
33 |
+
|
34 |
+
static protected $_instance;
|
35 |
+
static protected $_scope = 'default';
|
36 |
+
|
37 |
+
protected $_isIncludePathDefined= null;
|
38 |
+
protected $_collectClasses = false;
|
39 |
+
protected $_collectPath = null;
|
40 |
+
protected $_arrLoadedClasses = array();
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Class constructor
|
44 |
+
*/
|
45 |
+
public function __construct()
|
46 |
+
{
|
47 |
+
$this->_isIncludePathDefined = defined('COMPILER_INCLUDE_PATH');
|
48 |
+
if (defined('COMPILER_COLLECT_PATH')) {
|
49 |
+
$this->_collectClasses = true;
|
50 |
+
$this->_collectPath = COMPILER_COLLECT_PATH;
|
51 |
+
}
|
52 |
+
self::registerScope(self::$_scope);
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Singleton pattern implementation
|
57 |
+
*
|
58 |
+
* @return Varien_Autoload
|
59 |
+
*/
|
60 |
+
static public function instance()
|
61 |
+
{
|
62 |
+
if (!self::$_instance) {
|
63 |
+
self::$_instance = new Varien_Autoload();
|
64 |
+
}
|
65 |
+
return self::$_instance;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Register SPL autoload function
|
70 |
+
*/
|
71 |
+
static public function register()
|
72 |
+
{
|
73 |
+
spl_autoload_register(array(self::instance(), 'autoload'));
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Load class source code
|
78 |
+
*
|
79 |
+
* @param string $class
|
80 |
+
*/
|
81 |
+
public function autoload($class)
|
82 |
+
{
|
83 |
+
if ($this->_collectClasses) {
|
84 |
+
$this->_arrLoadedClasses[self::$_scope][] = $class;
|
85 |
+
}
|
86 |
+
if ($this->_isIncludePathDefined) {
|
87 |
+
$classFile = $class;
|
88 |
+
} else {
|
89 |
+
$classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));
|
90 |
+
}
|
91 |
+
$classFile.= '.php';
|
92 |
+
//echo $classFile;die();
|
93 |
+
return include $classFile;
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Register autoload scope
|
98 |
+
* This process allow include scope file which can contain classes
|
99 |
+
* definition which are used for this scope
|
100 |
+
*
|
101 |
+
* @param string $code scope code
|
102 |
+
*/
|
103 |
+
static public function registerScope($code)
|
104 |
+
{
|
105 |
+
self::$_scope = $code;
|
106 |
+
if (defined('COMPILER_INCLUDE_PATH')) {
|
107 |
+
@include_once self::SCOPE_FILE_PREFIX.$code.'.php';
|
108 |
+
}
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Get current autoload scope
|
113 |
+
*
|
114 |
+
* @return string
|
115 |
+
*/
|
116 |
+
static public function getScope()
|
117 |
+
{
|
118 |
+
return self::$_scope;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Class destructor
|
123 |
+
*/
|
124 |
+
public function __destruct()
|
125 |
+
{
|
126 |
+
if ($this->_collectClasses) {
|
127 |
+
$this->_saveCollectedStat();
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Save information about used classes per scope with class popularity
|
133 |
+
* Class_Name:popularity
|
134 |
+
*
|
135 |
+
* @return Varien_Autoload
|
136 |
+
*/
|
137 |
+
protected function _saveCollectedStat()
|
138 |
+
{
|
139 |
+
if (!is_dir($this->_collectPath)) {
|
140 |
+
@mkdir($this->_collectPath);
|
141 |
+
@chmod($this->_collectPath, 0777);
|
142 |
+
}
|
143 |
+
|
144 |
+
if (!is_writeable($this->_collectPath)) {
|
145 |
+
return $this;
|
146 |
+
}
|
147 |
+
|
148 |
+
foreach ($this->_arrLoadedClasses as $scope => $classes) {
|
149 |
+
$file = $this->_collectPath.DIRECTORY_SEPARATOR.$scope.'.csv';
|
150 |
+
$data = array();
|
151 |
+
if (file_exists($file)) {
|
152 |
+
$data = explode("\n", file_get_contents($file));
|
153 |
+
foreach ($data as $index => $class) {
|
154 |
+
$class = explode(':', $class);
|
155 |
+
$searchIndex = array_search($class[0], $classes);
|
156 |
+
if ($searchIndex !== false) {
|
157 |
+
$class[1]+=1;
|
158 |
+
unset($classes[$searchIndex]);
|
159 |
+
}
|
160 |
+
$data[$index] = $class[0].':'.$class[1];
|
161 |
+
}
|
162 |
+
}
|
163 |
+
foreach ($classes as $class) {
|
164 |
+
$data[] = $class . ':1';
|
165 |
+
}
|
166 |
+
file_put_contents($file, implode("\n", $data));
|
167 |
+
}
|
168 |
+
return $this;
|
169 |
+
}
|
170 |
+
}
|
lib/Varien/Cache/Backend/Database.php
ADDED
@@ -0,0 +1,544 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Varien
|
22 |
+
* @package Varien_Cache
|
23 |
+
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
Tables declaration:
|
29 |
+
|
30 |
+
CREATE TABLE IF NOT EXISTS `core_cache` (
|
31 |
+
`id` VARCHAR(255) NOT NULL,
|
32 |
+
`data` mediumblob,
|
33 |
+
`create_time` int(11),
|
34 |
+
`update_time` int(11),
|
35 |
+
`expire_time` int(11),
|
36 |
+
PRIMARY KEY (`id`),
|
37 |
+
KEY `IDX_EXPIRE_TIME` (`expire_time`)
|
38 |
+
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
39 |
+
|
40 |
+
CREATE TABLE IF NOT EXISTS `core_cache_tag` (
|
41 |
+
`tag` VARCHAR(255) NOT NULL,
|
42 |
+
`cache_id` VARCHAR(255) NOT NULL,
|
43 |
+
KEY `IDX_TAG` (`tag`),
|
44 |
+
KEY `IDX_CACHE_ID` (`cache_id`),
|
45 |
+
CONSTRAINT `FK_CORE_CACHE_TAG` FOREIGN KEY (`cache_id`) REFERENCES `core_cache` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
46 |
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
47 |
+
*/
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Database cache backend
|
51 |
+
*/
|
52 |
+
class Varien_Cache_Backend_Database extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
53 |
+
{
|
54 |
+
/**
|
55 |
+
* Available options
|
56 |
+
*
|
57 |
+
* @var array available options
|
58 |
+
*/
|
59 |
+
protected $_options = array(
|
60 |
+
'adapter' => '',
|
61 |
+
'adapter_callback' => '',
|
62 |
+
'data_table' => '',
|
63 |
+
'tags_table' => '',
|
64 |
+
'store_data' => true,
|
65 |
+
);
|
66 |
+
|
67 |
+
protected $_adapter = null;
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Constructor
|
71 |
+
*
|
72 |
+
* @param array $options associative array of options
|
73 |
+
*/
|
74 |
+
public function __construct($options = array())
|
75 |
+
{
|
76 |
+
parent::__construct($options);
|
77 |
+
if (empty($this->_options['adapter_callback'])) {
|
78 |
+
if (!($this->_options['adapter'] instanceof Zend_Db_Adapter_Abstract)) {
|
79 |
+
Zend_Cache::throwException('Option "adapter" should be declared and extend Zend_Db_Adapter_Abstract!');
|
80 |
+
}
|
81 |
+
}
|
82 |
+
if (empty($this->_options['data_table']) || empty ($this->_options['tags_table'])) {
|
83 |
+
Zend_Cache::throwException('Options "data_table" and "tags_table" should be declared!');
|
84 |
+
}
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Get DB adapter
|
89 |
+
*
|
90 |
+
* @return Zend_Db_Adapter_Abstract
|
91 |
+
*/
|
92 |
+
protected function _getAdapter()
|
93 |
+
{
|
94 |
+
if (!$this->_adapter) {
|
95 |
+
if (!empty($this->_options['adapter_callback'])) {
|
96 |
+
$adapter = call_user_func($this->_options['adapter_callback']);
|
97 |
+
} else {
|
98 |
+
$adapter = $this->_options['adapter'];
|
99 |
+
}
|
100 |
+
if (!($adapter instanceof Zend_Db_Adapter_Abstract)) {
|
101 |
+
Zend_Cache::throwException('DB Adapter should be declared and extend Zend_Db_Adapter_Abstract');
|
102 |
+
} else {
|
103 |
+
$this->_adapter = $adapter;
|
104 |
+
}
|
105 |
+
}
|
106 |
+
return $this->_adapter;
|
107 |
+
}
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Get table name where data is stored
|
111 |
+
*
|
112 |
+
* @return string
|
113 |
+
*/
|
114 |
+
protected function _getDataTable()
|
115 |
+
{
|
116 |
+
return $this->_options['data_table'];
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Get table name where tags are stored
|
121 |
+
*
|
122 |
+
* @return string
|
123 |
+
*/
|
124 |
+
protected function _getTagsTable()
|
125 |
+
{
|
126 |
+
return $this->_options['tags_table'];
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Test if a cache is available for the given id and (if yes) return it (false else)
|
131 |
+
*
|
132 |
+
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
133 |
+
*
|
134 |
+
* @param string $id Cache id
|
135 |
+
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
136 |
+
* @return string|false cached datas
|
137 |
+
*/
|
138 |
+
public function load($id, $doNotTestCacheValidity = false)
|
139 |
+
{
|
140 |
+
if ($this->_options['store_data']) {
|
141 |
+
$select = $this->_getAdapter()->select()
|
142 |
+
->from($this->_getDataTable(), 'data')
|
143 |
+
->where('id=:cache_id');
|
144 |
+
|
145 |
+
if (!$doNotTestCacheValidity) {
|
146 |
+
$select->where('expire_time=0 OR expire_time>?', time());
|
147 |
+
}
|
148 |
+
return $this->_getAdapter()->fetchOne($select, array('cache_id'=>$id));
|
149 |
+
} else {
|
150 |
+
return false;
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Test if a cache is available or not (for the given id)
|
156 |
+
*
|
157 |
+
* @param string $id cache id
|
158 |
+
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
159 |
+
*/
|
160 |
+
public function test($id)
|
161 |
+
{
|
162 |
+
if ($this->_options['store_data']) {
|
163 |
+
$select = $this->_getAdapter()->select()
|
164 |
+
->from($this->_getDataTable(), 'update_time')
|
165 |
+
->where('id=:cache_id')
|
166 |
+
->where('expire_time=0 OR expire_time>?', time());
|
167 |
+
return $this->_getAdapter()->fetchOne($select, array('cache_id'=>$id));
|
168 |
+
} else {
|
169 |
+
return false;
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Save some string datas into a cache record
|
175 |
+
*
|
176 |
+
* Note : $data is always "string" (serialization is done by the
|
177 |
+
* core not by the backend)
|
178 |
+
*
|
179 |
+
* @param string $data Datas to cache
|
180 |
+
* @param string $id Cache id
|
181 |
+
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
182 |
+
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
183 |
+
* @return boolean true if no problem
|
184 |
+
*/
|
185 |
+
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
186 |
+
{
|
187 |
+
if ($this->_options['store_data']) {
|
188 |
+
$adapter = $this->_getAdapter();
|
189 |
+
$dataTable = $this->_getDataTable();
|
190 |
+
|
191 |
+
$lifetime = $this->getLifetime($specificLifetime);
|
192 |
+
$time = time();
|
193 |
+
$expire = ($lifetime === 0 || $lifetime === null) ? 0 : $time+$lifetime;
|
194 |
+
|
195 |
+
$dataCol = $adapter->quoteIdentifier('data');
|
196 |
+
$expireCol = $adapter->quoteIdentifier('expire_time');
|
197 |
+
$query = "INSERT INTO {$dataTable} (
|
198 |
+
{$adapter->quoteIdentifier('id')},
|
199 |
+
{$dataCol},
|
200 |
+
{$adapter->quoteIdentifier('create_time')},
|
201 |
+
{$adapter->quoteIdentifier('update_time')},
|
202 |
+
{$expireCol})
|
203 |
+
VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE
|
204 |
+
{$dataCol}=VALUES({$dataCol}),
|
205 |
+
{$expireCol}=VALUES({$expireCol})";
|
206 |
+
|
207 |
+
$result = $adapter->query($query, array($id, $data, $time, $time, $expire))->rowCount();
|
208 |
+
if (!$result) {
|
209 |
+
return false;
|
210 |
+
}
|
211 |
+
}
|
212 |
+
$tagRes = $this->_saveTags($id, $tags);
|
213 |
+
return $tagRes;
|
214 |
+
}
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Remove a cache record
|
218 |
+
*
|
219 |
+
* @param string $id Cache id
|
220 |
+
* @return boolean True if no problem
|
221 |
+
*/
|
222 |
+
public function remove($id)
|
223 |
+
{
|
224 |
+
if ($this->_options['store_data']) {
|
225 |
+
$adapter = $this->_getAdapter();
|
226 |
+
$result = $adapter->delete($this->_getDataTable(), array('id=?'=>$id));
|
227 |
+
return $result;
|
228 |
+
} else {
|
229 |
+
return false;
|
230 |
+
}
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Clean some cache records
|
235 |
+
*
|
236 |
+
* Available modes are :
|
237 |
+
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
238 |
+
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
239 |
+
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
240 |
+
* ($tags can be an array of strings or a single string)
|
241 |
+
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
242 |
+
* ($tags can be an array of strings or a single string)
|
243 |
+
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
244 |
+
* ($tags can be an array of strings or a single string)
|
245 |
+
*
|
246 |
+
* @param string $mode Clean mode
|
247 |
+
* @param array $tags Array of tags
|
248 |
+
* @return boolean true if no problem
|
249 |
+
*/
|
250 |
+
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
251 |
+
{
|
252 |
+
$adapter = $this->_getAdapter();
|
253 |
+
switch($mode) {
|
254 |
+
case Zend_Cache::CLEANING_MODE_ALL:
|
255 |
+
if ($this->_options['store_data']) {
|
256 |
+
$result = $adapter->query('TRUNCATE TABLE '.$this->_getDataTable());
|
257 |
+
} else {
|
258 |
+
$result = true;
|
259 |
+
}
|
260 |
+
$result = $result && $adapter->query('TRUNCATE TABLE '.$this->_getTagsTable());
|
261 |
+
break;
|
262 |
+
case Zend_Cache::CLEANING_MODE_OLD:
|
263 |
+
if ($this->_options['store_data']) {
|
264 |
+
$result = $adapter->delete($this->_getDataTable(), array(
|
265 |
+
'expire_time> ?' => 0,
|
266 |
+
'expire_time<= ?' => time()
|
267 |
+
));
|
268 |
+
} else {
|
269 |
+
$result = true;
|
270 |
+
}
|
271 |
+
break;
|
272 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
273 |
+
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
274 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
275 |
+
$result = $this->_cleanByTags($mode, $tags);
|
276 |
+
break;
|
277 |
+
default:
|
278 |
+
Zend_Cache::throwException('Invalid mode for clean() method');
|
279 |
+
break;
|
280 |
+
}
|
281 |
+
|
282 |
+
return $result;
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Return an array of stored cache ids
|
287 |
+
*
|
288 |
+
* @return array array of stored cache ids (string)
|
289 |
+
*/
|
290 |
+
public function getIds()
|
291 |
+
{
|
292 |
+
if ($this->_options['store_data']) {
|
293 |
+
$select = $this->_getAdapter()->select()
|
294 |
+
->from($this->_getDataTable(), 'id');
|
295 |
+
return $this->_getAdapter()->fetchCol($select);
|
296 |
+
} else {
|
297 |
+
return array();
|
298 |
+
}
|
299 |
+
}
|
300 |
+
|
301 |
+
/**
|
302 |
+
* Return an array of stored tags
|
303 |
+
*
|
304 |
+
* @return array array of stored tags (string)
|
305 |
+
*/
|
306 |
+
public function getTags()
|
307 |
+
{
|
308 |
+
$select = $this->_getAdapter()->select()
|
309 |
+
->from($this->_getTagsTable(), 'tag')
|
310 |
+
->distinct(true);
|
311 |
+
return $this->_getAdapter()->fetchCol($select);
|
312 |
+
}
|
313 |
+
|
314 |
+
/**
|
315 |
+
* Return an array of stored cache ids which match given tags
|
316 |
+
*
|
317 |
+
* In case of multiple tags, a logical AND is made between tags
|
318 |
+
*
|
319 |
+
* @param array $tags array of tags
|
320 |
+
* @return array array of matching cache ids (string)
|
321 |
+
*/
|
322 |
+
public function getIdsMatchingTags($tags = array())
|
323 |
+
{
|
324 |
+
$select = $this->_getAdapter()->select()
|
325 |
+
->from($this->_getTagsTable(), 'cache_id')
|
326 |
+
->distinct(true)
|
327 |
+
->where('tag IN(?)', $tags)
|
328 |
+
->group('cache_id')
|
329 |
+
->having('COUNT(cache_id)='.count($tags));
|
330 |
+
return $this->_getAdapter()->fetchCol($select);
|
331 |
+
}
|
332 |
+
|
333 |
+
/**
|
334 |
+
* Return an array of stored cache ids which don't match given tags
|
335 |
+
*
|
336 |
+
* In case of multiple tags, a logical OR is made between tags
|
337 |
+
*
|
338 |
+
* @param array $tags array of tags
|
339 |
+
* @return array array of not matching cache ids (string)
|
340 |
+
*/
|
341 |
+
public function getIdsNotMatchingTags($tags = array())
|
342 |
+
{
|
343 |
+
return array_diff($this->getIds(), $this->getIdsMatchingAnyTags($tags));
|
344 |
+
}
|
345 |
+
|
346 |
+
/**
|
347 |
+
* Return an array of stored cache ids which match any given tags
|
348 |
+
*
|
349 |
+
* In case of multiple tags, a logical AND is made between tags
|
350 |
+
*
|
351 |
+
* @param array $tags array of tags
|
352 |
+
* @return array array of any matching cache ids (string)
|
353 |
+
*/
|
354 |
+
public function getIdsMatchingAnyTags($tags = array())
|
355 |
+
{
|
356 |
+
$select = $this->_getAdapter()->select()
|
357 |
+
->from($this->_getTagsTable(), 'cache_id')
|
358 |
+
->distinct(true)
|
359 |
+
->where('tag IN(?)', $tags);
|
360 |
+
return $this->_getAdapter()->fetchCol($select);
|
361 |
+
}
|
362 |
+
|
363 |
+
/**
|
364 |
+
* Return the filling percentage of the backend storage
|
365 |
+
*
|
366 |
+
* @return int integer between 0 and 100
|
367 |
+
*/
|
368 |
+
public function getFillingPercentage()
|
369 |
+
{
|
370 |
+
return 1;
|
371 |
+
}
|
372 |
+
|
373 |
+
/**
|
374 |
+
* Return an array of metadatas for the given cache id
|
375 |
+
*
|
376 |
+
* The array must include these keys :
|
377 |
+
* - expire : the expire timestamp
|
378 |
+
* - tags : a string array of tags
|
379 |
+
* - mtime : timestamp of last modification time
|
380 |
+
*
|
381 |
+
* @param string $id cache id
|
382 |
+
* @return array array of metadatas (false if the cache id is not found)
|
383 |
+
*/
|
384 |
+
public function getMetadatas($id)
|
385 |
+
{
|
386 |
+
$select = $this->_getAdapter()->select()
|
387 |
+
->from($this->_getTagsTable(), 'tag')
|
388 |
+
->where('cache_id=?', $id);
|
389 |
+
$tags = $this->_getAdapter()->fetchCol($select);
|
390 |
+
|
391 |
+
$select = $this->_getAdapter()->select()
|
392 |
+
->from($this->_getDataTable())
|
393 |
+
->where('id=?', $id);
|
394 |
+
$data = $this->_getAdapter()->fetchRow($select);
|
395 |
+
$res = false;
|
396 |
+
if ($data) {
|
397 |
+
$res = array (
|
398 |
+
'expire'=> $data['expire_time'],
|
399 |
+
'mtime' => $data['update_time'],
|
400 |
+
'tags' => $tags
|
401 |
+
);
|
402 |
+
}
|
403 |
+
return $res;
|
404 |
+
}
|
405 |
+
|
406 |
+
/**
|
407 |
+
* Give (if possible) an extra lifetime to the given cache id
|
408 |
+
*
|
409 |
+
* @param string $id cache id
|
410 |
+
* @param int $extraLifetime
|
411 |
+
* @return boolean true if ok
|
412 |
+
*/
|
413 |
+
public function touch($id, $extraLifetime)
|
414 |
+
{
|
415 |
+
if ($this->_options['store_data']) {
|
416 |
+
return $this->_getAdapter()->update(
|
417 |
+
$this->_getDataTable(),
|
418 |
+
array('expire_time'=>new Zend_Db_Expr('expire_time+'.$extraLifetime)),
|
419 |
+
array('id=?'=>$id, 'expire_time = 0 OR expire_time>'=>time())
|
420 |
+
);
|
421 |
+
} else {
|
422 |
+
return true;
|
423 |
+
}
|
424 |
+
}
|
425 |
+
|
426 |
+
/**
|
427 |
+
* Return an associative array of capabilities (booleans) of the backend
|
428 |
+
*
|
429 |
+
* The array must include these keys :
|
430 |
+
* - automatic_cleaning (is automating cleaning necessary)
|
431 |
+
* - tags (are tags supported)
|
432 |
+
* - expired_read (is it possible to read expired cache records
|
433 |
+
* (for doNotTestCacheValidity option for example))
|
434 |
+
* - priority does the backend deal with priority when saving
|
435 |
+
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
436 |
+
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
437 |
+
*
|
438 |
+
* @return array associative of with capabilities
|
439 |
+
*/
|
440 |
+
public function getCapabilities()
|
441 |
+
{
|
442 |
+
return array(
|
443 |
+
'automatic_cleaning' => true,
|
444 |
+
'tags' => true,
|
445 |
+
'expired_read' => true,
|
446 |
+
'priority' => false,
|
447 |
+
'infinite_lifetime' => true,
|
448 |
+
'get_list' => true
|
449 |
+
);
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Save tags related to specific id
|
454 |
+
*
|
455 |
+
* @param string $id
|
456 |
+
* @param array $tags
|
457 |
+
* @return bool
|
458 |
+
*/
|
459 |
+
protected function _saveTags($id, $tags)
|
460 |
+
{
|
461 |
+
if (!is_array($tags)) {
|
462 |
+
$tags = array($tags);
|
463 |
+
}
|
464 |
+
if (empty($tags)) {
|
465 |
+
return true;
|
466 |
+
}
|
467 |
+
|
468 |
+
$adapter = $this->_getAdapter();
|
469 |
+
$tagsTable = $this->_getTagsTable();
|
470 |
+
$select = $adapter->select()
|
471 |
+
->from($tagsTable, 'tag')
|
472 |
+
->where('cache_id=?', $id)
|
473 |
+
->where('tag IN(?)', $tags);
|
474 |
+
|
475 |
+
$existingTags = $adapter->fetchCol($select);
|
476 |
+
$insertTags = array_diff($tags, $existingTags);
|
477 |
+
if (!empty($insertTags)) {
|
478 |
+
$query = 'INSERT IGNORE INTO ' . $tagsTable . ' (tag, cache_id) VALUES ';
|
479 |
+
$bind = array();
|
480 |
+
$lines = array();
|
481 |
+
foreach ($insertTags as $tag) {
|
482 |
+
$lines[] = '(?, ?)';
|
483 |
+
$bind[] = $tag;
|
484 |
+
$bind[] = $id;
|
485 |
+
}
|
486 |
+
$query.= implode(',', $lines);
|
487 |
+
$adapter->query($query, $bind);
|
488 |
+
}
|
489 |
+
$result = true;
|
490 |
+
return $result;
|
491 |
+
}
|
492 |
+
|
493 |
+
/**
|
494 |
+
* Remove cache data by tags with specified mode
|
495 |
+
*
|
496 |
+
* @param string $mode
|
497 |
+
* @param array $tags
|
498 |
+
* @return bool
|
499 |
+
*/
|
500 |
+
protected function _cleanByTags($mode, $tags)
|
501 |
+
{
|
502 |
+
if ($this->_options['store_data']) {
|
503 |
+
$adapter = $this->_getAdapter();
|
504 |
+
$select = $adapter->select()
|
505 |
+
->from($this->_getTagsTable(), 'cache_id');
|
506 |
+
switch ($mode) {
|
507 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
508 |
+
$select->where('tag IN (?)', $tags)
|
509 |
+
->group('cache_id')
|
510 |
+
->having('COUNT(cache_id)='.count($tags));
|
511 |
+
break;
|
512 |
+
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
513 |
+
$select->where('tag NOT IN (?)', $tags);
|
514 |
+
break;
|
515 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
516 |
+
$select->where('tag IN (?)', $tags);
|
517 |
+
break;
|
518 |
+
default:
|
519 |
+
Zend_Cache::throwException('Invalid mode for _cleanByTags() method');
|
520 |
+
break;
|
521 |
+
}
|
522 |
+
|
523 |
+
$result = true;
|
524 |
+
$ids = array();
|
525 |
+
$counter = 0;
|
526 |
+
$stmt = $adapter->query($select);
|
527 |
+
while ($row = $stmt->fetch()) {
|
528 |
+
$ids[] = $row['cache_id'];
|
529 |
+
$counter++;
|
530 |
+
if ($counter>100) {
|
531 |
+
$result = $result && $adapter->delete($this->_getDataTable(), array('id IN (?)' => $ids));
|
532 |
+
$ids = array();
|
533 |
+
$counter = 0;
|
534 |
+
}
|
535 |
+
}
|
536 |
+
if (!empty($ids)) {
|
537 |
+
$result = $result && $adapter->delete($this->_getDataTable(), array('id IN (?)' => $ids));
|
538 |
+
}
|
539 |
+
return $result;
|
540 |
+
} else {
|
541 |
+
return true;
|
542 |
+
}
|
543 |
+
}
|
544 |
+
}
|
lib/Varien/Cache/Backend/Eaccelerator.php
ADDED
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Varien
|
22 |
+
* @package Varien_Cache
|
23 |
+
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Varien_Cache_Backend_Eaccelerator extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
28 |
+
{
|
29 |
+
/**
|
30 |
+
* Log message
|
31 |
+
*/
|
32 |
+
const TAGS_UNSUPPORTED_BY_CLEAN_OF_EACCELERATOR_BACKEND = 'Varien_Cache_Backend_Eaccelerator::clean() : tags are unsupported by the Eaccelerator backend';
|
33 |
+
const TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND = 'Varien_Cache_Backend_Eaccelerator::save() : tags are unsupported by the Eaccelerator backend';
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Constructor
|
37 |
+
*
|
38 |
+
* @param array $options associative array of options
|
39 |
+
* @throws Zend_Cache_Exception
|
40 |
+
* @return void
|
41 |
+
*/
|
42 |
+
public function __construct(array $options = array())
|
43 |
+
{
|
44 |
+
if (!extension_loaded('eaccelerator')) {
|
45 |
+
Zend_Cache::throwException('The eaccelerator extension must be loaded for using this backend !');
|
46 |
+
}
|
47 |
+
parent::__construct($options);
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Test if a cache is available for the given id and (if yes) return it (false else)
|
52 |
+
*
|
53 |
+
* WARNING $doNotTestCacheValidity=true is unsupported by the Eaccelerator backend
|
54 |
+
*
|
55 |
+
* @param string $id cache id
|
56 |
+
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
57 |
+
* @return string cached datas (or false)
|
58 |
+
*/
|
59 |
+
public function load($id, $doNotTestCacheValidity = false)
|
60 |
+
{
|
61 |
+
$tmp = eaccelerator_get($id);
|
62 |
+
if (is_array($tmp)) {
|
63 |
+
return $tmp[0];
|
64 |
+
}
|
65 |
+
return false;
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Test if a cache is available or not (for the given id)
|
70 |
+
*
|
71 |
+
* @param string $id cache id
|
72 |
+
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
73 |
+
*/
|
74 |
+
public function test($id)
|
75 |
+
{
|
76 |
+
$tmp = eaccelerator_get($id);
|
77 |
+
if (is_array($tmp)) {
|
78 |
+
return $tmp[1];
|
79 |
+
}
|
80 |
+
return false;
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Save some string datas into a cache record
|
85 |
+
*
|
86 |
+
* Note : $data is always "string" (serialization is done by the
|
87 |
+
* core not by the backend)
|
88 |
+
*
|
89 |
+
* @param string $data datas to cache
|
90 |
+
* @param string $id cache id
|
91 |
+
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
92 |
+
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
93 |
+
* @return boolean true if no problem
|
94 |
+
*/
|
95 |
+
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
96 |
+
{
|
97 |
+
$lifetime = $this->getLifetime($specificLifetime);
|
98 |
+
$result = eaccelerator_put($id, array($data, time(), $lifetime), $lifetime);
|
99 |
+
if (count($tags) > 0) {
|
100 |
+
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
|
101 |
+
}
|
102 |
+
return $result;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Remove a cache record
|
107 |
+
*
|
108 |
+
* @param string $id cache id
|
109 |
+
* @return boolean true if no problem
|
110 |
+
*/
|
111 |
+
public function remove($id)
|
112 |
+
{
|
113 |
+
return eaccelerator_rm($id);
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Clean some cache records
|
118 |
+
*
|
119 |
+
* Available modes are :
|
120 |
+
* 'all' (default) => remove all cache entries ($tags is not used)
|
121 |
+
* 'old' => unsupported
|
122 |
+
* 'matchingTag' => unsupported
|
123 |
+
* 'notMatchingTag' => unsupported
|
124 |
+
* 'matchingAnyTag' => unsupported
|
125 |
+
*
|
126 |
+
* @param string $mode clean mode
|
127 |
+
* @param array $tags array of tags
|
128 |
+
* @throws Zend_Cache_Exception
|
129 |
+
* @return boolean true if no problem
|
130 |
+
*/
|
131 |
+
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
132 |
+
{
|
133 |
+
switch ($mode) {
|
134 |
+
case Zend_Cache::CLEANING_MODE_ALL:
|
135 |
+
return eaccelerator_clean();
|
136 |
+
break;
|
137 |
+
case Zend_Cache::CLEANING_MODE_OLD:
|
138 |
+
$this->_log("Varien_Cache_Backend_Eaccelerator::clean() : CLEANING_MODE_OLD is unsupported by the Eaccelerator backend");
|
139 |
+
break;
|
140 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
141 |
+
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
142 |
+
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
143 |
+
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_EACCELERATOR_BACKEND);
|
144 |
+
break;
|
145 |
+
default:
|
146 |
+
Zend_Cache::throwException('Invalid mode for clean() method');
|
147 |
+
break;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Return true if the automatic cleaning is available for the backend
|
153 |
+
*
|
154 |
+
* DEPRECATED : use getCapabilities() instead
|
155 |
+
*
|
156 |
+
* @deprecated
|
157 |
+
* @return boolean
|
158 |
+
*/
|
159 |
+
public function isAutomaticCleaningAvailable()
|
160 |
+
{
|
161 |
+
return false;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Return the filling percentage of the backend storage
|
166 |
+
*
|
167 |
+
* @throws Zend_Cache_Exception
|
168 |
+
* @return int integer between 0 and 100
|
169 |
+
*/
|
170 |
+
public function getFillingPercentage()
|
171 |
+
{
|
172 |
+
$mem = eaccelerator_info();
|
173 |
+
$memSize = $mem['memorySize'];
|
174 |
+
$memAvailable= $mem['memoryAvailable'];
|
175 |
+
$memUsed = $memSize - $memAvailable;
|
176 |
+
if ($memSize == 0) {
|
177 |
+
Zend_Cache::throwException('can\'t get eaccelerator memory size');
|
178 |
+
}
|
179 |
+
if ($memUsed > $memSize) {
|
180 |
+
return 100;
|
181 |
+
}
|
182 |
+
return ((int) (100. * ($memUsed / $memSize)));
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Return an array of stored tags
|
187 |
+
*
|
188 |
+
* @return array array of stored tags (string)
|
189 |
+
*/
|
190 |
+
public function getTags()
|
191 |
+
{
|
192 |
+
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
|
193 |
+
return array();
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Return an array of stored cache ids which match given tags
|
198 |
+
*
|
199 |
+
* In case of multiple tags, a logical AND is made between tags
|
200 |
+
*
|
201 |
+
* @param array $tags array of tags
|
202 |
+
* @return array array of matching cache ids (string)
|
203 |
+
*/
|
204 |
+
public function getIdsMatchingTags($tags = array())
|
205 |
+
{
|
206 |
+
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
|
207 |
+
return array();
|
208 |
+
}
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Return an array of stored cache ids which don't match given tags
|
212 |
+
*
|
213 |
+
* In case of multiple tags, a logical OR is made between tags
|
214 |
+
*
|
215 |
+
* @param array $tags array of tags
|
216 |
+
* @return array array of not matching cache ids (string)
|
217 |
+
*/
|
218 |
+
public function getIdsNotMatchingTags($tags = array())
|
219 |
+
{
|
220 |
+
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
|
221 |
+
return array();
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Return an array of stored cache ids which match any given tags
|
226 |
+
*
|
227 |
+
* In case of multiple tags, a logical AND is made between tags
|
228 |
+
*
|
229 |
+
* @param array $tags array of tags
|
230 |
+
* @return array array of any matching cache ids (string)
|
231 |
+
*/
|
232 |
+
public function getIdsMatchingAnyTags($tags = array())
|
233 |
+
{
|
234 |
+
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_EACCELERATOR_BACKEND);
|
235 |
+
return array();
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Return an array of stored cache ids
|
240 |
+
*
|
241 |
+
* @return array array of stored cache ids (string)
|
242 |
+
*/
|
243 |
+
public function getIds()
|
244 |
+
{
|
245 |
+
$res = array();
|
246 |
+
$array = eaccelerator_list_keys();
|
247 |
+
foreach ($array as $key => $info) {
|
248 |
+
$res[] = $key;
|
249 |
+
}
|
250 |
+
return $res;
|
251 |
+
}
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Return an array of metadatas for the given cache id
|
255 |
+
*
|
256 |
+
* The array must include these keys :
|
257 |
+
* - expire : the expire timestamp
|
258 |
+
* - tags : a string array of tags
|
259 |
+
* - mtime : timestamp of last modification time
|
260 |
+
*
|
261 |
+
* @param string $id cache id
|
262 |
+
* @return array array of metadatas (false if the cache id is not found)
|
263 |
+
*/
|
264 |
+
public function getMetadatas($id)
|
265 |
+
{
|
266 |
+
$tmp = eaccelerator_get($id);
|
267 |
+
if (is_array($tmp)) {
|
268 |
+
$data = $tmp[0];
|
269 |
+
$mtime = $tmp[1];
|
270 |
+
if (!isset($tmp[2])) {
|
271 |
+
// because this record is only with 1.7 release
|
272 |
+
// if old cache records are still there...
|
273 |
+
return false;
|
274 |
+
}
|
275 |
+
$lifetime = $tmp[2];
|
276 |
+
return array(
|
277 |
+
'expire' => $mtime + $lifetime,
|
278 |
+
'tags' => array(),
|
279 |
+
'mtime' => $mtime
|
280 |
+
);
|
281 |
+
}
|
282 |
+
return false;
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Give (if possible) an extra lifetime to the given cache id
|
287 |
+
*
|
288 |
+
* @param string $id cache id
|
289 |
+
* @param int $extraLifetime
|
290 |
+
* @return boolean true if ok
|
291 |
+
*/
|
292 |
+
public function touch($id, $extraLifetime)
|
293 |
+
{
|
294 |
+
$tmp = eaccelerator_get($id);
|
295 |
+
if (is_array($tmp)) {
|
296 |
+
$data = $tmp[0];
|
297 |
+
$mtime = $tmp[1];
|
298 |
+
if (!isset($tmp[2])) {
|
299 |
+
// because this record is only with 1.7 release
|
300 |
+
// if old cache records are still there...
|
301 |
+
return false;
|
302 |
+
}
|
303 |
+
$lifetime = $tmp[2];
|
304 |
+
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
305 |
+
if ($newLifetime <=0) {
|
306 |
+
return false;
|
307 |
+
}
|
308 |
+
eaccelerator_put($id, array($data, time(), $newLifetime), $newLifetime);
|
309 |
+
return true;
|
310 |
+
}
|
311 |
+
return false;
|
312 |
+
}
|
313 |
+
|
314 |
+
/**
|
315 |
+
* Return an associative array of capabilities (booleans) of the backend
|
316 |
+
*
|
317 |
+
* The array must include these keys :
|
318 |
+
* - automatic_cleaning (is automating cleaning necessary)
|
319 |
+
* - tags (are tags supported)
|
320 |
+
* - expired_read (is it possible to read expired cache records
|
321 |
+
* (for doNotTestCacheValidity option for example))
|
322 |
+
* - priority does the backend deal with priority when saving
|
323 |
+
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
324 |
+
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
325 |
+
*
|
326 |
+
* @return array associative of with capabilities
|
327 |
+
*/
|
328 |
+
public function getCapabilities()
|
329 |
+
{
|
330 |
+
return array(
|
331 |
+
'automatic_cleaning' => false,
|
332 |
+
'tags' => false,
|
333 |
+
'expired_read' => false,
|
334 |
+
'priority' => false,
|
335 |
+
'infinite_lifetime' => false,
|
336 |
+
'get_list' => true
|
337 |
+
);
|
338 |
+
}
|
339 |
+
|
340 |
+
}
|
lib/Varien/Cache/Core.php
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Varien
|
22 |
+
* @package Varien_Cache
|
23 |
+
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
class Varien_Cache_Core extends Zend_Cache_Core
|
28 |
+
{
|
29 |
+
/**
|
30 |
+
* Make and return a cache id
|
31 |
+
*
|
32 |
+
* Checks 'cache_id_prefix' and returns new id with prefix or simply the id if null
|
33 |
+
*
|
34 |
+
* @param string $id Cache id
|
35 |
+
* @return string Cache id (with or without prefix)
|
36 |
+
*/
|
37 |
+
protected function _id($id)
|
38 |
+
{
|
39 |
+
if ($id !== null) {
|
40 |
+
$id = preg_replace('/([^a-zA-Z0-9_]{1,1})/', '_', $id);
|
41 |
+
if (isset($this->_options['cache_id_prefix'])) {
|
42 |
+
$id = $this->_options['cache_id_prefix'] . $id;
|
43 |
+
}
|
44 |
+
}
|
45 |
+
return $id;
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Prepare tags
|
50 |
+
*
|
51 |
+
* @param array $tags
|
52 |
+
* @return array
|
53 |
+
*/
|
54 |
+
protected function _tags($tags)
|
55 |
+
{
|
56 |
+
foreach ($tags as $key=>$tag) {
|
57 |
+
$tags[$key] = $this->_id($tag);
|
58 |
+
}
|
59 |
+
return $tags;
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Save some data in a cache
|
64 |
+
*
|
65 |
+
* @param mixed $data Data to put in cache (can be another type than string if automatic_serialization is on)
|
66 |
+
* @param string $id Cache id (if not set, the last cache id will be used)
|
67 |
+
* @param array $tags Cache tags
|
68 |
+
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
69 |
+
* @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends
|
70 |
+
* @throws Zend_Cache_Exception
|
71 |
+
* @return boolean True if no problem
|
72 |
+
*/
|
73 |
+
public function save($data, $id = null, $tags = array(), $specificLifetime = false, $priority = 8)
|
74 |
+
{
|
75 |
+
$tags = $this->_tags($tags);
|
76 |
+
return parent::save($data, $id, $tags, $specificLifetime, $priority);
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Clean cache entries
|
81 |
+
*
|
82 |
+
* Available modes are :
|
83 |
+
* 'all' (default) => remove all cache entries ($tags is not used)
|
84 |
+
* 'old' => remove too old cache entries ($tags is not used)
|
85 |
+
* 'matchingTag' => remove cache entries matching all given tags
|
86 |
+
* ($tags can be an array of strings or a single string)
|
87 |
+
* 'notMatchingTag' => remove cache entries not matching one of the given tags
|
88 |
+
* ($tags can be an array of strings or a single string)
|
89 |
+
* 'matchingAnyTag' => remove cache entries matching any given tags
|
90 |
+
* ($tags can be an array of strings or a single string)
|
91 |
+
*
|
92 |
+
* @param string $mode
|
93 |
+
* @param array|string $tags
|
94 |
+
* @throws Zend_Cache_Exception
|
95 |
+
* @return boolean True if ok
|
96 |
+
*/
|
97 |
+
public function clean($mode = 'all', $tags = array())
|
98 |
+
{
|
99 |
+
$tags = $this->_tags($tags);
|
100 |
+
return parent::clean($mode, $tags);
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Return an array of stored cache ids which match given tags
|
105 |
+
*
|
106 |
+
* In case of multiple tags, a logical AND is made between tags
|
107 |
+
*
|
108 |
+
* @param array $tags array of tags
|
109 |
+
* @return array array of matching cache ids (string)
|
110 |
+
*/
|
111 |
+
public function getIdsMatchingTags($tags = array())
|
112 |
+
{
|
113 |
+
$tags = $this->_tags($tags);
|
114 |
+
return parent::getIdsMatchingTags($tags);
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Return an array of stored cache ids which don't match given tags
|
119 |
+
*
|
120 |
+
* In case of multiple tags, a logical OR is made between tags
|
121 |
+
*
|
122 |
+
* @param array $tags array of tags
|
123 |
+
* @return array array of not matching cache ids (string)
|
124 |
+
*/
|
125 |
+
public function getIdsNotMatchingTags($tags = array())
|
126 |
+
{
|
127 |
+
$tags = $this->_tags($tags);
|
128 |
+
return parent::getIdsNotMatchingTags($tags);
|
129 |
+
}
|
130 |
+
}
|
lib/Varien/Convert.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Varien
|
22 |
+
* @package Varien_Convert
|
23 |
+
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Convert factory
|
30 |
+
*
|
31 |
+
* @category Varien
|
32 |
+
* @package Varien_Convert
|
33 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
34 |
+
*/
|
35 |
+
class Varien_Convert
|
36 |
+
{
|
37 |
+
static public function convert($class, $method, $data, array $vars=array())
|
38 |
+
{
|
39 |
+
if (is_string($class)) {
|
40 |
+
$class = new $class();
|
41 |
+
}
|
42 |
+
$action = new Varien_Convert_Action();
|
43 |
+
$action->setParam('method', $method)->setParam('class', $class);
|
44 |
+
|
45 |
+
$container = $action->getContainer();
|
46 |
+
$container->setData($data)->setVars($vars);
|
47 |
+
|
48 |
+
$action->run();
|
49 |
+
return $action->getData();
|
50 |
+
}
|
51 |
+
}
|
lib/Varien/Convert/Action.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|