Mage_Downloader - Version 1.7.0.0

Version Notes

1.7.0.0

Download this release

Release Info

Developer Magento Core Team
Extension Mage_Downloader
Version 1.7.0.0
Comparing to
See all releases


Code changes from version 1.6.2.0 to 1.7.0.0

Files changed (123) hide show
  1. .htaccess +23 -0
  2. downloader/Maged/Connect.php +156 -106
  3. downloader/Maged/Connect/Frontend.php +1 -1
  4. downloader/Maged/Controller.php +120 -4
  5. downloader/Maged/Exception.php +1 -1
  6. downloader/Maged/Model.php +1 -1
  7. downloader/Maged/Model/Config.php +1 -1
  8. downloader/Maged/Model/Config/Abstract.php +1 -1
  9. downloader/Maged/Model/Config/Community.php +1 -1
  10. downloader/Maged/Model/Config/Interface.php +1 -1
  11. downloader/Maged/Model/Connect.php +1 -1
  12. downloader/Maged/Model/Connect/Request.php +1 -1
  13. downloader/Maged/Model/Dowloader.php +1 -1
  14. downloader/Maged/Model/Session.php +1 -1
  15. downloader/Maged/View.php +1 -1
  16. downloader/favicon.ico +0 -0
  17. downloader/index.php +1 -1
  18. downloader/lib/Mage/Archive.php +6 -6
  19. downloader/lib/Mage/Archive/Abstract.php +7 -4
  20. downloader/lib/Mage/Archive/Bz.php +25 -15
  21. downloader/lib/Mage/Archive/Gz.php +25 -15
  22. downloader/lib/Mage/Archive/Helper/File.php +274 -0
  23. downloader/lib/Mage/Archive/Helper/File/Bz.php +92 -0
  24. downloader/lib/Mage/Archive/Helper/File/Gz.php +83 -0
  25. downloader/lib/Mage/Archive/Interface.php +1 -1
  26. downloader/lib/Mage/Archive/Tar.php +366 -50
  27. downloader/lib/Mage/Autoload/Simple.php +1 -1
  28. downloader/lib/Mage/Backup.php +59 -0
  29. downloader/lib/Mage/Backup/Abstract.php +318 -0
  30. downloader/lib/Mage/Backup/Archive/Tar.php +82 -0
  31. downloader/lib/Mage/Backup/Db.php +119 -0
  32. downloader/lib/Mage/Backup/Exception.php +36 -0
  33. downloader/lib/Mage/Backup/Exception/CantLoadSnapshot.php +36 -0
  34. downloader/lib/Mage/Backup/Exception/FtpConnectionFailed.php +36 -0
  35. downloader/lib/Mage/Backup/Exception/FtpValidationFailed.php +36 -0
  36. downloader/lib/Mage/Backup/Exception/NotEnoughFreeSpace.php +36 -0
  37. downloader/lib/Mage/Backup/Exception/NotEnoughPermissions.php +36 -0
  38. downloader/lib/Mage/Backup/Filesystem.php +284 -0
  39. downloader/lib/Mage/Backup/Filesystem/Helper.php +137 -0
  40. downloader/lib/Mage/Backup/Filesystem/Iterator/File.php +112 -0
  41. downloader/lib/Mage/Backup/Filesystem/Iterator/Filter.php +77 -0
  42. downloader/lib/Mage/Backup/Filesystem/Rollback/Abstract.php +57 -0
  43. downloader/lib/Mage/Backup/Filesystem/Rollback/Fs.php +78 -0
  44. downloader/lib/Mage/Backup/Filesystem/Rollback/Ftp.php +194 -0
  45. downloader/lib/Mage/Backup/Interface.php +88 -0
  46. downloader/lib/Mage/Backup/Media.php +99 -0
  47. downloader/lib/Mage/Backup/Nomedia.php +82 -0
  48. downloader/lib/Mage/Backup/Snapshot.php +140 -0
  49. downloader/lib/Mage/Connect/Channel/Generator.php +1 -1
  50. downloader/lib/Mage/Connect/Channel/Parser.php +1 -1
  51. downloader/lib/Mage/Connect/Channel/VO.php +1 -1
  52. downloader/lib/Mage/Connect/Command.php +85 -32
  53. downloader/lib/Mage/Connect/Command/Channels.php +1 -1
  54. downloader/lib/Mage/Connect/Command/Channels_Header.php +1 -1
  55. downloader/lib/Mage/Connect/Command/Config.php +13 -10
  56. downloader/lib/Mage/Connect/Command/Config_Header.php +1 -1
  57. downloader/lib/Mage/Connect/Command/Install.php +104 -125
  58. downloader/lib/Mage/Connect/Command/Install_Header.php +1 -1
  59. downloader/lib/Mage/Connect/Command/Package.php +1 -1
  60. downloader/lib/Mage/Connect/Command/Package_Header.php +1 -1
  61. downloader/lib/Mage/Connect/Command/Registry.php +1 -1
  62. downloader/lib/Mage/Connect/Command/Registry_Header.php +1 -1
  63. downloader/lib/Mage/Connect/Command/Remote.php +1 -1
  64. downloader/lib/Mage/Connect/Command/Remote_Header.php +1 -1
  65. downloader/lib/Mage/Connect/Config.php +167 -14
  66. downloader/lib/Mage/Connect/Converter.php +1 -1
  67. downloader/lib/Mage/Connect/Frontend.php +38 -22
  68. downloader/lib/Mage/Connect/Frontend/CLI.php +1 -1
  69. downloader/lib/Mage/Connect/Ftp.php +58 -48
  70. downloader/lib/Mage/Connect/Loader.php +4 -5
  71. downloader/lib/Mage/Connect/Loader/Ftp.php +1 -1
  72. downloader/lib/Mage/Connect/Package.php +1 -1
  73. downloader/lib/Mage/Connect/Package/Hotfix.php +1 -1
  74. downloader/lib/Mage/Connect/Package/Reader.php +1 -1
  75. downloader/lib/Mage/Connect/Package/Target.php +1 -1
  76. downloader/lib/Mage/Connect/Package/VO.php +1 -1
  77. downloader/lib/Mage/Connect/Package/Writer.php +1 -1
  78. downloader/lib/Mage/Connect/Packager.php +45 -40
  79. downloader/lib/Mage/Connect/Rest.php +85 -61
  80. downloader/lib/Mage/Connect/Singleconfig.php +221 -94
  81. downloader/lib/Mage/Connect/Structures/Graph.php +1 -1
  82. downloader/lib/Mage/Connect/Structures/Node.php +1 -1
  83. downloader/lib/Mage/Connect/Validator.php +106 -65
  84. downloader/lib/Mage/DB/Exception.php +1 -1
  85. downloader/lib/Mage/DB/Mysqli.php +1 -1
  86. downloader/lib/Mage/Exception.php +1 -1
  87. downloader/lib/Mage/HTTP/Client.php +10 -12
  88. downloader/lib/Mage/HTTP/Client/Curl.php +1 -1
  89. downloader/lib/Mage/HTTP/Client/Socket.php +1 -1
  90. downloader/lib/Mage/HTTP/IClient.php +1 -1
  91. downloader/lib/Mage/System/Args.php +3 -3
  92. downloader/lib/Mage/System/Dirs.php +16 -16
  93. downloader/lib/Mage/System/Ftp.php +509 -0
  94. downloader/lib/Mage/Xml/Generator.php +1 -1
  95. downloader/lib/Mage/Xml/Parser.php +1 -1
  96. downloader/mage.php +1 -1
  97. downloader/skin/boxes.css +1 -1
  98. downloader/skin/ie7boxes.css +1 -1
  99. downloader/skin/ieboxes.css +1 -1
  100. downloader/skin/install/boxes.css +1 -1
  101. downloader/skin/install/clears.css +1 -1
  102. downloader/skin/install/ie7minus.css +1 -1
  103. downloader/skin/install/iestyles.css +1 -1
  104. downloader/skin/install/reset.css +1 -1
  105. downloader/target.xml +15 -0
  106. downloader/template/connect/iframe.phtml +6 -2
  107. downloader/template/connect/packages.phtml +48 -6
  108. downloader/template/connect/packages_prepare.phtml +1 -1
  109. downloader/template/exception.phtml +1 -1
  110. downloader/template/footer.phtml +2 -2
  111. downloader/template/header.phtml +1 -1
  112. downloader/template/index.phtml +1 -1
  113. downloader/template/install/download.phtml +17 -7
  114. downloader/template/install/footer.phtml +2 -2
  115. downloader/template/install/header.phtml +1 -1
  116. downloader/template/install/writable.phtml +1 -1
  117. downloader/template/login.phtml +1 -1
  118. downloader/template/messages.phtml +1 -1
  119. downloader/template/noroute.phtml +1 -1
  120. downloader/template/settings.phtml +1 -1
  121. downloader/template/writable.phtml +1 -1
  122. index.php +10 -3
  123. package.xml +5 -5
