maruto 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/fixtures/magento_1.0/app/Mage.php +585 -0
- data/fixtures/magento_1.13.0.0/app/Mage.php +42 -0
- data/fixtures/magento_1.3.3.0/app/Mage.php +738 -0
- data/fixtures/magento_1.4.0.0/app/Mage.php +859 -0
- data/fixtures/magento_1.7.0.2/app/Mage.php +989 -0
- data/lib/maruto/magento_instance.rb +4 -0
- data/lib/maruto/magento_version.rb +57 -0
- data/lib/maruto/module_configuration.rb +11 -2
- data/lib/maruto/runner.rb +12 -3
- data/lib/maruto/version.rb +1 -1
- data/maruto.gemspec +1 -1
- data/spec/magento_version_spec.rb +57 -0
- data/spec/module_events_spec.rb +45 -35
- metadata +14 -6
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Main Mage hub class
|
|
5
|
+
*
|
|
6
|
+
* @author Magento Core Team <core@magentocommerce.com>
|
|
7
|
+
*/
|
|
8
|
+
final class Mage
|
|
9
|
+
{
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Gets the current Magento version string
|
|
13
|
+
* @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
|
|
14
|
+
*
|
|
15
|
+
* @return string
|
|
16
|
+
*/
|
|
17
|
+
public static function getVersion()
|
|
18
|
+
{
|
|
19
|
+
$i = self::getVersionInfo();
|
|
20
|
+
return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "")
|
|
21
|
+
. "-{$i['stability']}{$i['number']}", '.-');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Gets the detailed Magento version information
|
|
26
|
+
* @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
|
|
27
|
+
*
|
|
28
|
+
* @return array
|
|
29
|
+
*/
|
|
30
|
+
public static function getVersionInfo()
|
|
31
|
+
{
|
|
32
|
+
return array(
|
|
33
|
+
'major' => '1',
|
|
34
|
+
'minor' => '13',
|
|
35
|
+
'revision' => '0',
|
|
36
|
+
'patch' => '0',
|
|
37
|
+
'stability' => '',
|
|
38
|
+
'number' => '',
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
@@ -0,0 +1,738 @@
|
|
|
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 Mage
|
|
22
|
+
* @package Mage_Core
|
|
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
|
+
define('DS', DIRECTORY_SEPARATOR);
|
|
28
|
+
define('PS', PATH_SEPARATOR);
|
|
29
|
+
define('BP', dirname(dirname(__FILE__)));
|
|
30
|
+
|
|
31
|
+
Mage::register('original_include_path', get_include_path());
|
|
32
|
+
|
|
33
|
+
if (defined('COMPILER_INCLUDE_PATH')) {
|
|
34
|
+
$app_path = COMPILER_INCLUDE_PATH;
|
|
35
|
+
set_include_path($app_path . PS . Mage::registry('original_include_path'));
|
|
36
|
+
include_once "Mage_Core_functions.php";
|
|
37
|
+
include_once "Varien_Autoload.php";
|
|
38
|
+
} else {
|
|
39
|
+
/**
|
|
40
|
+
* Set include path
|
|
41
|
+
*/
|
|
42
|
+
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
|
|
43
|
+
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
|
|
44
|
+
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
|
|
45
|
+
$paths[] = BP . DS . 'lib';
|
|
46
|
+
|
|
47
|
+
$app_path = implode(PS, $paths);
|
|
48
|
+
set_include_path($app_path . PS . Mage::registry('original_include_path'));
|
|
49
|
+
include_once "Mage/Core/functions.php";
|
|
50
|
+
include_once "Varien/Autoload.php";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Varien_Autoload::register();
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Main Mage hub class
|
|
57
|
+
*
|
|
58
|
+
* @author Magento Core Team <core@magentocommerce.com>
|
|
59
|
+
*/
|
|
60
|
+
final class Mage {
|
|
61
|
+
/**
|
|
62
|
+
* Registry collection
|
|
63
|
+
*
|
|
64
|
+
* @var array
|
|
65
|
+
*/
|
|
66
|
+
static private $_registry = array();
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Application model
|
|
70
|
+
*
|
|
71
|
+
* @var Mage_Core_Model_App
|
|
72
|
+
*/
|
|
73
|
+
static private $_app;
|
|
74
|
+
|
|
75
|
+
static private $_useCache = array();
|
|
76
|
+
|
|
77
|
+
static private $_objects;
|
|
78
|
+
|
|
79
|
+
static private $_isDownloader = false;
|
|
80
|
+
|
|
81
|
+
static private $_isDeveloperMode = false;
|
|
82
|
+
|
|
83
|
+
public static $headersSentThrowsException = true;
|
|
84
|
+
|
|
85
|
+
public static function getVersion()
|
|
86
|
+
{
|
|
87
|
+
return '1.3.3.0';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Set all my static data to defaults
|
|
92
|
+
*
|
|
93
|
+
*/
|
|
94
|
+
public static function reset()
|
|
95
|
+
{
|
|
96
|
+
self::$_registry = array();
|
|
97
|
+
self::$_app = null;
|
|
98
|
+
self::$_useCache = array();
|
|
99
|
+
self::$_objects = null;
|
|
100
|
+
self::$_isDownloader = false;
|
|
101
|
+
self::$_isDeveloperMode = false;
|
|
102
|
+
// do not reset $headersSentThrowsException
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Register a new variable
|
|
107
|
+
*
|
|
108
|
+
* @param string $key
|
|
109
|
+
* @param mixed $value
|
|
110
|
+
* @param bool $graceful
|
|
111
|
+
*/
|
|
112
|
+
public static function register($key, $value, $graceful = false)
|
|
113
|
+
{
|
|
114
|
+
if(isset(self::$_registry[$key])) {
|
|
115
|
+
if ($graceful) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
Mage::throwException('Mage registry key "'.$key.'" already exists');
|
|
119
|
+
}
|
|
120
|
+
self::$_registry[$key] = $value;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public static function unregister($key)
|
|
124
|
+
{
|
|
125
|
+
if (isset(self::$_registry[$key])) {
|
|
126
|
+
if (is_object(self::$_registry[$key]) && (method_exists(self::$_registry[$key],'__destruct'))) {
|
|
127
|
+
self::$_registry[$key]->__destruct();
|
|
128
|
+
}
|
|
129
|
+
unset(self::$_registry[$key]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Retrieve a value from registry by a key
|
|
135
|
+
*
|
|
136
|
+
* @param string $key
|
|
137
|
+
* @return mixed
|
|
138
|
+
*/
|
|
139
|
+
public static function registry($key)
|
|
140
|
+
{
|
|
141
|
+
if (isset(self::$_registry[$key])) {
|
|
142
|
+
return self::$_registry[$key];
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Set application root absolute path
|
|
149
|
+
*
|
|
150
|
+
* @param string $appRoot
|
|
151
|
+
*/
|
|
152
|
+
public static function setRoot($appRoot='')
|
|
153
|
+
{
|
|
154
|
+
if (self::registry('appRoot')) {
|
|
155
|
+
return ;
|
|
156
|
+
}
|
|
157
|
+
if (''===$appRoot) {
|
|
158
|
+
// automagically find application root by dirname of Mage.php
|
|
159
|
+
$appRoot = dirname(__FILE__);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
$appRoot = realpath($appRoot);
|
|
163
|
+
|
|
164
|
+
if (is_dir($appRoot) and is_readable($appRoot)) {
|
|
165
|
+
Mage::register('appRoot', $appRoot);
|
|
166
|
+
} else {
|
|
167
|
+
Mage::throwException($appRoot.' is not a directory or not readable by this user');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Get application root absolute path
|
|
173
|
+
*
|
|
174
|
+
* @return string
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
public static function getRoot()
|
|
178
|
+
{
|
|
179
|
+
return Mage::registry('appRoot');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Varien Objects Cache
|
|
184
|
+
*
|
|
185
|
+
* @param string $key optional, if specified will load this key
|
|
186
|
+
* @return Varien_Object_Cache
|
|
187
|
+
*/
|
|
188
|
+
public static function objects($key=null)
|
|
189
|
+
{
|
|
190
|
+
if (!self::$_objects) {
|
|
191
|
+
self::$_objects = new Varien_Object_Cache;
|
|
192
|
+
}
|
|
193
|
+
if (is_null($key)) {
|
|
194
|
+
return self::$_objects;
|
|
195
|
+
} else {
|
|
196
|
+
return self::$_objects->load($key);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Retrieve application root absolute path
|
|
202
|
+
*
|
|
203
|
+
* @return string
|
|
204
|
+
*/
|
|
205
|
+
public static function getBaseDir($type='base')
|
|
206
|
+
{
|
|
207
|
+
return Mage::getConfig()->getOptions()->getDir($type);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
public static function getModuleDir($type, $moduleName)
|
|
211
|
+
{
|
|
212
|
+
return Mage::getConfig()->getModuleDir($type, $moduleName);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
public static function getStoreConfig($path, $id=null)
|
|
216
|
+
{
|
|
217
|
+
return self::app()->getStore($id)->getConfig($path);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public static function getStoreConfigFlag($path, $id=null)
|
|
221
|
+
{
|
|
222
|
+
$flag = strtolower(Mage::getStoreConfig($path, $id));
|
|
223
|
+
if (!empty($flag) && 'false'!==$flag && '0'!==$flag) {
|
|
224
|
+
return true;
|
|
225
|
+
} else {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Get base URL path by type
|
|
232
|
+
*
|
|
233
|
+
* @param string $type
|
|
234
|
+
* @return string
|
|
235
|
+
*/
|
|
236
|
+
public static function getBaseUrl($type=Mage_Core_Model_Store::URL_TYPE_LINK, $secure=null)
|
|
237
|
+
{
|
|
238
|
+
return Mage::app()->getStore()->getBaseUrl($type, $secure);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Generate url by route and parameters
|
|
243
|
+
*
|
|
244
|
+
* @param string $route
|
|
245
|
+
* @param array $params
|
|
246
|
+
* @return string
|
|
247
|
+
*/
|
|
248
|
+
public static function getUrl($route='', $params=array())
|
|
249
|
+
{
|
|
250
|
+
return Mage::getModel('core/url')->getUrl($route, $params);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Get design package singleton
|
|
255
|
+
*
|
|
256
|
+
* @return Mage_Core_Model_Design_Package
|
|
257
|
+
*/
|
|
258
|
+
public static function getDesign()
|
|
259
|
+
{
|
|
260
|
+
return Mage::getSingleton('core/design_package');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Get a config object
|
|
265
|
+
*
|
|
266
|
+
* @return Mage_Core_Model_Config
|
|
267
|
+
*/
|
|
268
|
+
public static function getConfig()
|
|
269
|
+
{
|
|
270
|
+
return Mage::registry('config');
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Add observer to even object
|
|
275
|
+
*
|
|
276
|
+
* @param string $eventName
|
|
277
|
+
* @param callback $callback
|
|
278
|
+
* @param array $arguments
|
|
279
|
+
* @param string $observerName
|
|
280
|
+
*/
|
|
281
|
+
public static function addObserver($eventName, $callback, $data=array(), $observerName='', $observerClass='')
|
|
282
|
+
{
|
|
283
|
+
if ($observerClass=='') {
|
|
284
|
+
$observerClass = 'Varien_Event_Observer';
|
|
285
|
+
}
|
|
286
|
+
$observer = new $observerClass();
|
|
287
|
+
$observer->setName($observerName)->addData($data)->setEventName($eventName)->setCallback($callback);
|
|
288
|
+
return Mage::registry('events')->addObserver($observer);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Dispatch event
|
|
293
|
+
*
|
|
294
|
+
* Calls all observer callbacks registered for this event
|
|
295
|
+
* and multiobservers matching event name pattern
|
|
296
|
+
*
|
|
297
|
+
* @param string $name
|
|
298
|
+
* @param array $args
|
|
299
|
+
*/
|
|
300
|
+
public static function dispatchEvent($name, array $data=array())
|
|
301
|
+
{
|
|
302
|
+
Varien_Profiler::start('DISPATCH EVENT:'.$name);
|
|
303
|
+
$result = Mage::app()->dispatchEvent($name, $data);
|
|
304
|
+
#$result = Mage::registry('events')->dispatch($name, $data);
|
|
305
|
+
Varien_Profiler::stop('DISPATCH EVENT:'.$name);
|
|
306
|
+
return $result;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Retrieve model object
|
|
311
|
+
*
|
|
312
|
+
* @link Mage_Core_Model_Config::getModelInstance
|
|
313
|
+
* @param string $modelClass
|
|
314
|
+
* @param array $arguments
|
|
315
|
+
* @return Mage_Core_Model_Abstract
|
|
316
|
+
*/
|
|
317
|
+
public static function getModel($modelClass='', $arguments=array())
|
|
318
|
+
{
|
|
319
|
+
return Mage::getConfig()->getModelInstance($modelClass, $arguments);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Retrieve model object singleton
|
|
324
|
+
*
|
|
325
|
+
* @param string $modelClass
|
|
326
|
+
* @param array $arguments
|
|
327
|
+
* @return Mage_Core_Model_Abstract
|
|
328
|
+
*/
|
|
329
|
+
public static function getSingleton($modelClass='', array $arguments=array())
|
|
330
|
+
{
|
|
331
|
+
$registryKey = '_singleton/'.$modelClass;
|
|
332
|
+
if (!Mage::registry($registryKey)) {
|
|
333
|
+
Mage::register($registryKey, Mage::getModel($modelClass, $arguments));
|
|
334
|
+
}
|
|
335
|
+
return Mage::registry($registryKey);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Retrieve object of resource model
|
|
340
|
+
*
|
|
341
|
+
* @param string $modelClass
|
|
342
|
+
* @param array $arguments
|
|
343
|
+
* @return Object
|
|
344
|
+
*/
|
|
345
|
+
public static function getResourceModel($modelClass, $arguments=array())
|
|
346
|
+
{
|
|
347
|
+
return Mage::getConfig()->getResourceModelInstance($modelClass, $arguments);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Retrieve resource vodel object singleton
|
|
352
|
+
*
|
|
353
|
+
* @param string $modelClass
|
|
354
|
+
* @param array $arguments
|
|
355
|
+
* @return object
|
|
356
|
+
*/
|
|
357
|
+
public static function getResourceSingleton($modelClass='', array $arguments=array())
|
|
358
|
+
{
|
|
359
|
+
$registryKey = '_resource_singleton/'.$modelClass;
|
|
360
|
+
if (!Mage::registry($registryKey)) {
|
|
361
|
+
Mage::register($registryKey, Mage::getResourceModel($modelClass, $arguments));
|
|
362
|
+
}
|
|
363
|
+
return Mage::registry($registryKey);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Deprecated, use Mage::helper()
|
|
368
|
+
*
|
|
369
|
+
* @param string $type
|
|
370
|
+
* @return object
|
|
371
|
+
*/
|
|
372
|
+
public static function getBlockSingleton($type)
|
|
373
|
+
{
|
|
374
|
+
$action = Mage::app()->getFrontController()->getAction();
|
|
375
|
+
return $action ? $action->getLayout()->getBlockSingleton($type) : false;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Retrieve helper object
|
|
380
|
+
*
|
|
381
|
+
* @param helper name $name
|
|
382
|
+
* @return Mage_Core_Helper_Abstract
|
|
383
|
+
*/
|
|
384
|
+
public static function helper($name)
|
|
385
|
+
{
|
|
386
|
+
return Mage::app()->getHelper($name);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Return new exception by module to be thrown
|
|
391
|
+
*
|
|
392
|
+
* @param string $module
|
|
393
|
+
* @param string $message
|
|
394
|
+
* @param integer $code
|
|
395
|
+
*/
|
|
396
|
+
public static function exception($module='Mage_Core', $message='', $code=0)
|
|
397
|
+
{
|
|
398
|
+
$className = $module.'_Exception';
|
|
399
|
+
return new $className($message, $code);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
public static function throwException($message, $messageStorage=null)
|
|
403
|
+
{
|
|
404
|
+
if ($messageStorage && ($storage = Mage::getSingleton($messageStorage))) {
|
|
405
|
+
$storage->addError($message);
|
|
406
|
+
}
|
|
407
|
+
throw new Mage_Core_Exception($message);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Initialize and retrieve application
|
|
412
|
+
*
|
|
413
|
+
* @param string $code
|
|
414
|
+
* @param string $type
|
|
415
|
+
* @param string|array $options
|
|
416
|
+
* @return Mage_Core_Model_App
|
|
417
|
+
*/
|
|
418
|
+
public static function app($code = '', $type = 'store', $options=array())
|
|
419
|
+
{
|
|
420
|
+
if (null === self::$_app) {
|
|
421
|
+
Varien_Profiler::start('mage::app::construct');
|
|
422
|
+
self::$_app = new Mage_Core_Model_App();
|
|
423
|
+
Varien_Profiler::stop('mage::app::construct');
|
|
424
|
+
|
|
425
|
+
Mage::setRoot();
|
|
426
|
+
Mage::register('events', new Varien_Event_Collection());
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
Varien_Profiler::start('mage::app::register_config');
|
|
430
|
+
Mage::register('config', new Mage_Core_Model_Config());
|
|
431
|
+
Varien_Profiler::stop('mage::app::register_config');
|
|
432
|
+
|
|
433
|
+
Varien_Profiler::start('mage::app::init');
|
|
434
|
+
self::$_app->init($code, $type, $options);
|
|
435
|
+
Varien_Profiler::stop('mage::app::init');
|
|
436
|
+
|
|
437
|
+
self::$_app->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
|
|
438
|
+
}
|
|
439
|
+
return self::$_app;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Front end main entry point
|
|
444
|
+
*
|
|
445
|
+
* @param string $code
|
|
446
|
+
* @param string $type
|
|
447
|
+
* @param string|array $options
|
|
448
|
+
*/
|
|
449
|
+
public static function run($code = '', $type = 'store', $options=array())
|
|
450
|
+
{
|
|
451
|
+
try {
|
|
452
|
+
Varien_Profiler::start('mage');
|
|
453
|
+
|
|
454
|
+
Varien_Profiler::start('mage::app');
|
|
455
|
+
self::app($code, $type, $options);
|
|
456
|
+
Varien_Profiler::stop('mage::app');
|
|
457
|
+
|
|
458
|
+
Varien_Profiler::start('mage::dispatch');
|
|
459
|
+
self::app()->getFrontController()->dispatch();
|
|
460
|
+
Varien_Profiler::stop('mage::dispatch');
|
|
461
|
+
|
|
462
|
+
Varien_Profiler::stop('mage');
|
|
463
|
+
}
|
|
464
|
+
catch (Mage_Core_Model_Session_Exception $e) {
|
|
465
|
+
header('Location: ' . Mage::getBaseUrl());
|
|
466
|
+
die();
|
|
467
|
+
}
|
|
468
|
+
catch (Mage_Core_Model_Store_Exception $e) {
|
|
469
|
+
$baseUrl = self::getScriptSystemUrl('404');
|
|
470
|
+
if (!headers_sent()) {
|
|
471
|
+
header('Location: ' . rtrim($baseUrl, '/').'/404/');
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
print '<script type="text/javascript">';
|
|
475
|
+
print "window.location.href = '{$baseUrl}';";
|
|
476
|
+
print '</script>';
|
|
477
|
+
}
|
|
478
|
+
die();
|
|
479
|
+
}
|
|
480
|
+
catch (Exception $e) {
|
|
481
|
+
if (self::isInstalled() || self::$_isDownloader) {
|
|
482
|
+
self::printException($e);
|
|
483
|
+
exit();
|
|
484
|
+
}
|
|
485
|
+
try {
|
|
486
|
+
self::dispatchEvent('mage_run_exception', array('exception' => $e));
|
|
487
|
+
if (!headers_sent()) {
|
|
488
|
+
header('Location:'.self::getUrl('install'));
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
self::printException($e);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
catch (Exception $ne) {
|
|
495
|
+
self::printException($ne, $e->getMessage());
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Retrieve application installation flag
|
|
502
|
+
*
|
|
503
|
+
* @param string|array $options
|
|
504
|
+
* @return bool
|
|
505
|
+
*/
|
|
506
|
+
public static function isInstalled($options = array())
|
|
507
|
+
{
|
|
508
|
+
$isInstalled = self::registry('_is_installed');
|
|
509
|
+
if ($isInstalled === null) {
|
|
510
|
+
self::setRoot();
|
|
511
|
+
|
|
512
|
+
if (is_string($options)) {
|
|
513
|
+
$options = array(
|
|
514
|
+
'etc_dir' => $options
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
$etcDir = 'etc';
|
|
518
|
+
if (!empty($options['etc_dir'])) {
|
|
519
|
+
$etcDir = $options['etc_dir'];
|
|
520
|
+
}
|
|
521
|
+
$localConfigFile = self::getRoot() . DS . $etcDir . DS . 'local.xml';
|
|
522
|
+
|
|
523
|
+
$isInstalled = false;
|
|
524
|
+
|
|
525
|
+
if (is_readable($localConfigFile)) {
|
|
526
|
+
$localConfig = simplexml_load_file($localConfigFile);
|
|
527
|
+
date_default_timezone_set('UTC');
|
|
528
|
+
if (($date = $localConfig->global->install->date) && strtotime($date)) {
|
|
529
|
+
$isInstalled = true;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
self::register('_is_installed', $isInstalled);
|
|
533
|
+
}
|
|
534
|
+
return $isInstalled;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* log facility (??)
|
|
539
|
+
*
|
|
540
|
+
* @param string $message
|
|
541
|
+
* @param integer $level
|
|
542
|
+
* @param string $file
|
|
543
|
+
* @param bool $forceLog
|
|
544
|
+
*/
|
|
545
|
+
public static function log($message, $level=null, $file = '', $forceLog = false)
|
|
546
|
+
{
|
|
547
|
+
if (!self::getConfig()) {
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (!Mage::getStoreConfig('dev/log/active') && !$forceLog) {
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
static $loggers = array();
|
|
555
|
+
|
|
556
|
+
$level = is_null($level) ? Zend_Log::DEBUG : $level;
|
|
557
|
+
if (empty($file)) {
|
|
558
|
+
$file = Mage::getStoreConfig('dev/log/file');
|
|
559
|
+
$file = empty($file) ? 'system.log' : $file;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
try {
|
|
563
|
+
if (!isset($loggers[$file])) {
|
|
564
|
+
$logFile = Mage::getBaseDir('var').DS.'log'.DS.$file;
|
|
565
|
+
$logDir = Mage::getBaseDir('var').DS.'log';
|
|
566
|
+
|
|
567
|
+
if (!is_dir(Mage::getBaseDir('var').DS.'log')) {
|
|
568
|
+
mkdir(Mage::getBaseDir('var').DS.'log', 0777);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (!file_exists($logFile)) {
|
|
572
|
+
file_put_contents($logFile,'');
|
|
573
|
+
chmod($logFile, 0777);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
$format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
|
|
577
|
+
$formatter = new Zend_Log_Formatter_Simple($format);
|
|
578
|
+
$writerModel = (string)self::getConfig()->getNode('global/log/core/writer_model');
|
|
579
|
+
if (!self::$_app || !$writerModel) {
|
|
580
|
+
$writer = new Zend_Log_Writer_Stream($logFile);
|
|
581
|
+
} else {
|
|
582
|
+
$writer = new $writerModel($logFile);
|
|
583
|
+
}
|
|
584
|
+
$writer->setFormatter($formatter);
|
|
585
|
+
$loggers[$file] = new Zend_Log($writer);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (is_array($message) || is_object($message)) {
|
|
589
|
+
$message = print_r($message, true);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
$loggers[$file]->log($message, $level);
|
|
593
|
+
}
|
|
594
|
+
catch (Exception $e){
|
|
595
|
+
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
public static function logException(Exception $e)
|
|
600
|
+
{
|
|
601
|
+
if (!self::getConfig()) {
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
$file = Mage::getStoreConfig('dev/log/exception_file');
|
|
605
|
+
self::log("\n".(string)$e, Zend_Log::ERR, $file);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Set enabled developer mode
|
|
610
|
+
*
|
|
611
|
+
* @param bool $mode
|
|
612
|
+
* @return bool
|
|
613
|
+
*/
|
|
614
|
+
public static function setIsDeveloperMode($mode)
|
|
615
|
+
{
|
|
616
|
+
self::$_isDeveloperMode = (bool)$mode;
|
|
617
|
+
return self::$_isDeveloperMode;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Retrieve enabled developer mode
|
|
622
|
+
*
|
|
623
|
+
* @return bool
|
|
624
|
+
*/
|
|
625
|
+
public static function getIsDeveloperMode()
|
|
626
|
+
{
|
|
627
|
+
return self::$_isDeveloperMode;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Display exception
|
|
632
|
+
*
|
|
633
|
+
* @param Exception $e
|
|
634
|
+
*/
|
|
635
|
+
public static function printException(Exception $e, $extra = '')
|
|
636
|
+
{
|
|
637
|
+
if (self::$_isDeveloperMode) {
|
|
638
|
+
print '<pre>';
|
|
639
|
+
|
|
640
|
+
if (!empty($extra)) {
|
|
641
|
+
print $extra . "\n\n";
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
print $e->getMessage() . "\n\n";
|
|
645
|
+
print $e->getTraceAsString();
|
|
646
|
+
print '</pre>';
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
self::getConfig()->createDirIfNotExists(self::getBaseDir('var') . DS . 'report');
|
|
650
|
+
$reportId = intval(microtime(true) * rand(100, 1000));
|
|
651
|
+
$reportFile = self::getBaseDir('var') . DS . 'report' . DS . $reportId;
|
|
652
|
+
$reportData = array(
|
|
653
|
+
!empty($extra) ? $extra . "\n\n" : '' . $e->getMessage(),
|
|
654
|
+
$e->getTraceAsString()
|
|
655
|
+
);
|
|
656
|
+
$reportData = serialize($reportData);
|
|
657
|
+
|
|
658
|
+
file_put_contents($reportFile, $reportData);
|
|
659
|
+
chmod($reportFile, 0777);
|
|
660
|
+
|
|
661
|
+
$storeCode = 'default';
|
|
662
|
+
try {
|
|
663
|
+
$storeCode = self::app()->getStore()->getCode();
|
|
664
|
+
}
|
|
665
|
+
catch (Exception $e) {}
|
|
666
|
+
|
|
667
|
+
$baseUrl = self::getScriptSystemUrl('report', true);
|
|
668
|
+
$reportUrl = rtrim($baseUrl, '/') . '/report/?id='
|
|
669
|
+
. $reportId . '&s=' . $storeCode;
|
|
670
|
+
|
|
671
|
+
if (!headers_sent()) {
|
|
672
|
+
header('Location: ' . $reportUrl);
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
print '<script type="text/javascript">';
|
|
676
|
+
print "window.location.href = '{$reportUrl}';";
|
|
677
|
+
print '</script>';
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
die();
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Define system folder directory url by virtue of running script directory name
|
|
686
|
+
* Try to find requested folder by shifting to domain root directory
|
|
687
|
+
*
|
|
688
|
+
* @param string $folder
|
|
689
|
+
* @param boolean $exitIfNot
|
|
690
|
+
* @return string
|
|
691
|
+
*/
|
|
692
|
+
public static function getScriptSystemUrl($folder, $exitIfNot = false)
|
|
693
|
+
{
|
|
694
|
+
$runDirUrl = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/');
|
|
695
|
+
$runDir = rtrim(dirname($_SERVER['SCRIPT_FILENAME']), DS);
|
|
696
|
+
|
|
697
|
+
$baseUrl = null;
|
|
698
|
+
if (is_dir($runDir.'/'.$folder)) {
|
|
699
|
+
$baseUrl = str_replace(DS, '/', $runDirUrl);
|
|
700
|
+
} else {
|
|
701
|
+
$runDirUrlArray = explode('/', $runDirUrl);
|
|
702
|
+
$runDirArray = explode('/', $runDir);
|
|
703
|
+
$count = count($runDirArray);
|
|
704
|
+
|
|
705
|
+
for ($i=0; $i < $count; $i++) {
|
|
706
|
+
array_pop($runDirUrlArray);
|
|
707
|
+
array_pop($runDirArray);
|
|
708
|
+
$_runDir = implode('/', $runDirArray);
|
|
709
|
+
if (!empty($_runDir)) {
|
|
710
|
+
$_runDir .= '/';
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
if (is_dir($_runDir.$folder)) {
|
|
714
|
+
$_runDirUrl = implode('/', $runDirUrlArray);
|
|
715
|
+
$baseUrl = str_replace(DS, '/', $_runDirUrl);
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
if (is_null($baseUrl)) {
|
|
722
|
+
$errorMessage = "Unable detect system directory: $folder";
|
|
723
|
+
if ($exitIfNot) {
|
|
724
|
+
// exit because of infinity loop
|
|
725
|
+
exit($errorMessage);
|
|
726
|
+
} else {
|
|
727
|
+
self::printException(new Exception(), $errorMessage);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
return $baseUrl;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
public static function setIsDownloader($flag=true)
|
|
735
|
+
{
|
|
736
|
+
self::$_isDownloader = $flag;
|
|
737
|
+
}
|
|
738
|
+
}
|