Version Notes
1.7.0.0
Download this release
Release Info
Developer | Magento Core Team |
Extension | Lib_Mage |
Version | 1.7.0.0 |
Comparing to | |
See all releases |
Code changes from version 1.6.1.0 to 1.7.0.0
- lib/Mage/Archive.php +5 -6
- lib/Mage/Archive/Abstract.php +8 -5
- lib/Mage/Archive/Bz.php +26 -16
- lib/Mage/Archive/Gz.php +26 -16
- lib/Mage/Archive/Helper/File.php +274 -0
- lib/Mage/Archive/Helper/File/Bz.php +92 -0
- lib/Mage/Archive/Helper/File/Gz.php +83 -0
- lib/Mage/Archive/Interface.php +2 -2
- lib/Mage/Archive/Tar.php +366 -50
- lib/Mage/Backup.php +59 -0
- lib/Mage/Backup/Abstract.php +318 -0
- lib/Mage/Backup/Archive/Tar.php +82 -0
- lib/Mage/Backup/Db.php +119 -0
- lib/Mage/Backup/Exception.php +36 -0
- lib/Mage/Backup/Exception/CantLoadSnapshot.php +36 -0
- lib/Mage/Backup/Exception/FtpConnectionFailed.php +36 -0
- lib/Mage/Backup/Exception/FtpValidationFailed.php +36 -0
- lib/Mage/Backup/Exception/NotEnoughFreeSpace.php +36 -0
- lib/Mage/Backup/Exception/NotEnoughPermissions.php +36 -0
- lib/Mage/Backup/Filesystem.php +284 -0
- lib/Mage/Backup/Filesystem/Helper.php +137 -0
- lib/Mage/Backup/Filesystem/Iterator/File.php +112 -0
- lib/Mage/Backup/Filesystem/Iterator/Filter.php +77 -0
- lib/Mage/Backup/Filesystem/Rollback/Abstract.php +57 -0
- lib/Mage/Backup/Filesystem/Rollback/Fs.php +78 -0
- lib/Mage/Backup/Filesystem/Rollback/Ftp.php +198 -0
- lib/Mage/Backup/Interface.php +88 -0
- lib/Mage/Backup/Media.php +99 -0
- lib/Mage/Backup/Nomedia.php +82 -0
- lib/Mage/Backup/Snapshot.php +140 -0
- lib/Mage/Connect/Ftp.php +2 -460
- lib/Mage/Connect/Packager.php +33 -29
- lib/Mage/Exception.php +3 -2
- lib/Mage/System/Args.php +4 -4
- lib/Mage/System/Dirs.php +1 -1
- lib/Mage/System/Ftp.php +509 -0
- package.xml +5 -5
lib/Mage/Archive.php
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
-
* @copyright Copyright (c)
|
24 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
*/
|
26 |
|
@@ -143,7 +143,8 @@ class Mage_Archive
|
|
143 |
*
|
144 |
* @param string $source
|
145 |
* @param string $destination
|
146 |
-
* @param
|
|
|
147 |
* @return string Path to file
|
148 |
*/
|
149 |
public function unpack($source, $destination='.', $tillTar=false, $clearInterm = true)
|
@@ -160,9 +161,7 @@ class Mage_Archive
|
|
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 +217,5 @@ class Mage_Archive
|
|
218 |
}
|
219 |
return false;
|
220 |
}
|
|
|
221 |
|
222 |
-
}
|
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 |
|
143 |
*
|
144 |
* @param string $source
|
145 |
* @param string $destination
|
146 |
+
* @param bool $tillTar
|
147 |
+
* @param bool $clearInterm
|
148 |
* @return string Path to file
|
149 |
*/
|
150 |
public function unpack($source, $destination='.', $tillTar=false, $clearInterm = true)
|
161 |
$packed = rtrim($destination, DS) . DS . '~tmp-'. microtime(true) . $archivers[$i-1] . '.' . $archivers[$i-1];
|
162 |
}
|
163 |
$source = $this->_getArchiver($archivers[$i])->unpack($source, $packed);
|
164 |
+
|
|
|
|
|
165 |
if ($clearInterm && $interimSource && $i >= 0) {
|
166 |
unlink($interimSource);
|
167 |
}
|
217 |
}
|
218 |
return false;
|
219 |
}
|
220 |
+
}
|
221 |
|
|
lib/Mage/Archive/Abstract.php
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
-
* @copyright Copyright (c)
|
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 |
-
* @
|
|
|
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) 2010 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 |
+
}
|
|
lib/Mage/Archive/Bz.php
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
-
* @copyright Copyright (c)
|
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 |
-
$
|
47 |
-
$
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
return $destination;
|
50 |
}
|
51 |
|
@@ -58,22 +68,22 @@ 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 |
-
|
75 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
return $destination;
|
77 |
}
|
78 |
|
79 |
-
}
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
+
* @copyright Copyright (c) 2010 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 |
|
89 |
+
}
|
lib/Mage/Archive/Gz.php
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
-
* @copyright Copyright (c)
|
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 |
-
$
|
46 |
-
$
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
return $destination;
|
75 |
}
|
76 |
-
|
77 |
-
}
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
+
* @copyright Copyright (c) 2010 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 |
+
}
|
|
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) 2010 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 |
+
}
|
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) 2010 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 |
+
|
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) 2010 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 |
+
}
|
lib/Mage/Archive/Interface.php
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
-
* @copyright Copyright (c)
|
24 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
*/
|
26 |
|
@@ -50,4 +50,4 @@ interface Mage_Archive_Interface
|
|
50 |
* @return string
|
51 |
*/
|
52 |
public function unpack($source, $destination);
|
53 |
-
}
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
+
* @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
|
24 |
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
*/
|
26 |
|
50 |
* @return string
|
51 |
*/
|
52 |
public function unpack($source, $destination);
|
53 |
+
}
|
lib/Mage/Archive/Tar.php
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
-
* @copyright Copyright (c)
|
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 |
-
*
|
|
|
|
|
38 |
*/
|
39 |
-
const
|
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
|
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?' '
|
|
|
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)
|
|
|
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
|
188 |
-
$header['100-symlink'] = is_link($file)
|
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 |
-
$
|
226 |
-
$pointer = fopen($file, 'r');
|
227 |
-
if (empty($pointer)) {
|
228 |
-
throw new Mage_Exception('Can\'t open file: ' . $file);
|
229 |
-
}
|
230 |
$list = array();
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
}
|
242 |
-
|
243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
}
|
245 |
}
|
246 |
}
|
247 |
-
|
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::
|
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 |
-
|
321 |
-
|
322 |
-
|
|
|
|
|
|
|
|
|
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 |
-
$
|
336 |
-
|
337 |
-
|
338 |
-
$this->
|
339 |
-
->
|
340 |
-
->
|
341 |
-
|
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 |
-
$
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
$list = array();
|
360 |
$extractedFile = '';
|
361 |
-
|
362 |
-
|
|
|
363 |
if ($header['name'] == $file) {
|
364 |
$extractedFile = $destination . basename($header['name']);
|
365 |
-
$this->
|
366 |
break;
|
367 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
368 |
}
|
369 |
-
|
|
|
370 |
return $extractedFile;
|
371 |
}
|
372 |
}
|
20 |
*
|
21 |
* @category Mage
|
22 |
* @package Mage_Archive
|
23 |
+
* @copyright Copyright (c) 2010 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 |
+
|
433 |
+
$currentFile = $destination . $header['name'];
|
434 |
+
$dirname = dirname($currentFile);
|
435 |
+
|
436 |
+
if (in_array($header['type'], array("0",chr(0), ''))) {
|
437 |
+
|
438 |
+
if(!file_exists($dirname)) {
|
439 |
+
$mkdirResult = @mkdir($dirname, 0777, true);
|
440 |
+
|
441 |
+
if (false === $mkdirResult) {
|
442 |
+
throw new Mage_Exception('Failed to create directory ' . $dirname);
|
443 |
}
|
444 |
+
}
|
445 |
+
|
446 |
+
$this->_extractAndWriteFile($header, $currentFile);
|
447 |
+
$list[] = $currentFile;
|
448 |
+
|
449 |
+
} elseif ($header['type'] == '5') {
|
450 |
+
|
451 |
+
if(!file_exists($dirname)) {
|
452 |
+
$mkdirResult = @mkdir($currentFile, $header['mode'], true);
|
453 |
+
|
454 |
+
if (false === $mkdirResult) {
|
455 |
+
throw new Mage_Exception('Failed to create directory ' . $currentFile);
|
456 |
+
}
|
457 |
+
}
|
458 |
+
$list[] = $currentFile . DS;
|
459 |
+
} elseif ($header['type'] == '2') {
|
460 |
+
|
461 |
+
$symlinkResult = @symlink($header['symlink'], $currentFile);
|
462 |
+
|
463 |
+
if (false === $symlinkResult) {
|
464 |
+
throw new Mage_Exception('Failed to create symlink ' . $currentFile . ' to ' . $header['symlink']);
|
465 |
}
|
466 |
}
|
467 |
}
|
468 |
+
|
469 |
return $list;
|
470 |
}
|
471 |
|
472 |
/**
|
473 |
* Get header from TAR string and unpacked it by format.
|
474 |
*
|
475 |
+
* @deprecated after 1.7.0.0
|
476 |
* @param resource $pointer
|
477 |
* @return string
|
478 |
*/
|
484 |
return false;
|
485 |
}
|
486 |
|
487 |
+
$fmt = self::_getFormatParseHeader();
|
488 |
$header = unpack ($fmt, $firstLine);
|
489 |
|
|
|
490 |
$header['mode']=$header['mode']+0;
|
491 |
$header['uid']=octdec($header['uid']);
|
492 |
$header['gid']=octdec($header['gid']);
|
505 |
}
|
506 |
|
507 |
$isUstar = 'ustar' == strtolower(substr($header['magic'], 0, 5));
|
508 |
+
|
509 |
$checksumOk = $header['checksum'] == $checksum;
|
510 |
if (isset($header['name']) && $checksumOk) {
|
511 |
if ($header['name'] == '././@LongLink' && $header['type'] == 'L') {
|
525 |
return false;
|
526 |
}
|
527 |
|
528 |
+
/**
|
529 |
+
* Read and decode file header information from tarball
|
530 |
+
*
|
531 |
+
* @return array|boolean
|
532 |
+
*/
|
533 |
+
protected function _extractFileHeader()
|
534 |
+
{
|
535 |
+
$archiveReader = $this->_getReader();
|
536 |
+
|
537 |
+
$headerBlock = $archiveReader->read(self::TAR_BLOCK_SIZE);
|
538 |
+
|
539 |
+
if (strlen($headerBlock) < self::TAR_BLOCK_SIZE) {
|
540 |
+
return false;
|
541 |
+
}
|
542 |
+
|
543 |
+
$header = unpack(self::_getFormatParseHeader(), $headerBlock);
|
544 |
+
|
545 |
+
$header['mode'] = octdec($header['mode']);
|
546 |
+
$header['uid'] = octdec($header['uid']);
|
547 |
+
$header['gid'] = octdec($header['gid']);
|
548 |
+
$header['size'] = octdec($header['size']);
|
549 |
+
$header['mtime'] = octdec($header['mtime']);
|
550 |
+
$header['checksum'] = octdec($header['checksum']);
|
551 |
+
|
552 |
+
if ($header['type'] == "5") {
|
553 |
+
$header['size'] = 0;
|
554 |
+
}
|
555 |
+
|
556 |
+
$checksum = 0;
|
557 |
+
$headerBlock = substr_replace($headerBlock, ' ', 148, 8);
|
558 |
+
|
559 |
+
for ($i = 0; $i < 512; $i++) {
|
560 |
+
$checksum += ord(substr($headerBlock, $i, 1));
|
561 |
+
}
|
562 |
+
|
563 |
+
$isUstar = 'ustar' == strtolower(substr($header['magic'], 0, 5));
|
564 |
+
|
565 |
+
$checksumOk = $header['checksum'] == $checksum;
|
566 |
+
if (isset($header['name']) && $checksumOk) {
|
567 |
+
|
568 |
+
if (!($header['name'] == '././@LongLink' && $header['type'] == 'L')) {
|
569 |
+
return $header;
|
570 |
+
}
|
571 |
+
|
572 |
+
$realNameBlockSize = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
|
573 |
+
* self::TAR_BLOCK_SIZE;
|
574 |
+
$realNameBlock = $archiveReader->read($realNameBlockSize);
|
575 |
+
$realName = substr($realNameBlock, 0, $header['size']);
|
576 |
+
|
577 |
+
$headerMain = $this->_extractFileHeader();
|
578 |
+
$headerMain['name'] = $realName;
|
579 |
+
return $headerMain;
|
580 |
+
}
|
581 |
+
|
582 |
+
return false;
|
583 |
+
}
|
584 |
+
|
585 |
+
/**
|
586 |
+
* Extract next file from tarball by its $header information and save it to $destination
|
587 |
+
*
|
588 |
+
* @param array $fileHeader
|
589 |
+
* @param string $destination
|
590 |
+
*/
|
591 |
+
protected function _extractAndWriteFile($fileHeader, $destination)
|
592 |
+
{
|
593 |
+
$fileWriter = new Mage_Archive_Helper_File($destination);
|
594 |
+
$fileWriter->open('w', $fileHeader['mode']);
|
595 |
+
|
596 |
+
$archiveReader = $this->_getReader();
|
597 |
+
|
598 |
+
$filesize = $fileHeader['size'];
|
599 |
+
$bytesExtracted = 0;
|
600 |
+
|
601 |
+
while ($filesize > $bytesExtracted && !$archiveReader->eof()) {
|
602 |
+
$block = $archiveReader->read(self::TAR_BLOCK_SIZE);
|
603 |
+
$nonExtractedBytesCount = $filesize - $bytesExtracted;
|
604 |
+
|
605 |
+
$data = substr($block, 0, $nonExtractedBytesCount);
|
606 |
+
$fileWriter->write($data);
|
607 |
+
|
608 |
+
$bytesExtracted += strlen($block);
|
609 |
+
}
|
610 |
+
}
|
611 |
+
|
612 |
/**
|
613 |
* Pack file to TAR (Tape Archiver).
|
614 |
*
|
617 |
* @param boolean $skipRoot
|
618 |
* @return string
|
619 |
*/
|
620 |
+
public function pack($source, $destination, $skipRoot = false)
|
621 |
{
|
622 |
$this->_setSkipRoot($skipRoot);
|
623 |
$source = realpath($source);
|
624 |
$tarData = $this->_setCurrentPath($source)
|
625 |
+
->_setDestinationFilePath($destination)
|
626 |
+
->_setCurrentFile($source);
|
627 |
+
|
628 |
+
$this->_initWriter();
|
629 |
+
$this->_createTar($skipRoot, true);
|
630 |
+
$this->_destroyWriter();
|
631 |
+
|
632 |
return $destination;
|
633 |
}
|
634 |
|
641 |
*/
|
642 |
public function unpack($source, $destination)
|
643 |
{
|
644 |
+
$this->_setCurrentFile($source)
|
645 |
+
->_setCurrentPath($source);
|
646 |
+
|
647 |
+
$this->_initReader();
|
648 |
+
$this->_unpackCurrentTar($destination);
|
649 |
+
$this->_destroyReader();
|
650 |
+
|
651 |
return $destination;
|
652 |
}
|
653 |
|
661 |
*/
|
662 |
public function extract($file, $source, $destination)
|
663 |
{
|
664 |
+
$this->_setCurrentFile($source);
|
665 |
+
$this->_initReader();
|
666 |
+
|
667 |
+
$archiveReader = $this->_getReader();
|
|
|
668 |
$extractedFile = '';
|
669 |
+
|
670 |
+
while (!$archiveReader->eof()) {
|
671 |
+
$header = $this->_extractFileHeader();
|
672 |
if ($header['name'] == $file) {
|
673 |
$extractedFile = $destination . basename($header['name']);
|
674 |
+
$this->_extractAndWriteFile($header, $extractedFile);
|
675 |
break;
|
676 |
}
|
677 |
+
|
678 |
+
if ($header['type'] != 5){
|
679 |
+
$skipBytes = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
|
680 |
+
* self::TAR_BLOCK_SIZE;
|
681 |
+
$archiveReader->read($skipBytes);
|
682 |
+
}
|
683 |
}
|
684 |
+
|
685 |
+
$this->_destroyReader();
|
686 |
return $extractedFile;
|
687 |
}
|
688 |
}
|
lib/Mage/Backup.php
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_Backup
|
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 |
+
|
27 |
+
/**
|
28 |
+
* Class to work with backups
|
29 |
+
*
|
30 |
+
* @category Mage
|
31 |
+
* @package Mage_Backup
|
32 |
+
* @author Magento Core Team <core@magentocommerce.com>
|
33 |
+
*/
|
34 |
+
class Mage_Backup
|
35 |
+
{
|
36 |
+
/**
|
37 |
+
* List of supported a backup types
|
38 |
+
*
|
39 |
+
* @var array
|
40 |
+
*/
|
41 |
+
static protected $_allowedBackupTypes = array('db', 'snapshot', 'filesystem', 'media', 'nomedia');
|
42 |
+
|
43 |
+
/**
|
44 |
+
* get Backup Instance By File Name
|
45 |
+
*
|
46 |
+
* @param string $type
|
47 |
+
* @return Mage_Backup_Interface
|
48 |
+
*/
|
49 |
+
static public function getBackupInstance($type)
|
50 |
+
{
|
51 |
+
$class = 'Mage_Backup_' . ucfirst($type);
|
52 |
+
|
53 |
+
if (!in_array($type, self::$_allowedBackupTypes) || !class_exists($class, true)){
|
54 |
+
throw new Mage_Exception('Current implementation not supported this type (' . $type . ') of backup.');
|
55 |
+
}
|
56 |
+
|
57 |
+
return new $class();
|
58 |
+
}
|
59 |
+
}
|
lib/Mage/Backup/Abstract.php
ADDED
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|