.htaccess CHANGED
@@ -122,12 +122,35 @@
122
123
#RewriteBase /magento/
124
125
############################################
126
## workaround for HTTP authorization
127
## in CGI environment
128
129
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
130
131
############################################
132
## always send 404 on missing files in these folders
133
122
123
#RewriteBase /magento/
124
125
+ ############################################
126
+ ## uncomment next line to enable light API calls processing
127
+
128
+ # RewriteRule ^api/([a-z][0-9a-z_]+)/?$ api.php?type=$1 [QSA,L]
129
+
130
+ ############################################
131
+ ## rewrite API2 calls to api.php (by now it is REST only)
132
+
133
+ RewriteRule ^api/rest api.php?type=rest [QSA,L]
134
+
135
############################################
136
## workaround for HTTP authorization
137
## in CGI environment
138
139
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
140
141
+ ############################################
142
+ ## TRACE and TRACK HTTP methods disabled to prevent XSS attacks
143
+
144
+ RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
145
+ RewriteRule .* - [L,R=405]
146
+
147
+ ############################################
148
+ ## redirect for mobile user agents
149
+
150
+ #RewriteCond %{REQUEST_URI} !^/mobiledirectoryhere/.*$
151
+ #RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
152
+ #RewriteRule ^(.*)$ /mobiledirectoryhere/ [L,R=302]
153
+
154
############################################
155
## always send 404 on missing files in these folders
156
downloader/Maged/Connect.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
@@ -55,17 +55,17 @@ class Maged_Connect
55
{
56
57
/**
58
- * Object of config
59
- *
60
- * @var Mage_Connect_Config
61
- */
62
protected $_config;
63
64
/**
65
- * Object of single config
66
- *
67
- * @var Mage_Connect_Singleconfig
68
- */
69
protected $_sconfig;
70
71
/**
@@ -76,22 +76,29 @@ class Maged_Connect
76
protected $_frontend;
77
78
/**
79
- * Internal cache for command objects
80
- *
81
- * @var array
82
- */
83
protected $_cmdCache = array();
84
85
/**
86
- * Instance of class
87
- *
88
- * @var Maged_Connect
89
- */
90
static protected $_instance;
91
92
/**
93
- * Constructor
94
- */
95
public function __construct()
96
{
97
$this->getConfig();
@@ -100,10 +107,20 @@ class Maged_Connect
100
}
101
102
/**
103
- * Initialize instance
104
- *
105
- * @return Maged_Connect
106
- */
107
public static function getInstance()
108
{
109
if (!self::$_instance) {
@@ -113,10 +130,10 @@ class Maged_Connect
113
}
114
115
/**
116
- * Retrieve object of config and set it to Mage_Connect_Command
117
- *
118
- * @return Mage_Connect_Config
119
- */
120
public function getConfig()
121
{
122
if (!$this->_config) {
@@ -135,15 +152,19 @@ class Maged_Connect
135
}
136
137
/**
138
- * Retrieve object of single config and set it to Mage_Connect_Command
139
- *
140
- * @param bool $reload
141
- * @return Mage_Connect_Singleconfig
142
- */
143
public function getSingleConfig($reload = false)
144
{
145
if(!$this->_sconfig || $reload) {
146
- $this->_sconfig = new Mage_Connect_Singleconfig($this->getConfig()->magento_root . DIRECTORY_SEPARATOR . $this->getConfig()->downloader_path . DIRECTORY_SEPARATOR . Mage_Connect_Singleconfig::DEFAULT_SCONFIG_FILENAME);
147
}
148
Mage_Connect_Command::setSconfig($this->_sconfig);
149
return $this->_sconfig;
@@ -151,10 +172,10 @@ class Maged_Connect
151
}
152
153
/**
154
- * Retrieve object of frontend and set it to Mage_Connect_Command
155
- *
156
- * @return Maged_Connect_Frontend
157
- */
158
public function getFrontend()
159
{
160
if (!$this->_frontend) {
@@ -165,30 +186,30 @@ class Maged_Connect
165
}
166
167
/**
168
- * Retrieve lof from frontend
169
- *
170
- * @return array
171
- */
172
public function getLog()
173
{
174
return $this->getFrontend()->getLog();
175
}
176
177
/**
178
- * Retrieve output from frontend
179
- *
180
- * @return array
181
- */
182
public function getOutput()
183
{
184
return $this->getFrontend()->getOutput();
185
}
186
187
/**
188
- * Clean registry
189
- *
190
- * @return Maged_Connect
191
- */
192
public function cleanSconfig()
193
{
194
$this->getSingleConfig()->clear();
@@ -196,11 +217,11 @@ class Maged_Connect
196
}
197
198
/**
199
- * Delete directory recursively
200
- *
201
- * @param string $path
202
- * @return Maged_Connect
203
- */
204
public function delTree($path) {
205
if (@is_dir($path)) {
206
$entries = @scandir($path);
@@ -217,13 +238,13 @@ class Maged_Connect
217
}
218
219
/**
220
- * Run commands from Mage_Connect_Command
221
- *
222
- * @param string $command
223
- * @param array $options
224
- * @param array $params
225
- * @return
226
- */
227
public function run($command, $options=array(), $params=array())
228
{
229
@set_time_limit(0);
@@ -257,16 +278,20 @@ class Maged_Connect
257
}
258
}
259
260
- public function setRemoteConfig($uri) #$host, $user, $password, $path='', $port=null)
261
{
262
- #$uri = 'ftp://' . $user . ':' . $password . '@' . $host . (is_numeric($port) ? ':' . $port : '') . '/' . trim($path, '/') . '/';
263
- //$this->run('config-set', array(), array('remote_config', $uri));
264
- //$this->run('config-set', array('ftp'=>$uri), array('remote_config', $uri));
265
$this->getConfig()->remote_config=$uri;
266
return $this;
267
}
268
269
/**
270
*
271
* @param array $errors Error messages
272
* @return Maged_Connect
@@ -277,7 +302,7 @@ class Maged_Connect
277
$run = new Maged_Model_Connect_Request();
278
if ($callback = $run->get('failure_callback')) {
279
if (is_array($callback)) {
280
- call_user_func_array($callback, array($result));
281
} else {
282
echo $callback;
283
}
@@ -290,8 +315,9 @@ class Maged_Connect
290
/**
291
* Run Mage_Connect_Command with html output console style
292
*
293
- * @param array|Maged_Model $runParams command, options, params,
294
- * comment, success_callback, failure_callback
295
*/
296
public function runHtmlConsole($runParams)
297
{
@@ -318,6 +344,58 @@ class Maged_Connect
318
}
319
320
if (!$run->get('no-header')) {
321
?>
322
<html><head><style type="text/css">
323
body { margin:0px;
@@ -414,44 +492,17 @@ function clear_cache(callbacks)
414
}
415
</script>
416
<?php
417
}
418
- echo htmlspecialchars($run->get('comment'));
419
-
420
- if ($command = $run->get('command')) {
421
- $result = $this->run($command, $run->get('options'), $run->get('params'));
422
423
- if ($this->getFrontend()->hasErrors()) {
424
- echo "<br/>CONNECT ERROR: ";
425
- foreach ($this->getFrontend()->getErrors(false) as $error) {
426
- echo nl2br($error[1]);
427
- echo '<br/>';
428
- }
429
- }
430
- echo '<script type="text/javascript">';
431
- if ($this->getFrontend()->hasErrors()) {
432
- if ($callback = $run->get('failure_callback')) {
433
- if (is_array($callback)) {
434
- call_user_func_array($callback, array($result));
435
- } else {
436
- echo $callback;
437
- }
438
- }
439
- } else {
440
- if (!$run->get('no-footer')) {
441
- if ($callback = $run->get('success_callback')) {
442
- if (is_array($callback)) {
443
- call_user_func_array($callback, array($result));
444
- } else {
445
- echo $callback;
446
- }
447
- }
448
- }
449
- }
450
- echo '</script>';
451
- } else {
452
- $result = false;
453
- }
454
- if ($this->getFrontend()->getErrors() || !$run->get('no-footer')) {
455
?>
456
<script type="text/javascript">
457
if (parent && parent.disableInputs) {
@@ -460,8 +511,7 @@ if (parent && parent.disableInputs) {
460
</script>
461
</body></html>
462
<?php
463
- $fe->setLogStream($oldLogStream);
464
}
465
- return $result;
466
}
467
}
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
55
{
56
57
/**
58
+ * Object of config
59
+ *
60
+ * @var Mage_Connect_Config
61
+ */
62
protected $_config;
63
64
/**
65
+ * Object of single config
66
+ *
67
+ * @var Mage_Connect_Singleconfig
68
+ */
69
protected $_sconfig;
70
71
/**
76
protected $_frontend;
77
78
/**
79
+ * Internal cache for command objects
80
+ *
81
+ * @var array
82
+ */
83
protected $_cmdCache = array();
84
85
/**
86
+ * Console Started flag
87
+ *
88
+ * @var boolean
89
+ */
90
+ protected $_consoleStarted = false;
91
+
92
+ /**
93
+ * Instance of class
94
+ *
95
+ * @var Maged_Connect
96
+ */
97
static protected $_instance;
98
99
/**
100
+ * Constructor loads Config, Cache Config and initializes Frontend
101
+ */
102
public function __construct()
103
{
104
$this->getConfig();
107
}
108
109
/**
110
+ * Destructor, sends Console footer if Console started
111
+ */
112
+ public function __destruct()
113
+ {
114
+ if ($this->_consoleStarted) {
115
+ $this->_consoleFooter();
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Initialize instance
121
+ *
122
+ * @return Maged_Connect
123
+ */
124
public static function getInstance()
125
{
126
if (!self::$_instance) {
130
}
131
132
/**
133
+ * Retrieve object of config and set it to Mage_Connect_Command
134
+ *
135
+ * @return Mage_Connect_Config
136
+ */
137
public function getConfig()
138
{
139
if (!$this->_config) {
152
}
153
154
/**
155
+ * Retrieve object of single config and set it to Mage_Connect_Command
156
+ *
157
+ * @param bool $reload
158
+ * @return Mage_Connect_Singleconfig
159
+ */
160
public function getSingleConfig($reload = false)
161
{
162
if(!$this->_sconfig || $reload) {
163
+ $this->_sconfig = new Mage_Connect_Singleconfig(
164
+ $this->getConfig()->magento_root . DIRECTORY_SEPARATOR
165
+ . $this->getConfig()->downloader_path . DIRECTORY_SEPARATOR
166
+ . Mage_Connect_Singleconfig::DEFAULT_SCONFIG_FILENAME
167
+ );
168
}
169
Mage_Connect_Command::setSconfig($this->_sconfig);
170
return $this->_sconfig;
172
}
173
174
/**
175
+ * Retrieve object of frontend and set it to Mage_Connect_Command
176
+ *
177
+ * @return Maged_Connect_Frontend
178
+ */
179
public function getFrontend()
180
{
181
if (!$this->_frontend) {
186
}
187
188
/**
189
+ * Retrieve lof from frontend
190
+ *
191
+ * @return array
192
+ */
193
public function getLog()
194
{
195
return $this->getFrontend()->getLog();
196
}
197
198
/**
199
+ * Retrieve output from frontend
200
+ *
201
+ * @return array
202
+ */
203
public function getOutput()
204
{
205
return $this->getFrontend()->getOutput();
206
}
207
208
/**
209
+ * Clean registry
210
+ *
211
+ * @return Maged_Connect
212
+ */
213
public function cleanSconfig()
214
{
215
$this->getSingleConfig()->clear();
217
}
218
219
/**
220
+ * Delete directory recursively
221
+ *
222
+ * @param string $path
223
+ * @return Maged_Connect
224
+ */
225
public function delTree($path) {
226
if (@is_dir($path)) {
227
$entries = @scandir($path);
238
}
239
240
/**
241
+ * Run commands from Mage_Connect_Command
242
+ *
243
+ * @param string $command
244
+ * @param array $options
245
+ * @param array $params
246
+ * @return boolean|Mage_Connect_Error
247
+ */
248
public function run($command, $options=array(), $params=array())
249
{
250
@set_time_limit(0);
278
}
279
}
280
281
+ /**
282
+ * Set remote Config by URI
283
+ *
284
+ * @param $uri
285
+ * @return Maged_Connect
286
+ */
287
+ public function setRemoteConfig($uri)
288
{
289
$this->getConfig()->remote_config=$uri;
290
return $this;
291
}
292
293
/**
294
+ * Show Errors
295
*
296
* @param array $errors Error messages
297
* @return Maged_Connect
302
$run = new Maged_Model_Connect_Request();
303
if ($callback = $run->get('failure_callback')) {
304
if (is_array($callback)) {
305
+ call_user_func_array($callback, array($errors));
306
} else {
307
echo $callback;
308
}
315
/**
316
* Run Mage_Connect_Command with html output console style
317
*
318
+ * @throws Maged_Exception
319
+ * @param array|string|Maged_Model $runParams command, options, params, comment, success_callback, failure_callback
320
+ * @return bool|Mage_Connect_Error
321
*/
322
public function runHtmlConsole($runParams)
323
{
344
}
345
346
if (!$run->get('no-header')) {
347
+ $this->_consoleHeader();
348
+ }
349
+ echo htmlspecialchars($run->get('comment')).'<br/>';
350
+
351
+ if ($command = $run->get('command')) {
352
+ $result = $this->run($command, $run->get('options'), $run->get('params'));
353
+
354
+ if ($this->getFrontend()->hasErrors()) {
355
+ echo "<br/>CONNECT ERROR: ";
356
+ foreach ($this->getFrontend()->getErrors(false) as $error) {
357
+ echo nl2br($error[1]);
358
+ echo '<br/>';
359
+ }
360
+ }
361
+ echo '<script type="text/javascript">';
362
+ if ($this->getFrontend()->hasErrors()) {
363
+ if ($callback = $run->get('failure_callback')) {
364
+ if (is_array($callback)) {
365
+ call_user_func_array($callback, array($result));
366
+ } else {
367
+ echo $callback;
368
+ }
369
+ }
370
+ } else {
371
+ if (!$run->get('no-footer')) {
372
+ if ($callback = $run->get('success_callback')) {
373
+ if (is_array($callback)) {
374
+ call_user_func_array($callback, array($result));
375
+ } else {
376
+ echo $callback;
377
+ }
378
+ }
379
+ }
380
+ }
381
+ echo '</script>';
382
+ } else {
383
+ $result = false;
384
+ }
385
+ if ($this->getFrontend()->getErrors() || !$run->get('no-footer')) {
386
+ //$this->_consoleFooter();
387
+ $fe->setLogStream($oldLogStream);
388
+ }
389
+ return $result;
390
+ }
391
+
392
+ /**
393
+ * Show HTML Console Header
394
+ *
395
+ * @return void
396
+ */
397
+ protected function _consoleHeader() {
398
+ if (!$this->_consoleStarted) {
399
?>
400
<html><head><style type="text/css">
401
body { margin:0px;
492
}
493
</script>
494
<?php
495
+ $this->_consoleStarted = true;
496
}
497
+ }
498
499
+ /**
500
+ * Show HTML Console Footer
501
+ *
502
+ * @return void
503
+ */
504
+ protected function _consoleFooter() {
505
+ if ($this->_consoleStarted) {
506
?>
507
<script type="text/javascript">
508
if (parent && parent.disableInputs) {
511
</script>
512
</body></html>
513
<?php
514
+ $this->_consoleStarted = false;
515
}
516
}
517
}
downloader/Maged/Connect/Frontend.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Controller.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
@@ -492,7 +492,6 @@ final class Maged_Controller
492
self::singleton()->dispatch();
493
} catch (Exception $e) {
494
echo $e->getMessage();
495
- //echo self::singleton()->view()->set('exception', $e)->template("exception.phtml");
496
}
497
}
498
@@ -597,7 +596,7 @@ final class Maged_Controller
597
if (is_null($model)) {
598
$class = 'Maged_Model';
599
} else {
600
- $class = 'Maged_Model_'.str_replace(' ', '_', ucwords(str_replace('_', ' ', $model)));
601
if (!class_exists($class, false)) {
602
include_once str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
603
}
@@ -884,6 +883,31 @@ final class Maged_Controller
884
@file_put_contents($this->_getMaintenanceFilePath(), 'maintenance');
885
}
886
}
887
}
888
889
/**
@@ -967,11 +991,103 @@ final class Maged_Controller
967
{
968
return array(
969
'major' => '1',
970
- 'minor' => '5',
971
'revision' => '0',
972
'patch' => '0',
973
'stability' => '',
974
'number' => '',
975
);
976
}
977
}
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
492
self::singleton()->dispatch();
493
} catch (Exception $e) {
494
echo $e->getMessage();
495
}
496
}
497
596
if (is_null($model)) {
597
$class = 'Maged_Model';
598
} else {
599
+ $class = 'Maged_Model_' . str_replace(' ', '_', ucwords(str_replace('_', ' ', $model)));
600
if (!class_exists($class, false)) {
601
include_once str_replace('_', DIRECTORY_SEPARATOR, $class).'.php';
602
}
883
@file_put_contents($this->_getMaintenanceFilePath(), 'maintenance');
884
}
885
}
886
+
887
+ if (!empty($_GET['archive_type'])) {
888
+
889
+ $backupName = $_GET['backup_name'];
890
+ $connect = $this->model('connect', true)->connect();
891
+ $isSuccess = true;
892
+
893
+ if (!preg_match('/^[a-zA-Z0-9\ ]{0,50}#x2F;', $backupName)) {
894
+ $connect->runHtmlConsole('Please use only letters (a-z or A-Z), numbers (0-9) or space in '
895
+ . 'Backup Name field. Other characters are not allowed.');
896
+ $isSuccess = false;
897
+ }
898
+
899
+ if ($isSuccess) {
900
+ $isSuccess = $this->_createBackup($_GET['archive_type'], $_GET['backup_name']);
901
+ }
902
+
903
+ if (!$isSuccess) {
904
+ $this->endInstall();
905
+ $this->cleanCache();
906
+ throw new Mage_Exception(
907
+ 'The installation process has been canceled because of the backup creation error'
908
+ );
909
+ }
910
+ }
911
}
912
913
/**
991
{
992
return array(
993
'major' => '1',
994
+ 'minor' => '7',
995
'revision' => '0',
996
'patch' => '0',
997
'stability' => '',
998
'number' => '',
999
);
1000
}
1001
+
1002
+ /**
1003
+ * Create Backup
1004
+ *
1005
+ * @param string $archiveType
1006
+ * @param string $archiveName
1007
+ * @return bool
1008
+ */
1009
+ protected function _createBackup($archiveType, $archiveName){
1010
+ /** @var $connect Maged_Connect */
1011
+ $connect = $this->model('connect', true)->connect();
1012
+ $connect->runHtmlConsole('Creating backup...');
1013
+
1014
+ $isSuccess = false;
1015
+
1016
+ try {
1017
+ $type = $this->_getBackupTypeByCode($archiveType);
1018
+
1019
+ $backupManager = Mage_Backup::getBackupInstance($type)
1020
+ ->setBackupExtension(Mage::helper('backup')->getExtensionByType($type))
1021
+ ->setTime(time())
1022
+ ->setName($archiveName)
1023
+ ->setBackupsDir(Mage::helper('backup')->getBackupsDir());
1024
+
1025
+ Mage::register('backup_manager', $backupManager);
1026
+
1027
+ if ($type != Mage_Backup_Helper_Data::TYPE_DB) {
1028
+ $backupManager->setRootDir(Mage::getBaseDir())
1029
+ ->addIgnorePaths(Mage::helper('backup')->getBackupIgnorePaths());
1030
+ }
1031
+ $backupManager->create();
1032
+ $connect->runHtmlConsole(
1033
+ $this->_getCreateBackupSuccessMessageByType($type)
1034
+ );
1035
+ $isSuccess = true;
1036
+ } catch (Mage_Backup_Exception_NotEnoughFreeSpace $e) {
1037
+ $connect->runHtmlConsole('Not enough free space to create backup.');
1038
+ Mage::logException($e);
1039
+ } catch (Mage_Backup_Exception_NotEnoughPermissions $e) {
1040
+ $connect->runHtmlConsole('Not enough permissions to create backup.');
1041
+ Mage::logException($e);
1042
+ } catch (Exception $e) {
1043
+ $connect->runHtmlConsole('An error occurred while creating the backup.');
1044
+ Mage::logException($e);
1045
+ }
1046
+
1047
+ return $isSuccess;
1048
+ }
1049
+
1050
+ /**
1051
+ * Retrieve Backup Type by Code
1052
+ *
1053
+ * @param int $code
1054
+ * @return string
1055
+ */
1056
+ protected function _getBackupTypeByCode($code)
1057
+ {
1058
+ $typeMap = array(
1059
+ 1 => Mage_Backup_Helper_Data::TYPE_DB,
1060
+ 2 => Mage_Backup_Helper_Data::TYPE_SYSTEM_SNAPSHOT,
1061
+ 3 => Mage_Backup_Helper_Data::TYPE_SNAPSHOT_WITHOUT_MEDIA,
1062
+ 4 => Mage_Backup_Helper_Data::TYPE_MEDIA
1063
+ );
1064
+
1065
+ if (!isset($typeMap[$code])) {
1066
+ Mage::throwException('Unknown backup type');
1067
+ }
1068
+
1069
+ return $typeMap[$code];
1070
+ }
1071
+
1072
+ /**
1073
+ * Get backup create success message by backup type
1074
+ *
1075
+ * @param string $type
1076
+ * @return string
1077
+ */
1078
+ protected function _getCreateBackupSuccessMessageByType($type)
1079
+ {
1080
+ $messagesMap = array(
1081
+ Mage_Backup_Helper_Data::TYPE_SYSTEM_SNAPSHOT => 'System backup has been created',
1082
+ Mage_Backup_Helper_Data::TYPE_SNAPSHOT_WITHOUT_MEDIA => 'System (excluding Media) backup has been created',
1083
+ Mage_Backup_Helper_Data::TYPE_MEDIA => 'Database and media backup has been created',
1084
+ Mage_Backup_Helper_Data::TYPE_DB => 'Database backup has been created'
1085
+ );
1086
+
1087
+ if (!isset($messagesMap[$type])) {
1088
+ return '';
1089
+ }
1090
+
1091
+ return $messagesMap[$type];
1092
+ }
1093
}
downloader/Maged/Exception.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Model.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Model/Config.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Model/Config/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Model/Config/Community.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Model/Config/Interface.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Model/Connect.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Model/Connect/Request.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Model/Dowloader.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/Model/Session.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/Maged/View.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/favicon.ico ADDED
Binary file
downloader/index.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Connect
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Connect
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/lib/Mage/Archive.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Archive
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
@@ -84,7 +84,7 @@ class Mage_Archive
84
} else {
85
$format = self::DEFAULT_ARCHIVER;
86
}
87
- $class = 'Mage_Archive_'.ucfirst($format);
88
$this->_archiver = new $class();
89
return $this->_archiver;
90
}
@@ -157,12 +157,13 @@ class Mage_Archive
157
if ($i == 0) {
158
$packed = rtrim($destination, DS) . DS;
159
} else {
160
- $packed = rtrim($destination, DS) . DS . '~tmp-'. microtime(true) . $archivers[$i-1] . '.' . $archivers[$i-1];
161
}
162
$source = $this->_getArchiver($archivers[$i])->unpack($source, $packed);
163
-
164
//var_dump($packed, $source);
165
-
166
if ($clearInterm && $interimSource && $i >= 0) {
167
unlink($interimSource);
168
}
@@ -218,5 +219,4 @@ class Mage_Archive
218
}
219
return false;
220
}
221
-
222
}
20
*
21
* @category Mage
22
* @package Mage_Archive
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
84
} else {
85
$format = self::DEFAULT_ARCHIVER;
86
}
87
+ $class = 'Mage_Archive_' . ucfirst($format);
88
$this->_archiver = new $class();
89
return $this->_archiver;
90
}
157
if ($i == 0) {
158
$packed = rtrim($destination, DS) . DS;
159
} else {
160
+ $packed = rtrim($destination, DS) . DS . '~tmp-'. microtime(true) . $archivers[$i-1] . '.'
161
+ . $archivers[$i-1];
162
}
163
$source = $this->_getArchiver($archivers[$i])->unpack($source, $packed);
164
+
165
//var_dump($packed, $source);
166
+
167
if ($clearInterm && $interimSource && $i >= 0) {
168
unlink($interimSource);
169
}
219
}
220
return false;
221
}
222
}
downloader/lib/Mage/Archive/Abstract.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Archive
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
@@ -34,14 +34,16 @@
34
class Mage_Archive_Abstract
35
{
36
/**
37
- * Write data to file. If file can't be opened,
38
*
39
* @param string $destination
40
* @param string $data
41
* @return boolean
42
*/
43
protected function _writeFile($destination, $data)
44
{
45
if(false === file_put_contents($destination, $data)) {
46
throw new Mage_Exception("Can't write to file: " . $destination);
47
}
@@ -53,6 +55,7 @@ class Mage_Archive_Abstract
53
*
54
* @param string $source
55
* @return string
56
*/
57
protected function _readFile($source)
58
{
@@ -70,7 +73,8 @@ class Mage_Archive_Abstract
70
* Get file name from source (URI) without last extension.
71
*
72
* @param string $source
73
- * @return string
74
*/
75
public function getFilename($source, $withExtension=false)
76
{
@@ -80,5 +84,4 @@ class Mage_Archive_Abstract
80
}
81
return $file;
82
}
83
-
84
}
20
*
21
* @category Mage
22
* @package Mage_Archive
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
34
class Mage_Archive_Abstract
35
{
36
/**
37
+ * Write data to file. If file can't be opened - throw exception
38
*
39
* @param string $destination
40
* @param string $data
41
* @return boolean
42
+ * @throws Mage_Exception
43
*/
44
protected function _writeFile($destination, $data)
45
{
46
+ $destination = trim($destination);
47
if(false === file_put_contents($destination, $data)) {
48
throw new Mage_Exception("Can't write to file: " . $destination);
49
}
55
*
56
* @param string $source
57
* @return string
58
+ * @throws Mage_Exception
59
*/
60
protected function _readFile($source)
61
{
73
* Get file name from source (URI) without last extension.
74
*
75
* @param string $source
76
+ * @param bool $withExtension
77
+ * @return mixed|string
78
*/
79
public function getFilename($source, $withExtension=false)
80
{
84
}
85
return $file;
86
}
87
}
downloader/lib/Mage/Archive/Bz.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Archive
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
@@ -43,9 +43,19 @@ class Mage_Archive_Bz extends Mage_Archive_Abstract implements Mage_Archive_Inte
43
*/
44
public function pack($source, $destination)
45
{
46
- $data = $this->_readFile($source);
47
- $bzData = bzcompress($data, 9);
48
- $this->_writeFile($destination, $bzData);
49
return $destination;
50
}
51
@@ -58,21 +68,21 @@ class Mage_Archive_Bz extends Mage_Archive_Abstract implements Mage_Archive_Inte
58
*/
59
public function unpack($source, $destination)
60
{
61
- $data = '';
62
- $bzPointer = bzopen($source, 'r' );
63
- if (empty($bzPointer)) {
64
- throw new Exception('Can\'t open BZ archive : ' . $source);
65
- }
66
- while (!feof($bzPointer)) {
67
- $data .= bzread($bzPointer, 131072);
68
- }
69
- bzclose($bzPointer);
70
if (is_dir($destination)) {
71
$file = $this->getFilename($source);
72
$destination = $destination . $file;
73
}
74
- echo $destination;
75
- $this->_writeFile($destination, $data);
76
return $destination;
77
}
78
20
*
21
* @category Mage
22
* @package Mage_Archive
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
43
*/
44
public function pack($source, $destination)
45
{
46
+ $fileReader = new Mage_Archive_Helper_File($source);
47
+ $fileReader->open('r');
48
+
49
+ $archiveWriter = new Mage_Archive_Helper_File_Bz($destination);
50
+ $archiveWriter->open('w');
51
+
52
+ while (!$fileReader->eof()) {
53
+ $archiveWriter->write($fileReader->read());
54
+ }
55
+
56
+ $fileReader->close();
57
+ $archiveWriter->close();
58
+
59
return $destination;
60
}
61
68
*/
69
public function unpack($source, $destination)
70
{
71
if (is_dir($destination)) {
72
$file = $this->getFilename($source);
73
$destination = $destination . $file;
74
}
75
+
76
+ $archiveReader = new Mage_Archive_Helper_File_Bz($source);
77
+ $archiveReader->open('r');
78
+
79
+ $fileWriter = new Mage_Archive_Helper_File($destination);
80
+ $fileWriter->open('w');
81
+
82
+ while (!$archiveReader->eof()) {
83
+ $fileWriter->write($archiveReader->read());
84
+ }
85
+
86
return $destination;
87
}
88
downloader/lib/Mage/Archive/Gz.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Archive
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
@@ -42,9 +42,19 @@ class Mage_Archive_Gz extends Mage_Archive_Abstract implements Mage_Archive_Inte
42
*/
43
public function pack($source, $destination)
44
{
45
- $data = $this->_readFile($source);
46
- $gzData = gzencode($data, 9);
47
- $this->_writeFile($destination, $gzData);
48
return $destination;
49
}
50
@@ -57,21 +67,21 @@ class Mage_Archive_Gz extends Mage_Archive_Abstract implements Mage_Archive_Inte
57
*/
58
public function unpack($source, $destination)
59
{
60
- $gzPointer = gzopen($source, 'r' );
61
- if (empty($gzPointer)) {
62
- throw new Mage_Exception('Can\'t open GZ archive : ' . $source);
63
- }
64
- $data = '';
65
- while (!gzeof($gzPointer)) {
66
- $data .= gzread($gzPointer, 131072);
67
- }
68
- gzclose($gzPointer);
69
if (is_dir($destination)) {
70
$file = $this->getFilename($source);
71
$destination = $destination . $file;
72
}
73
- $this->_writeFile($destination, $data);
74
return $destination;
75
}
76
-
77
}
20
*
21
* @category Mage
22
* @package Mage_Archive
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
42
*/
43
public function pack($source, $destination)
44
{
45
+ $fileReader = new Mage_Archive_Helper_File($source);
46
+ $fileReader->open('r');
47
+
48
+ $archiveWriter = new Mage_Archive_Helper_File_Gz($destination);
49
+ $archiveWriter->open('wb9');
50
+
51
+ while (!$fileReader->eof()) {
52
+ $archiveWriter->write($fileReader->read());
53
+ }
54
+
55
+ $fileReader->close();
56
+ $archiveWriter->close();
57
+
58
return $destination;
59
}
60
67
*/
68
public function unpack($source, $destination)
69
{
70
if (is_dir($destination)) {
71
$file = $this->getFilename($source);
72
$destination = $destination . $file;
73
}
74
+
75
+ $archiveReader = new Mage_Archive_Helper_File_Gz($source);
76
+ $archiveReader->open('r');
77
+
78
+ $fileWriter = new Mage_Archive_Helper_File($destination);
79
+ $fileWriter->open('w');
80
+
81
+ while (!$archiveReader->eof()) {
82
+ $fileWriter->write($archiveReader->read());
83
+ }
84
+
85
return $destination;
86
}
87
}
downloader/lib/Mage/Archive/Helper/File.php ADDED
@@ -0,0 +1,274 @@
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_Archive
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Helper class that simplifies files stream reading and writing
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Archive
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Archive_Helper_File
35
+ {
36
+ /**
37
+ * Full path to directory where file located
38
+ *
39
+ * @var string
40
+ */
41
+ protected $_fileLocation;
42
+
43
+ /**
44
+ * File name
45
+ *
46
+ * @var string
47
+ */
48
+ protected $_fileName;
49
+
50
+ /**
51
+ * Full path (directory + filename) to file
52
+ *
53
+ * @var string
54
+ */
55
+ protected $_filePath;
56
+
57
+ /**
58
+ * File permissions that will be set if file opened in write mode
59
+ *
60
+ * @var int
61
+ */
62
+ protected $_chmod;
63
+
64
+ /**
65
+ * File handler
66
+ *
67
+ * @var pointer
68
+ */
69
+ protected $_fileHandler;
70
+
71
+ /**
72
+ * Set file path via constructor
73
+ *
74
+ * @param string $filePath
75
+ */
76
+ public function __construct($filePath)
77
+ {
78
+ $pathInfo = pathinfo($filePath);
79
+
80
+ $this->_filePath = $filePath;
81
+ $this->_fileLocation = isset($pathInfo['dirname']) ? $pathInfo['dirname'] : '';
82
+ $this->_fileName = isset($pathInfo['basename']) ? $pathInfo['basename'] : '';
83
+ }
84
+
85
+ /**
86
+ * Close file if it's not closed before object destruction
87
+ */
88
+ public function __destruct()
89
+ {
90
+ if ($this->_fileHandler) {
91
+ $this->_close();
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Open file
97
+ *
98
+ * @param string $mode
99
+ * @param int $chmod
100
+ * @throws Mage_Exception
101
+ */
102
+ public function open($mode = 'w+', $chmod = 0666)
103
+ {
104
+ if ($this->_isWritableMode($mode)) {
105
+ if (!is_writable($this->_fileLocation)) {
106
+ throw new Mage_Exception('Permission denied to write to ' . $this->_fileLocation);
107
+ }
108
+
109
+ if (is_file($this->_filePath) && !is_writable($this->_filePath)) {
110
+ throw new Mage_Exception("Can't open file " . $this->_fileName . " for writing. Permission denied.");
111
+ }
112
+ }
113
+
114
+ if ($this->_isReadableMode($mode) && (!is_file($this->_filePath) || !is_readable($this->_filePath))) {
115
+ if (!is_file($this->_filePath)) {
116
+ throw new Mage_Exception('File ' . $this->_filePath . ' does not exist');
117
+ }
118
+
119
+ if (!is_readable($this->_filePath)) {
120
+ throw new Mage_Exception('Permission denied to read file ' . $this->_filePath);
121
+ }
122
+ }
123
+
124
+ $this->_open($mode);
125
+
126
+ $this->_chmod = $chmod;
127
+ }
128
+
129
+ /**
130
+ * Write data to file
131
+ *
132
+ * @param string $data
133
+ */
134
+ public function write($data)
135
+ {
136
+ $this->_checkFileOpened();
137
+ $this->_write($data);
138
+ }
139
+
140
+ /**
141
+ * Read data from file
142
+ *
143
+ * @param int $length
144
+ * @return string|boolean
145
+ */
146
+ public function read($length = 4096)
147
+ {
148
+ $data = false;
149
+ $this->_checkFileOpened();
150
+ if ($length > 0) {
151
+ $data = $this->_read($length);
152
+ }
153
+
154
+ return $data;
155
+ }
156
+
157
+ /**
158
+ * Check whether end of file reached
159
+ *
160
+ * @return boolean
161
+ */
162
+ public function eof()
163
+ {
164
+ $this->_checkFileOpened();
165
+ return $this->_eof();
166
+ }
167
+
168
+ /**
169
+ * Close file
170
+ */
171
+ public function close()
172
+ {
173
+ $this->_checkFileOpened();
174
+ $this->_close();
175
+ $this->_fileHandler = false;
176
+ @chmod($this->_filePath, $this->_chmod);
177
+ }
178
+
179
+ /**
180
+ * Implementation of file opening
181
+ *
182
+ * @param string $mode
183
+ * @throws Mage_Exception
184
+ */
185
+ protected function _open($mode)
186
+ {
187
+ $this->_fileHandler = @fopen($this->_filePath, $mode);
188
+
189
+ if (false === $this->_fileHandler) {
190
+ throw new Mage_Exception('Failed to open file ' . $this->_filePath);
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Implementation of writing data to file
196
+ *
197
+ * @param string $data
198
+ * @throws Mage_Exception
199
+ */
200
+ protected function _write($data)
201
+ {
202
+ $result = @fwrite($this->_fileHandler, $data);
203
+
204
+ if (false === $result) {
205
+ throw new Mage_Exception('Failed to write data to ' . $this->_filePath);
206
+ }
207
+ }
208
+
209
+ /**
210
+ * Implementation of file reading
211
+ *
212
+ * @param int $length
213
+ * @throws Mage_Exception
214
+ */
215
+ protected function _read($length)
216
+ {
217
+ $result = fread($this->_fileHandler, $length);
218
+
219
+ if (false === $result) {
220
+ throw new Mage_Exception('Failed to read data from ' . $this->_filePath);
221
+ }
222
+
223
+ return $result;
224
+ }
225
+
226
+ /**
227
+ * Implementation of EOF indicator
228
+ *
229
+ * @return boolean
230
+ */
231
+ protected function _eof()
232
+ {
233
+ return feof($this->_fileHandler);
234
+ }
235
+
236
+ /**
237
+ * Implementation of file closing
238
+ */
239
+ protected function _close()
240
+ {
241
+ fclose($this->_fileHandler);
242
+ }
243
+
244
+ /**
245
+ * Check whether requested mode is writable mode
246
+ *
247
+ * @param string $mode
248
+ */
249
+ protected function _isWritableMode($mode)
250
+ {
251
+ return preg_match('/(^[waxc])|(\+$)/', $mode);
252
+ }
253
+
254
+ /**
255
+ * Check whether requested mode is readable mode
256
+ *
257
+ * @param string $mode
258
+ */
259
+ protected function _isReadableMode($mode) {
260
+ return !$this->_isWritableMode($mode);
261
+ }
262
+
263
+ /**
264
+ * Check whether file is opened
265
+ *
266
+ * @throws Mage_Exception
267
+ */
268
+ protected function _checkFileOpened()
269
+ {
270
+ if (!$this->_fileHandler) {
271
+ throw new Mage_Exception('File not opened');
272
+ }
273
+ }
274
+ }
downloader/lib/Mage/Archive/Helper/File/Bz.php ADDED
@@ -0,0 +1,92 @@
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_Archive
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Helper class that simplifies bz2 files stream reading and writing
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Archive
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Archive_Helper_File_Bz extends Mage_Archive_Helper_File
35
+ {
36
+ /**
37
+ * Open bz archive file
38
+ *
39
+ * @throws Mage_Exception
40
+ * @param string $mode
41
+ */
42
+ protected function _open($mode)
43
+ {
44
+ $this->_fileHandler = @bzopen($this->_filePath, $mode);
45
+
46
+ if (false === $this->_fileHandler) {
47
+ throw new Mage_Exception('Failed to open file ' . $this->_filePath);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Write data to bz archive
53
+ *
54
+ * @throws Mage_Exception
55
+ * @param $data
56
+ */
57
+ protected function _write($data)
58
+ {
59
+ $result = @bzwrite($this->_fileHandler, $data);
60
+
61
+ if (false === $result) {
62
+ throw new Mage_Exception('Failed to write data to ' . $this->_filePath);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Read data from bz archive
68
+ *
69
+ * @throws Mage_Exception
70
+ * @param int $length
71
+ * @return string
72
+ */
73
+ protected function _read($length)
74
+ {
75
+ $data = bzread($this->_fileHandler, $length);
76
+
77
+ if (false === $data) {
78
+ throw new Mage_Exception('Failed to read data from ' . $this->_filePath);
79
+ }
80
+
81
+ return $data;
82
+ }
83
+
84
+ /**
85
+ * Close bz archive
86
+ */
87
+ protected function _close()
88
+ {
89
+ bzclose($this->_fileHandler);
90
+ }
91
+ }
92
+
downloader/lib/Mage/Archive/Helper/File/Gz.php ADDED
@@ -0,0 +1,83 @@
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_Archive
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Helper class that simplifies gz files stream reading and writing
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Archive
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Archive_Helper_File_Gz extends Mage_Archive_Helper_File
35
+ {
36
+ /**
37
+ * @see Mage_Archive_Helper_File::_open()
38
+ */
39
+ protected function _open($mode)
40
+ {
41
+ $this->_fileHandler = @gzopen($this->_filePath, $mode);
42
+
43
+ if (false === $this->_fileHandler) {
44
+ throw new Mage_Exception('Failed to open file ' . $this->_filePath);
45
+ }
46
+ }
47
+
48
+ /**
49
+ * @see Mage_Archive_Helper_File::_write()
50
+ */
51
+ protected function _write($data)
52
+ {
53
+ $result = @gzwrite($this->_fileHandler, $data);
54
+
55
+ if (empty($result) && !empty($data)) {
56
+ throw new Mage_Exception('Failed to write data to ' . $this->_filePath);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * @see Mage_Archive_Helper_File::_read()
62
+ */
63
+ protected function _read($length)
64
+ {
65
+ return gzread($this->_fileHandler, $length);
66
+ }
67
+
68
+ /**
69
+ * @see Mage_Archive_Helper_File::_eof()
70
+ */
71
+ protected function _eof()
72
+ {
73
+ return gzeof($this->_fileHandler);
74
+ }
75
+
76
+ /**
77
+ * @see Mage_Archive_Helper_File::_close()
78
+ */
79
+ protected function _close()
80
+ {
81
+ gzclose($this->_fileHandler);
82
+ }
83
+ }
downloader/lib/Mage/Archive/Interface.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Archive
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
20
*
21
* @category Mage
22
* @package Mage_Archive
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
downloader/lib/Mage/Archive/Tar.php CHANGED
@@ -20,7 +20,7 @@
20
*
21
* @category Mage
22
* @package Mage_Archive
23
- * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
@@ -34,9 +34,11 @@
34
class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Interface
35
{
36
/**
37
- * Constant is used for parse tar's header.
38
*/
39
- const FORMAT_PARSE_HEADER = 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix/a12closer';
40
41
/**
42
* Keep file or directory for packing.
@@ -60,6 +62,122 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
60
*/
61
protected $_skipRoot;
62
63
/**
64
* Set option that define ability skip first catalog level.
65
*
@@ -80,7 +198,19 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
80
*/
81
protected function _setCurrentFile($file)
82
{
83
- $this->_currentFile = $file .((is_dir($file) && substr($file, -1)!=DS)?DS:'');
84
return $this;
85
}
86
@@ -124,6 +254,7 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
124
* Walk through directory and add to tar file or directory.
125
* Result is packed string on TAR format.
126
*
127
* @param boolean $skipRoot
128
* @return string
129
*/
@@ -154,10 +285,74 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
154
return $tarData;
155
}
156
157
/**
158
* Compose header for current file in TAR format.
159
* If length of file's name greater 100 characters,
160
- * method breaks header to two pieces. First conatins
161
* header and data with long name. Second contain only header.
162
*
163
* @param boolean $long
@@ -178,14 +373,16 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
178
}
179
$header = array();
180
$header['100-name'] = $long?'././@LongLink':substr($nameFile, 0, 100);
181
- $header['8-mode'] = $long?' ':str_pad(substr(sprintf("%07o", $infoFile['mode']),-4), 6, '0', STR_PAD_LEFT);
182
$header['8-uid'] = $long || $infoFile['uid']==0?"\0\0\0\0\0\0\0":sprintf("%07o", $infoFile['uid']);
183
$header['8-gid'] = $long || $infoFile['gid']==0?"\0\0\0\0\0\0\0":sprintf("%07o", $infoFile['gid']);
184
- $header['12-size'] = $long?sprintf("%011o", strlen($nameFile)):sprintf("%011o", is_dir($file) ? 0 : filesize($file));
185
$header['12-mtime'] = $long?'00000000000':sprintf("%011o", $infoFile['mtime']);
186
$header['8-check'] = sprintf('% 8s', '');
187
- $header['1-type'] = $long?'L':(is_link($file) ? 2 : is_dir ($file) ? 5 : 0);
188
- $header['100-symlink'] = is_link($file) == 2 ? readlink($item) : '';
189
$header['6-magic'] = 'ustar ';
190
$header['2-version'] = ' ';
191
$a=function_exists('posix_getpwuid')?posix_getpwuid (fileowner($file)):array('name'=>'');
@@ -219,38 +416,63 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
219
*
220
* @param string $destination path to file is unpacked
221
* @return array list of files
222
*/
223
protected function _unpackCurrentTar($destination)
224
{
225
- $file = $this->_getCurrentFile();
226
- $pointer = fopen($file, 'r');
227
- if (empty($pointer)) {
228
- throw new Mage_Exception('Can\'t open file: ' . $file);
229
- }
230
$list = array();
231
- while (!feof($pointer)) {
232
- $header = $this->_parseHeader($pointer);
233
- if ($header) {
234
- $currentFile = $destination . $header['name'];
235
- if ($header['type']=='5' && @mkdir($currentFile, 0777, true)) {
236
- $list[] = $currentFile . DS;
237
- } elseif (in_array($header['type'], array("0",chr(0), ''))) {
238
- $dirname = dirname($currentFile);
239
- if(!file_exists($dirname)) {
240
- @mkdir($dirname, 0777, true);
241
}
242
- $this->_writeFile($currentFile, $header['data']);
243
- $list[] = $currentFile;
244
}
245
}
246
}
247
- fclose($pointer);
248
return $list;
249
}
250
251
/**
252
* Get header from TAR string and unpacked it by format.
253
*
254
* @param resource $pointer
255
* @return string
256
*/
@@ -262,10 +484,9 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
262
return false;
263
}
264
265
- $fmt = self::FORMAT_PARSE_HEADER;
266
$header = unpack ($fmt, $firstLine);
267
268
-
269
$header['mode']=$header['mode']+0;
270
$header['uid']=octdec($header['uid']);
271
$header['gid']=octdec($header['gid']);
@@ -284,7 +505,7 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
284
}
285
286
$isUstar = 'ustar' == strtolower(substr($header['magic'], 0, 5));
287
-
288
$checksumOk = $header['checksum'] == $checksum;
289
if (isset($header['name']) && $checksumOk) {
290
if ($header['name'] == '././@LongLink' && $header['type'] == 'L') {
@@ -304,6 +525,90 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
304
return false;
305
}
306
307
/**
308
* Pack file to TAR (Tape Archiver).
309
*
@@ -312,14 +617,18 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
312
* @param boolean $skipRoot
313
* @return string
314
*/
315
- public function pack($source, $destination, $skipRoot=false)
316
{
317
$this->_setSkipRoot($skipRoot);
318
$source = realpath($source);
319
$tarData = $this->_setCurrentPath($source)
320
- ->_setCurrentFile($source)
321
- ->_packToTar($skipRoot);
322
- $this->_writeFile($destination, $tarData);
323
return $destination;
324
}
325
@@ -332,13 +641,13 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
332
*/
333
public function unpack($source, $destination)
334
{
335
- $tempFile = $destination . DS . '~tmp-'.microtime(true).'.tar';
336
- $data = $this->_readFile($source);
337
- $this->_writeFile($tempFile, $data);
338
- $this->_setCurrentFile($tempFile)
339
- ->_setCurrentPath($tempFile)
340
- ->_unpackCurrentTar($destination);
341
- unlink($tempFile);
342
return $destination;
343
}
344
@@ -352,21 +661,28 @@ class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Int
352
*/
353
public function extract($file, $source, $destination)
354
{
355
- $pointer = fopen($source, 'r');
356
- if (empty($pointer)) {
357
- throw new Mage_Exception('Can\'t open file: '.$source);
358
- }
359
- $list = array();
360
$extractedFile = '';
361
- while (!feof($pointer)) {
362
- $header = $this->_parseHeader($pointer);
363
if ($header['name'] == $file) {
364
$extractedFile = $destination . basename($header['name']);
365
- $this->_writeFile($extractedFile, $header['data']);
366
break;
367
}
368
}
369
- fclose($pointer);
370
return $extractedFile;
371
}
372
}
20
*
21
* @category Mage
22
* @package Mage_Archive
23
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
*/
26
34
class Mage_Archive_Tar extends Mage_Archive_Abstract implements Mage_Archive_Interface
35
{
36
/**
37
+ * Tar block size
38
+ *
39
+ * @const int
40
*/
41
+ const TAR_BLOCK_SIZE = 512;
42
43
/**
44
* Keep file or directory for packing.
62
*/
63
protected $_skipRoot;
64
65
+ /**
66
+ * Tarball data writer
67
+ *
68
+ * @var Mage_Archive_Helper_File
69
+ */
70
+ protected $_writer;
71
+
72
+ /**
73
+ * Tarball data reader
74
+ *
75
+ * @var Mage_Archive_Helper_File
76
+ */
77
+ protected $_reader;
78
+
79
+ /**
80
+ * Path to file where tarball should be placed
81
+ *
82
+ * @var string
83
+ */
84
+ protected $_destinationFilePath;
85
+
86
+ /**
87
+ * Initialize tarball writer
88
+ *
89
+ * @return Mage_Archive_Tar
90
+ */
91
+ protected function _initWriter()
92
+ {
93
+ $this->_writer = new Mage_Archive_Helper_File($this->_destinationFilePath);
94
+ $this->_writer->open('w');
95
+
96
+ return $this;
97
+ }
98
+
99
+ /**
100
+ * Returns string that is used for tar's header parsing
101
+ *
102
+ * @return string
103
+ */
104
+ protected static final function _getFormatParseHeader()
105
+ {
106
+ return 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2version/'
107
+ . 'a32uname/a32gname/a8devmajor/a8devminor/a155prefix/a12closer';
108
+ }
109
+
110
+ /**
111
+ * Destroy tarball writer
112
+ *
113
+ * @return Mage_Archive_Tar
114
+ */
115
+ protected function _destroyWriter()
116
+ {
117
+ if ($this->_writer instanceof Mage_Archive_Helper_File) {
118
+ $this->_writer->close();
119
+ $this->_writer = null;
120
+ }
121
+
122
+ return $this;
123
+ }
124
+
125
+ /**
126
+ * Get tarball writer
127
+ *
128
+ * @return Mage_Archive_Helper_File
129
+ */
130
+ protected function _getWriter()
131
+ {
132
+ if (!$this->_writer) {
133
+ $this->_initWriter();
134
+ }
135
+
136
+ return $this->_writer;
137
+ }
138
+
139
+ /**
140
+ * Initialize tarball reader
141
+ *
142
+ * @return Mage_Archive_Tar
143
+ */
144
+ protected function _initReader()
145
+ {
146
+ $this->_reader = new Mage_Archive_Helper_File($this->_getCurrentFile());
147
+ $this->_reader->open('r');
148
+
149
+ return $this;
150
+ }
151
+
152
+ /**
153
+ * Destroy tarball reader
154
+ *
155
+ * @return Mage_Archive_Tar
156
+ */
157
+ protected function _destroyReader()
158
+ {
159
+ if ($this->_reader instanceof Mage_Archive_Helper_File) {
160
+ $this->_reader->close();
161
+ $this->_reader = null;
162
+ }
163
+
164
+ return $this;
165
+ }
166
+
167
+ /**
168
+ * Get tarball reader
169
+ *
170
+ * @return Mage_Archive_Helper_File
171
+ */
172
+ protected function _getReader()
173
+ {
174
+ if (!$this->_reader) {
175
+ $this->_initReader();
176
+ }
177
+
178
+ return $this->_reader;
179
+ }
180
+
181
/**
182
* Set option that define ability skip first catalog level.
183
*
198
*/
199
protected function _setCurrentFile($file)
200
{
201
+ $this->_currentFile = $file .((!is_link($file) && is_dir($file) && substr($file, -1) != DS) ? DS : '');
202
+ return $this;
203
+ }
204
+
205
+ /**
206
+ * Set path to file where tarball should be placed
207
+ *
208
+ * @param string $destinationFilePath
209
+ * @return Mage_Archive_Tar
210
+ */
211
+ protected function _setDestinationFilePath($destinationFilePath)
212
+ {
213
+ $this->_destinationFilePath = $destinationFilePath;
214
return $this;
215
}
216
254
* Walk through directory and add to tar file or directory.
255
* Result is packed string on TAR format.
256
*
257
+ * @deprecated after 1.7.0.0
258
* @param boolean $skipRoot
259
* @return string
260
*/
285
return $tarData;
286
}
287
288
+ /**
289
+ * Recursively walk through file tree and create tarball
290
+ *
291
+ * @param boolean $skipRoot
292
+ * @param boolean $finalize
293
+ * @throws Mage_Exception
294
+ */
295
+ protected function _createTar($skipRoot = false, $finalize = false)
296
+ {
297
+ if (!$skipRoot) {
298
+ $this->_packAndWriteCurrentFile();
299
+ }
300
+
301
+ $file = $this->_getCurrentFile();
302
+
303
+ if (is_dir($file)) {
304
+ $dirFiles = scandir($file);
305
+
306
+ if (false === $dirFiles) {
307
+ throw new Mage_Exception('Can\'t scan dir: ' . $file);
308
+ }
309
+
310
+ array_shift($dirFiles); /* remove './'*/
311
+ array_shift($dirFiles); /* remove '../'*/
312
+
313
+ foreach ($dirFiles as $item) {
314
+ $this->_setCurrentFile($file . $item)->_createTar();
315
+ }
316
+ }
317
+
318
+ if ($finalize) {
319
+ $this->_getWriter()->write(str_repeat("\0", self::TAR_BLOCK_SIZE * 12));
320
+ }
321
+ }
322
+
323
+ /**
324
+ * Write current file to tarball
325
+ */
326
+ protected function _packAndWriteCurrentFile()
327
+ {
328
+ $archiveWriter = $this->_getWriter();
329
+ $archiveWriter->write($this->_composeHeader());
330
+
331
+ $currentFile = $this->_getCurrentFile();
332
+
333
+ $fileSize = 0;
334
+
335
+ if (is_file($currentFile) && !is_link($currentFile)) {
336
+ $fileReader = new Mage_Archive_Helper_File($currentFile);
337
+ $fileReader->open('r');
338
+
339
+ while (!$fileReader->eof()) {
340
+ $archiveWriter->write($fileReader->read());
341
+ }
342
+
343
+ $fileReader->close();
344
+
345
+ $fileSize = filesize($currentFile);
346
+ }
347
+
348
+ $appendZerosCount = (self::TAR_BLOCK_SIZE - $fileSize % self::TAR_BLOCK_SIZE) % self::TAR_BLOCK_SIZE;
349
+ $archiveWriter->write(str_repeat("\0", $appendZerosCount));
350
+ }
351
+
352
/**
353
* Compose header for current file in TAR format.
354
* If length of file's name greater 100 characters,
355
+ * method breaks header into two pieces. First contains
356
* header and data with long name. Second contain only header.
357
*
358
* @param boolean $long
373
}
374
$header = array();
375
$header['100-name'] = $long?'././@LongLink':substr($nameFile, 0, 100);
376
+ $header['8-mode'] = $long ? ' '
377
+ : str_pad(substr(sprintf("%07o", $infoFile['mode']),-4), 6, '0', STR_PAD_LEFT);
378
$header['8-uid'] = $long || $infoFile['uid']==0?"\0\0\0\0\0\0\0":sprintf("%07o", $infoFile['uid']);
379
$header['8-gid'] = $long || $infoFile['gid']==0?"\0\0\0\0\0\0\0":sprintf("%07o", $infoFile['gid']);
380
+ $header['12-size'] = $long ? sprintf("%011o", strlen($nameFile)) : sprintf("%011o", is_dir($file)
381
+ ? 0 : filesize($file));
382
$header['12-mtime'] = $long?'00000000000':sprintf("%011o", $infoFile['mtime']);
383
$header['8-check'] = sprintf('% 8s', '');
384
+ $header['1-type'] = $long ? 'L' : (is_link($file) ? 2 : (is_dir($file) ? 5 : 0));
385
+ $header['100-symlink'] = is_link($file) ? readlink($file) : '';
386
$header['6-magic'] = 'ustar ';
387
$header['2-version'] = ' ';
388
$a=function_exists('posix_getpwuid')?posix_getpwuid (fileowner($file)):array('name'=>'');
416
*
417
* @param string $destination path to file is unpacked
418
* @return array list of files
419
+ * @throws Mage_Exception
420
*/
421
protected function _unpackCurrentTar($destination)
422
{
423
+ $archiveReader = $this->_getReader();
424
$list = array();
425
+
426
+ while (!$archiveReader->eof()) {
427
+ $header = $this->_extractFileHeader();
428
+
429
+ if (!$header) {
430
+ continue;
431
+ }
432
+