Lib_Mage - Version 1.6.0.0

Version Notes

1.6.0.0

Download this release

Release Info

Developer Magento Core Team
Extension Lib_Mage
Version 1.6.0.0
Comparing to
See all releases


Version 1.6.0.0

Files changed (64) hide show
  1. lib/Mage/Archive.php +222 -0
  2. lib/Mage/Archive/Abstract.php +84 -0
  3. lib/Mage/Archive/Bz.php +79 -0
  4. lib/Mage/Archive/Gz.php +77 -0
  5. lib/Mage/Archive/Interface.php +53 -0
  6. lib/Mage/Archive/Tar.php +372 -0
  7. lib/Mage/Autoload/Simple.php +52 -0
  8. lib/Mage/Connect/Channel/Generator.php +63 -0
  9. lib/Mage/Connect/Channel/Parser.php +25 -0
  10. lib/Mage/Connect/Channel/VO.php +113 -0
  11. lib/Mage/Connect/Command.php +390 -0
  12. lib/Mage/Connect/Command/Channels.php +189 -0
  13. lib/Mage/Connect/Command/Channels_Header.php +105 -0
  14. lib/Mage/Connect/Command/Config.php +211 -0
  15. lib/Mage/Connect/Command/Config_Header.php +100 -0
  16. lib/Mage/Connect/Command/Install.php +448 -0
  17. lib/Mage/Connect/Command/Install_Header.php +237 -0
  18. lib/Mage/Connect/Command/Package.php +134 -0
  19. lib/Mage/Connect/Command/Package_Header.php +67 -0
  20. lib/Mage/Connect/Command/Registry.php +175 -0
  21. lib/Mage/Connect/Command/Registry_Header.php +68 -0
  22. lib/Mage/Connect/Command/Remote.php +226 -0
  23. lib/Mage/Connect/Command/Remote_Header.php +88 -0
  24. lib/Mage/Connect/Config.php +265 -0
  25. lib/Mage/Connect/Converter.php +337 -0
  26. lib/Mage/Connect/Frontend.php +251 -0
  27. lib/Mage/Connect/Frontend/CLI.php +441 -0
  28. lib/Mage/Connect/Ftp.php +494 -0
  29. lib/Mage/Connect/Loader.php +51 -0
  30. lib/Mage/Connect/Loader/Ftp.php +121 -0
  31. lib/Mage/Connect/Package.php +1486 -0
  32. lib/Mage/Connect/Package/Extension.php +1 -0
  33. lib/Mage/Connect/Package/Hotfix.php +137 -0
  34. lib/Mage/Connect/Package/Maintainer.php +0 -0
  35. lib/Mage/Connect/Package/Reader.php +150 -0
  36. lib/Mage/Connect/Package/Target.php +126 -0
  37. lib/Mage/Connect/Package/VO.php +96 -0
  38. lib/Mage/Connect/Package/Writer.php +209 -0
  39. lib/Mage/Connect/Packager.php +662 -0
  40. lib/Mage/Connect/Repository.php +0 -0
  41. lib/Mage/Connect/Repository/Abstract.php +0 -0
  42. lib/Mage/Connect/Repository/Channel.php +0 -0
  43. lib/Mage/Connect/Repository/Channel/Abstract.php +0 -0
  44. lib/Mage/Connect/Repository/Channel/Commercial.php +0 -0
  45. lib/Mage/Connect/Repository/Channel/Community.php +0 -0
  46. lib/Mage/Connect/Repository/Channel/Core.php +0 -0
  47. lib/Mage/Connect/Repository/Local.php +0 -0
  48. lib/Mage/Connect/Rest.php +364 -0
  49. lib/Mage/Connect/Singleconfig.php +865 -0
  50. lib/Mage/Connect/Structures/Graph.php +248 -0
  51. lib/Mage/Connect/Structures/Node.php +257 -0
  52. lib/Mage/Connect/Validator.php +417 -0
  53. lib/Mage/DB/Exception.php +36 -0
  54. lib/Mage/DB/Mysqli.php +532 -0
  55. lib/Mage/Exception.php +35 -0
  56. lib/Mage/HTTP/Client.php +84 -0
  57. lib/Mage/HTTP/Client/Curl.php +499 -0
  58. lib/Mage/HTTP/Client/Socket.php +537 -0
  59. lib/Mage/HTTP/IClient.php +145 -0
  60. lib/Mage/System/Args.php +102 -0
  61. lib/Mage/System/Dirs.php +82 -0
  62. lib/Mage/Xml/Generator.php +90 -0
  63. lib/Mage/Xml/Parser.php +91 -0
  64. package.xml +18 -0
lib/Mage/Archive.php ADDED
@@ -0,0 +1,222 @@
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) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Class to work with archives
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Archive
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Archive
35
+ {
36
+
37
+ /**
38
+ * Archiver is used for compress.
39
+ */
40
+ const DEFAULT_ARCHIVER = 'gz';
41
+
42
+ /**
43
+ * Default packer for directory.
44
+ */
45
+ const TAPE_ARCHIVER = 'tar';
46
+
47
+ /**
48
+ * Current archiver is used for compress.
49
+ *
50
+ * @var Mage_Archiver_Tar|Mage_Archiver_Gz|Mage_Archiver_Bz
51
+ */
52
+ protected $_archiver=null;
53
+
54
+ /**
55
+ * Accessible formats for compress.
56
+ *
57
+ * @var array
58
+ */
59
+ protected $_formats = array(
60
+ 'tar' => 'tar',
61
+ 'gz' => 'gz',
62
+ 'gzip' => 'gz',
63
+ 'tgz' => 'tar.gz',
64
+ 'tgzip' => 'tar.gz',
65
+ 'bz' => 'bz',
66
+ 'bzip' => 'bz',
67
+ 'bzip2' => 'bz',
68
+ 'bz2' => 'bz',
69
+ 'tbz' => 'tar.bz',
70
+ 'tbzip' => 'tar.bz',
71
+ 'tbz2' => 'tar.bz',
72
+ 'tbzip2' => 'tar.bz');
73
+
74
+ /**
75
+ * Create object of current archiver by $extension.
76
+ *
77
+ * @param string $extension
78
+ * @return Mage_Archiver_Tar|Mage_Archiver_Gz|Mage_Archiver_Bz
79
+ */
80
+ protected function _getArchiver($extension)
81
+ {
82
+ if(array_key_exists(strtolower($extension), $this->_formats)) {
83
+ $format = $this->_formats[$extension];
84
+ } else {
85
+ $format = self::DEFAULT_ARCHIVER;
86
+ }
87
+ $class = 'Mage_Archive_'.ucfirst($format);
88
+ $this->_archiver = new $class();
89
+ return $this->_archiver;
90
+ }
91
+
92
+ /**
93
+ * Split current format to list of archivers.
94
+ *
95
+ * @param string $source
96
+ * @return array
97
+ */
98
+ protected function _getArchivers($source)
99
+ {
100
+ $ext = pathinfo($source, PATHINFO_EXTENSION);
101
+ if(!isset($this->_formats[$ext])) {
102
+ return array();
103
+ }
104
+ $format = $this->_formats[$ext];
105
+ if ($format) {
106
+ $archivers = explode('.', $format);
107
+ return $archivers;
108
+ }
109
+ return array();
110
+ }
111
+
112
+ /**
113
+ * Pack file or directory to archivers are parsed from extension.
114
+ *
115
+ * @param string $source
116
+ * @param string $destination
117
+ * @param boolean $skipRoot skip first level parent
118
+ * @return string Path to file
119
+ */
120
+ public function pack($source, $destination='packed.tgz', $skipRoot=false)
121
+ {
122
+ $archivers = $this->_getArchivers($destination);
123
+ $interimSource = '';
124
+ for ($i=0; $i<count($archivers); $i++ ) {
125
+ if ($i == (count($archivers) - 1)) {
126
+ $packed = $destination;
127
+ } else {
128
+ $packed = dirname($destination) . DS . '~tmp-'. microtime(true) . $archivers[$i] . '.' . $archivers[$i];
129
+ }
130
+ $source = $this->_getArchiver($archivers[$i])->pack($source, $packed, $skipRoot);
131
+ if ($interimSource && $i < count($archivers)) {
132
+ unlink($interimSource);
133
+ }
134
+ $interimSource = $source;
135
+ }
136
+ return $source;
137
+ }
138
+
139
+ /**
140
+ * Unpack file from archivers are parsed from extension.
141
+ * If $tillTar == true unpack file from archivers till
142
+ * meet TAR archiver.
143
+ *
144
+ * @param string $source
145
+ * @param string $destination
146
+ * @param boolean $tillTar
147
+ * @return string Path to file
148
+ */
149
+ public function unpack($source, $destination='.', $tillTar=false, $clearInterm = true)
150
+ {
151
+ $archivers = $this->_getArchivers($source);
152
+ $interimSource = '';
153
+ for ($i=count($archivers)-1; $i>=0; $i--) {
154
+ if ($tillTar && $archivers[$i] == self::TAPE_ARCHIVER) {
155
+ break;
156
+ }
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
+ }
169
+ $interimSource = $source;
170
+ }
171
+ return $source;
172
+ }
173
+
174
+ /**
175
+ * Extract one file from TAR (Tape Archiver).
176
+ *
177
+ * @param string $file
178
+ * @param string $source
179
+ * @param string $destination
180
+ * @return string Path to file
181
+ */
182
+ public function extract($file, $source, $destination='.')
183
+ {
184
+ $tarFile = $this->unpack($source, $destination, true);
185
+ $resFile = $this->_getArchiver(self::TAPE_ARCHIVER)->extract($file, $tarFile, $destination);
186
+ if (!$this->isTar($source)) {
187
+ unlink($tarFile);
188
+ }
189
+ return $resFile;
190
+ }
191
+
192
+ /**
193
+ * Check file is archive.
194
+ *
195
+ * @param string $file
196
+ * @return boolean
197
+ */
198
+ public function isArchive($file)
199
+ {
200
+ $archivers = $this->_getArchivers($file);
201
+ if (count($archivers)) {
202
+ return true;
203
+ }
204
+ return false;
205
+ }
206
+
207
+ /**
208
+ * Check file is TAR.
209
+ *
210
+ * @param mixed $file
211
+ * @return boolean
212
+ */
213
+ public function isTar($file)
214
+ {
215
+ $archivers = $this->_getArchivers($file);
216
+ if (count($archivers)==1 && $archivers[0] == self::TAPE_ARCHIVER) {
217
+ return true;
218
+ }
219
+ return false;
220
+ }
221
+
222
+ }
lib/Mage/Archive/Abstract.php ADDED
@@ -0,0 +1,84 @@
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) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Class to work with archives
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Archive
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
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
+ }
48
+ return true;
49
+ }
50
+
51
+ /**
52
+ * Read data from file. If file can't be opened, throw to exception.
53
+ *
54
+ * @param string $source
55
+ * @return string
56
+ */
57
+ protected function _readFile($source)
58
+ {
59
+ $data = '';
60
+ if (is_file($source) && is_readable($source)) {
61
+ $data = @file_get_contents($source);
62
+ if ($data === false) {
63
+ throw new Mage_Exception("Can't get contents from: " . $source);
64
+ }
65
+ }
66
+ return $data;
67
+ }
68
+
69
+ /**
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
+ {
77
+ $file = str_replace(dirname($source) . DS, '', $source);
78
+ if (!$withExtension) {
79
+ $file = substr($file, 0, strrpos($file, '.'));
80
+ }
81
+ return $file;
82
+ }
83
+
84
+ }
lib/Mage/Archive/Bz.php ADDED
@@ -0,0 +1,79 @@
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) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Class to work with bzip2 archives
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Archive
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Archive_Bz extends Mage_Archive_Abstract implements Mage_Archive_Interface
35
+ {
36
+
37
+ /**
38
+ * Pack file by BZIP2 compressor.
39
+ *
40
+ * @param string $source
41
+ * @param string $destination
42
+ * @return string
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
+
52
+ /**
53
+ * Unpack file by BZIP2 compressor.
54
+ *
55
+ * @param string $source
56
+ * @param string $destination
57
+ * @return string
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
+
79
+ }
lib/Mage/Archive/Gz.php ADDED
@@ -0,0 +1,77 @@
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) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Class to work with gz archives
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Archive
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ class Mage_Archive_Gz extends Mage_Archive_Abstract implements Mage_Archive_Interface
35
+ {
36
+ /**
37
+ * Pack file by GZ compressor.
38
+ *
39
+ * @param string $source
40
+ * @param string $destination
41
+ * @return string
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
+
51
+ /**
52
+ * Unpack file by GZ compressor.
53
+ *
54
+ * @param string $source
55
+ * @param string $destination
56
+ * @return string
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
+ }
lib/Mage/Archive/Interface.php ADDED
@@ -0,0 +1,53 @@
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) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Interface for work with archives
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Archive
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
34
+ interface Mage_Archive_Interface
35
+ {
36
+ /**
37
+ * Pack file or directory.
38
+ *
39
+ * @param string $source
40
+ * @param string $destination
41
+ * @return string
42
+ */
43
+ public function pack($source, $destination);
44
+
45
+ /**
46
+ * Unpack file or directory.
47
+ *
48
+ * @param string $source
49
+ * @param string $destination
50
+ * @return string
51
+ */
52
+ public function unpack($source, $destination);
53
+ }
lib/Mage/Archive/Tar.php ADDED
@@ -0,0 +1,372 @@
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) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Class to work with tar archives
29
+ *
30
+ * @category Mage
31
+ * @package Mage_Archive
32
+ * @author Magento Core Team <core@magentocommerce.com>
33
+ */
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.
43
+ *
44
+ * @var string
45
+ */
46
+ protected $_currentFile;
47
+
48
+ /**
49
+ * Keep path to file or directory for packing.
50
+ *
51
+ * @var mixed
52
+ */
53
+ protected $_currentPath;
54
+
55
+ /**
56
+ * Skip first level parent directory. Example:
57
+ * use test/fip.php instead test/test/fip.php;
58
+ *
59
+ * @var mixed
60
+ */
61
+ protected $_skipRoot;
62
+
63
+ /**
64
+ * Set option that define ability skip first catalog level.
65
+ *
66
+ * @param mixed $skipRoot
67
+ * @return Mage_Archive_Tar
68
+ */
69
+ protected function _setSkipRoot($skipRoot)
70
+ {
71
+ $this->_skipRoot = $skipRoot;
72
+ return $this;
73
+ }
74
+
75
+ /**
76
+ * Set file which is packing.
77
+ *
78
+ * @param string $file
79
+ * @return Mage_Archive_Tar
80
+ */
81
+ protected function _setCurrentFile($file)
82
+ {
83
+ $this->_currentFile = $file .((is_dir($file) && substr($file, -1)!=DS)?DS:'');
84
+ return $this;
85
+ }
86
+
87
+ /**
88
+ * Retrieve file which is packing.
89
+ *
90
+ * @return string
91
+ */
92
+ protected function _getCurrentFile()
93
+ {
94
+ return $this->_currentFile;
95
+ }
96
+
97
+ /**
98
+ * Set path to file which is packing.
99
+ *
100
+ * @param string $path
101
+ * @return Mage_Archive_Tar
102
+ */
103
+ protected function _setCurrentPath($path)
104
+ {
105
+ if ($this->_skipRoot && is_dir($path)) {
106
+ $this->_currentPath = $path.(substr($path, -1)!=DS?DS:'');
107
+ } else {
108
+ $this->_currentPath = dirname($path) . DS;
109
+ }
110
+ return $this;
111
+ }
112
+
113
+ /**
114
+ * Retrieve path to file which is packing.
115
+ *
116
+ * @return string
117
+ */
118
+ protected function _getCurrentPath()
119
+ {
120
+ return $this->_currentPath;
121
+ }
122
+
123
+ /**
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
+ */
130
+ protected function _packToTar($skipRoot=false)
131
+ {
132
+ $file = $this->_getCurrentFile();
133
+ $header = '';
134
+ $data = '';
135
+ if (!$skipRoot) {
136
+ $header = $this->_composeHeader();
137
+ $data = $this->_readFile($file);
138
+ $data = str_pad($data, floor(((is_dir($file) ? 0 : filesize($file)) + 512 - 1) / 512) * 512, "\0");
139
+ }
140
+ $sub = '';
141
+ if (is_dir($file)) {
142
+ $treeDir = scandir($file);
143
+ if (empty($treeDir)) {
144
+ throw new Mage_Exception('Can\'t scan dir: ' . $file);
145
+ }
146
+ array_shift($treeDir); /* remove './'*/
147
+ array_shift($treeDir); /* remove '../'*/
148
+ foreach ($treeDir as $item) {
149
+ $sub .= $this->_setCurrentFile($file.$item)->_packToTar(false);
150
+ }
151
+ }
152
+ $tarData = $header . $data . $sub;
153
+ $tarData = str_pad($tarData, floor((strlen($tarData) - 1) / 1536) * 1536, "\0");
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
164
+ * @return string
165
+ */
166
+ protected function _composeHeader($long = false)
167
+ {
168
+ $file = $this->_getCurrentFile();
169
+ $path = $this->_getCurrentPath();
170
+ $infoFile = stat($file);
171
+ $nameFile = str_replace($path, '', $file);
172
+ $nameFile = str_replace('\\', '/', $nameFile);
173
+ $packedHeader = '';
174
+ $longHeader = '';
175
+ if (!$long && strlen($nameFile)>100) {
176
+ $longHeader = $this->_composeHeader(true);
177
+ $longHeader .= str_pad($nameFile, floor((strlen($nameFile) + 512 - 1) / 512) * 512, "\0");
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'=>'');
192
+ $header['32-uname'] = $a['name'];
193
+ $a=function_exists('posix_getgrgid')?posix_getgrgid (filegroup($file)):array('name'=>'');
194
+ $header['32-gname'] = $a['name'];
195
+ $header['8-devmajor'] = '';
196
+ $header['8-devminor'] = '';
197
+ $header['155-prefix'] = '';
198
+ $header['12-closer'] = '';
199
+
200
+ $packedHeader = '';
201
+ foreach ($header as $key=>$element) {
202
+ $length = explode('-', $key);
203
+ $packedHeader .= pack('a' . $length[0], $element);
204
+ }
205
+
206
+ $checksum = 0;
207
+ for ($i = 0; $i < 512; $i++) {
208
+ $checksum += ord(substr($packedHeader, $i, 1));
209
+ }
210
+ $packedHeader = substr_replace($packedHeader, sprintf("%07o", $checksum)."\0", 148, 8);
211
+
212
+ return $longHeader . $packedHeader;
213
+ }
214
+
215
+ /**
216
+ * Read TAR string from file, and unpacked it.
217
+ * Create files and directories information about discribed
218
+ * in the string.
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
+ */
257
+ protected function _parseHeader(&$pointer)
258
+ {
259
+ $firstLine = fread($pointer, 512);
260
+
261
+ if (strlen($firstLine)<512){
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']);
272
+ $header['size']=octdec($header['size']);
273
+ $header['mtime']=octdec($header['mtime']);
274
+ $header['checksum']=octdec($header['checksum']);
275
+
276
+ if ($header['type'] == "5") {
277
+ $header['size'] = 0;
278
+ }
279
+
280
+ $checksum = 0;
281
+ $firstLine = substr_replace($firstLine, ' ', 148, 8);
282
+ for ($i = 0; $i < 512; $i++) {
283
+ $checksum += ord(substr($firstLine, $i, 1));
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') {
291
+ $realName = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
292
+ $headerMain = $this->_parseHeader($pointer);
293
+ $headerMain['name'] = $realName;
294
+ return $headerMain;
295
+ } else {
296
+ if ($header['size']>0) {
297
+ $header['data'] = substr(fread($pointer, floor(($header['size'] + 512 - 1) / 512) * 512), 0, $header['size']);
298
+ } else {
299
+ $header['data'] = '';
300
+ }
301
+ return $header;
302
+ }
303
+ }
304
+ return false;
305
+ }
306
+
307
+ /**
308
+ * Pack file to TAR (Tape Archiver).
309
+ *
310
+ * @param string $source
311
+ * @param string $destination
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
+
326
+ /**
327
+ * Unpack file from TAR (Tape Archiver).
328
+ *
329
+ * @param string $source
330
+ * @param string $destination
331
+ * @return string
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
+
345
+ /**
346
+ * Extract one file from TAR (Tape Archiver).
347
+ *
348
+ * @param string $file
349
+ * @param string $source
350
+ * @param string $destination
351
+ * @return string
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
+ }
lib/Mage/Autoload/Simple.php ADDED
@@ -0,0 +1,52 @@
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_Connect
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Mage_Autoload_Simple
28
+ {
29
+ private static $_instance;
30
+
31
+ public static function instance()
32
+ {
33
+ if (!self::$_instance) {
34
+ $class = __CLASS__;
35
+ self::$_instance = new $class();
36
+ }
37
+ return self::$_instance;
38
+ }
39
+
40
+ public static function register()
41
+ {
42
+ spl_autoload_register(array(self::instance(), 'autoload'));
43
+ }
44
+
45
+ public function autoload($class)
46
+ {
47
+ $classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));
48
+ $classFile.= '.php';
49
+ @include $classFile;
50
+ }
51
+
52
+ }
lib/Mage/Connect/Channel/Generator.php ADDED
@@ -0,0 +1,63 @@
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_Connect
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ class Mage_Connect_Channel_Generator extends Mage_Xml_Generator
28
+ {
29
+ protected $_file = 'channel.xml';
30
+ protected $_generator = null;
31
+
32
+ public function __construct($file='')
33
+ {
34
+ if ($file) {
35
+ $this->_file = $file;
36
+ }
37
+ return $this;
38
+ }
39
+
40
+ public function getFile()
41
+ {
42
+ return $this->_file;
43
+ }
44
+
45
+ public function getGenerator()
46
+ {
47
+ if (is_null($this->_generator)) {
48
+ $this->_generator = new Mage_Xml_Generator();
49
+ }
50
+ return $this->_generator;
51
+ }
52
+
53
+ /**
54
+ * @param array $content
55
+ */
56
+ public function save($content)
57
+ {
58
+ $xmlContent = $this->getGenerator()
59
+ ->arrayToXml($content)
60
+ ->save($this->getFile());
61
+ return $this;
62
+ }
63
+ }
lib/Mage/Connect/Channel/Parser.php ADDED
@@ -0,0 +1,25 @@
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_Connect
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
lib/Mage/Connect/Channel/VO.php ADDED
@@ -0,0 +1,113 @@
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_Connect
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ class Mage_Connect_Channel_VO implements Iterator
29
+ {
30
+
31
+ private $_validator = null;
32
+
33
+ protected $properties = array(
34
+ 'name' => '',
35
+ 'uri' => '',
36
+ 'summary' => '',
37
+ );
38
+
39
+ public function rewind() {
40
+ reset($this->properties);
41
+ }
42
+
43
+ public function valid() {
44
+ return current($this->properties) !== false;
45
+ }
46
+
47
+ public function key() {
48
+ return key($this->properties);
49
+ }
50
+
51
+ public function current() {
52
+ return current($this->properties);
53
+ }
54
+
55
+ public function next() {
56
+ next($this->properties);
57
+ }
58
+
59
+ public function __get($var)
60
+ {
61
+ if (isset($this->properties[$var])) {
62
+ return $this->properties[$var];
63
+ }
64
+ return null;
65
+ }
66
+
67
+ public function __set($var, $value)
68
+ {
69
+ if (is_string($value)) {
70
+ $value = trim($value);
71
+ }
72
+ if (isset($this->properties[$var])) {
73
+ if ($value === null) {
74
+ $value = '';
75
+ }
76
+ $this->properties[$var] = $value;
77
+ }
78
+ }
79
+
80
+ public function toArray()
81
+ {
82
+ return array('channel' => $this->properties);
83
+ }
84
+
85
+ public function fromArray(array $arr)
86
+ {
87
+ foreach($arr as $k=>$v) {
88
+ $this->$k = $v;
89
+ }
90
+ }
91
+
92
+
93
+ private function validator()
94
+ {
95
+ if(is_null($this->_validator)) {
96
+ $this->_validator = new Mage_Connect_Validator();
97
+ }
98
+ return $this->_validator;
99
+ }
100
+
101
+ /**
102
+ Stub for validation result
103
+ */
104
+ public function validate()
105
+ {
106
+ $v = $this->validator();
107
+ if(!$v->validatePackageName($this->name)) {
108
+ return false;
109
+ }
110
+ return true;
111
+ }
112
+
113
+ }
lib/Mage/Connect/Command.php ADDED
@@ -0,0 +1,390 @@
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_Connect
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ class Mage_Connect_Command
29
+ {
30
+ /**
31
+ * All commands list
32
+ * @var array
33
+ */
34
+ protected static $_commandsAll = array();
35
+
36
+ /**
37
+ * Commands list hash (key=class)
38
+ * @var array
39
+ */
40
+ protected static $_commandsByClass = array();
41
+
42
+ /**
43
+ * Frontend object
44
+ * @var Mage_Connect_Fro
45
+ */
46
+ protected static $_frontend = null;
47
+ protected static $_config = null;
48
+ protected static $_registry = null;
49
+ protected static $_validator = null;
50
+ protected static $_rest = null;
51
+ protected static $_sconfig = null;
52
+
53
+ protected $_data;
54
+ protected $_class;
55
+ protected static $_packager = null;
56
+
57
+ protected static $_return = array();
58
+
59
+ /**
60
+ * Constructor
61
+ *
62
+ */
63
+ public function __construct()
64
+ {
65
+ $class = $this->_class = get_class($this);
66
+ if(__CLASS__ == $class) {
67
+ throw new Exception("You shouldn't instantiate {$class} directly!");
68
+ }
69
+ $this->commandsInfo = self::$_commandsByClass[$class];
70
+ }
71
+
72
+
73
+ /**
74
+ * Get command info (static)
75
+ * @param string $name command name
76
+ * @return array/bool
77
+ */
78
+ public static function commandInfo($name)
79
+ {
80
+ $name = strtolower($name);
81
+ if(!isset(self::$_commandsAll[$name])) {
82
+ return false;
83
+ }
84
+ return self::$_commandsAll[$name];
85
+ }
86
+
87
+ /**
88
+ * Get command info for current command object
89
+ * @param string $name
90
+ * @return array/bool
91
+ */
92
+
93
+ public function getCommandInfo($name)
94
+ {
95
+ if(!isset(self::$_commandsByClass[$this->_class][$name])) {
96
+ return false;
97
+ }
98
+ return self::$_commandsByClass[$this->_class][$name];
99
+ }
100
+
101
+ /**
102
+ * Run command
103
+ * @param string $command
104
+ * @param string $options
105
+ * @param string $params
106
+ * @throws Exception if there's no needed method
107
+ * @return mixed
108
+ */
109
+ public function run($command, $options, $params)
110
+ {
111
+ $data = $this->getCommandInfo($command);
112
+ $method = $data['function'];
113
+ if(! method_exists($this, $method)) {
114
+ throw new Exception("$method does't exist in class ".$this->_class);
115
+ }
116
+ return $this->$method($command, $options, $params);
117
+ }
118
+
119
+ /**
120
+ * Static functions
121
+ */
122
+
123
+ /**
124
+ * Static
125
+ * @param $commandName
126
+ * @return unknown_type
127
+ */
128
+ public static function getInstance($commandName)
129
+ {
130
+ if(!isset(self::$_commandsAll[$commandName])) {
131
+ throw new UnexpectedValueException("Cannot find command $commandName");
132
+ }
133
+ $currentCommand = self::$_commandsAll[$commandName];
134
+ return new $currentCommand['class']();
135
+ }
136
+
137
+
138
+ public static function setSconfig($obj)
139
+ {
140
+ self::$_sconfig = $obj;
141
+ }
142
+
143
+ /**
144
+ *
145
+ * @return Mage_Connect_Singleconfig
146
+ */
147
+ public function getSconfig()
148
+ {
149
+ return self::$_sconfig;
150
+ }
151
+
152
+
153
+ /**
154
+ * Sets frontend object for all commands
155
+ *
156
+ * @param Mage_Connect_Frontend $obj
157
+ * @return void
158
+ */
159
+ public static function setFrontendObject($obj)
160
+ {
161
+ self::$_frontend = $obj;
162
+ }
163
+
164
+
165
+ /**
166
+ * Set config object for all commands
167
+ * @param Mage_Connect_Config $obj
168
+ * @return void
169
+ */
170
+ public static function setConfigObject($obj)
171
+ {
172
+ self::$_config = $obj;
173
+ }
174
+
175
+
176
+ /**
177
+ * Non-static getter for config
178
+ * @return Mage_Connect_Config
179
+ */
180
+ public function config()
181
+ {
182
+ return self::$_config;
183
+ }
184
+
185
+ /**
186
+ * Non-static getter for UI
187
+ * @return Mage_Connect_Frontend
188
+ */
189
+ public function ui()
190
+ {
191
+ return self::$_frontend;
192
+ }
193
+
194
+
195
+ /**
196
+ * Get validator object
197
+ * @return Mage_Connect_Validator
198
+ */
199
+ public function validator()
200
+ {
201
+ if(is_null(self::$_validator)) {
202
+ self::$_validator = new Mage_Connect_Validator();
203
+ }
204
+ return self::$_validator;
205
+ }
206
+
207
+ /**
208
+ * Get rest object
209
+ * @return Mage_Connect_Rest
210
+ */
211
+ public function rest()
212
+ {
213
+ if(is_null(self::$_rest)) {
214
+ self::$_rest = new Mage_Connect_Rest(self::config()->protocol);
215
+ }
216
+ return self::$_rest;
217
+ }
218
+
219
+
220
+ /**
221
+ * Get commands list sorted
222
+ * @return array
223
+ */
224
+ public static function getCommands()
225
+ {
226
+ if(!count(self::$_commandsAll)) {
227
+ self::registerCommands();
228
+ }
229
+ ksort(self::$_commandsAll);
230
+ return self::$_commandsAll;
231
+ }
232
+
233
+
234
+ /**
235
+ * Get Getopt args from command definitions
236
+ * and parse them
237
+ * @param $command
238
+ * @return array
239
+ */
240
+ public static function getGetoptArgs($command)
241
+ {
242
+ $commandInfo = self::commandInfo($command);
243
+ $short_args = '';
244
+ $long_args = array();
245
+ if (empty($commandInfo) || empty($commandInfo['options'])) {
246
+ return;
247
+ }
248
+ reset($commandInfo['options']);
249
+ while (list($option, $info) = each($commandInfo['options'])) {
250
+ $larg = $sarg = '';
251
+ if (isset($info['arg'])) {
252
+ if ($info['arg']{0} == '(') {
253
+ $larg = '==';
254
+ $sarg = '::';
255
+ $arg = substr($info['arg'], 1, -1);
256
+ } else {
257
+ $larg = '=';
258
+ $sarg = ':';
259
+ $arg = $info['arg'];
260
+ }
261
+ }
262
+ if (isset($info['shortopt'])) {
263
+ $short_args .= $info['shortopt'] . $sarg;
264
+ }
265
+ $long_args[] = $option . $larg;
266
+ }
267
+ return array($short_args, $long_args);
268
+ }
269
+
270
+ /**
271
+ * Try to register commands automatically
272
+ * @return void
273
+ */
274
+ public static function registerCommands()
275
+ {
276
+ $pathCommands = dirname(__FILE__).DIRECTORY_SEPARATOR.basename(__FILE__, ".php");
277
+ $f = new DirectoryIterator($pathCommands);
278
+ foreach($f as $file) {
279
+ if (! $file->isFile()) {
280
+ continue;
281
+ }
282
+ $pattern = preg_match("/(.*)_Header\.php/imsu", $file->getFilename(), $matches);
283
+ if(! $pattern) {
284
+ continue;
285
+ }
286
+ include($file->getPathname());
287
+ if(! isset($commands)) {
288
+ continue;
289
+ }
290
+ $class = __CLASS__."_".$matches[1];
291
+ foreach ($commands as $k=>$v) {
292
+ $commands[$k]['class'] = $class;
293
+ self::$_commandsAll[$k] = $commands[$k];
294
+ }
295
+ self::$_commandsByClass[$class] = $commands;
296
+ }
297
+ }
298
+
299
+ public function doError($command, $message)
300
+ {
301
+ return $this->ui()->doError($command, $message);
302
+ }
303
+
304
+
305
+ /**
306
+ * Set command return
307
+ * @param string $key
308
+ * @param mixed $val
309
+ * @return void
310
+ */
311
+ public static function setReturn($key, $val)
312
+ {
313
+ self::$_return[$key] = $val;
314
+ }
315
+
316
+ /**
317
+ * Get command return
318
+ * @param $key
319
+ * @param $clear
320
+ * @return mixed
321
+ */
322
+ public static function getReturn($key, $clear = true)
323
+ {
324
+ if(isset(self::$_return[$key])) {
325
+ $out = self::$_return[$key];
326
+ if($clear) {
327
+ unset(self::$_return[$key]);
328
+ }
329
+ return $out;
330
+ }
331
+ return null;
332
+ }
333
+
334
+ /**
335
+ * Cleanup command params from empty strings
336
+ *
337
+ * @param array $params by reference
338
+ */
339
+ public function cleanupParams(array & $params)
340
+ {
341
+ $newParams = array();
342
+ if(!count($params)) {
343
+ return;
344
+ }
345
+ foreach($params as $k=>$v) {
346
+ if(is_string($v)) {
347
+ $v = trim($v);
348
+ if(!strlen($v)) {
349
+ continue;
350
+ }
351
+ }
352
+ $newParams[] = $v;
353
+ }
354
+ $params = $newParams;
355
+ }
356
+
357
+ /**
358
+ * Splits first command argument: channel/package
359
+ * to two arguments if found in top of array
360
+ *
361
+ * @param array $params
362
+ */
363
+ public function splitPackageArgs(array & $params)
364
+ {
365
+ if(!count($params) || !isset($params[0])) {
366
+ return;
367
+ }
368
+ if($this->validator()->validateUrl($params[0])) {
369
+ return;
370
+ }
371
+ if(preg_match("@([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)@ims", $params[0], $subs)) {
372
+ $params[0] = $subs[2];
373
+ array_unshift($params, $subs[1]);
374
+ }
375
+ }
376
+
377
+
378
+ /**
379
+ * Get packager instance
380
+ * @return Mage_Connect_Pacakger
381
+ */
382
+ public function getPackager()
383
+ {
384
+ if(!self::$_packager) {
385
+ self::$_packager = new Mage_Connect_Packager();
386
+ }
387
+ return self::$_packager;
388
+ }
389
+
390
+ }
lib/Mage/Connect/Command/Channels.php ADDED
@@ -0,0 +1,189 @@
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_Connect
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ final class Mage_Connect_Command_Channels
28
+ extends Mage_Connect_Command
29
+ {
30
+
31
+ /**
32
+ * List available channels
33
+ * @param $command
34
+ * @param $params
35
+ * @param $options
36
+ */
37
+ public function doList($command, $options, $params)
38
+ {
39
+
40
+ try {
41
+ $title = "Available channels:";
42
+ $aliasT = "Available aliases:";
43
+ $packager = $this->getPackager();
44
+ $ftp = empty($options['ftp']) ? false : $options['ftp'];
45
+ if($ftp) {
46
+ list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
47
+ $data = $cache->getData();
48
+ @unlink($config->getFilename());
49
+ @unlink($cache->getFilename());
50
+ } else {
51
+ $cache = $this->getSconfig();
52
+ $config = $this->config();
53
+ $data = $cache->getData();
54
+ }
55
+ $out = array($command => array('data'=>$data, 'title'=>$title, 'title_aliases'=>$aliasT));
56
+ $this->ui()->output($out);
57
+ } catch (Exception $e) {
58
+ $this->doError($command, $e->getMessage());
59
+ }
60
+ }
61
+
62
+ /**
63
+ * channel-delete callback method
64
+ * @param string $command
65
+ * @param array $options
66
+ * @param array $params
67
+ */
68
+ public function doDelete($command, $options, $params)
69
+ {
70
+ $this->cleanupParams($params);
71
+ try {
72
+ if(count($params) != 1) {
73
+ throw new Exception("Parameters count should be equal to 1");
74
+ }
75
+ $packager = $this->getPackager();
76
+
77
+ $ftp = empty($options['ftp']) ? false : $options['ftp'];
78
+ if($ftp) {
79
+ list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
80
+ $cache->deleteChannel($params[0]);
81
+ $packager->writeToRemoteCache($cache, $ftpObj);
82
+ @unlink($config->getFilename());
83
+ } else {
84
+ $config = $this->config();
85
+ $cache = $this->getSconfig();
86
+ $cache->deleteChannel($params[0]);
87
+ }
88
+ $this->ui()->output("Successfully deleted");
89
+
90
+ } catch (Exception $e) {
91
+ $this->doError($command, $e->getMessage());
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Channel-add callback
97
+ * @param string $command
98
+ * @param array $options
99
+ * @param array $params
100
+ */
101
+ public function doAdd($command, $options, $params)
102
+ {
103
+ $this->cleanupParams($params);
104
+ try {
105
+ if(count($params) != 1) {
106
+ throw new Exception("Parameters count should be equal to 1");
107
+ }
108
+ $url = $params[0];
109
+ $rest = $this->rest();
110
+ $rest->setChannel($url);
111
+ $data = $rest->getChannelInfo();
112
+ $data->url = $url;
113
+
114
+ $packager = $this->getPackager();
115
+ $ftp = empty($options['ftp']) ? false : $options['ftp'];
116
+ if($ftp) {
117
+ list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
118
+ $cache->addChannel($data->name, $url);
119
+ $packager->writeToRemoteCache($cache, $ftpObj);
120
+ @unlink($config->getFilename());
121
+ } else {
122
+ $cache = $this->getSconfig();
123
+ $config = $this->config();
124
+ $cache->addChannel($data->name, $url);
125
+ }
126
+
127
+ $this->ui()->output("Successfully added: ".$url);
128
+ } catch (Exception $e) {
129
+ $this->doError($command, $e->getMessage());
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Get information about given channel callback
135
+ * @param string $command
136
+ * @param array $options
137
+ * @param array $params
138
+ */
139
+ public function doInfo($command, $options, $params)
140
+ {
141
+
142
+ }
143
+
144
+ /**
145
+ * channel-alias
146
+ * @param $command
147
+ * @param $options
148
+ * @param $params
149
+ * @return unknown_type
150
+ */
151
+ public function doAlias($command, $options, $params)
152
+ {
153
+ $this->cleanupParams($params);
154
+ try {
155
+ if(count($params) != 2) {
156
+ throw new Exception("Parameters count should be equal to 2");
157
+ }
158
+
159
+ $packager = $this->getPackager();
160
+ $chanUrl = $params[0];
161
+ $alias = $params[1];
162
+ $ftp = empty($options['ftp']) ? false : $options['ftp'];
163
+ if($ftp) {
164
+ list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
165
+ $cache->addChannelAlias($chanUrl, $alias);
166
+ $packager->writeToRemoteCache($cache, $ftpObj);
167
+ @unlink($config->getFilename());
168
+ } else {
169
+ $cache = $this->getSconfig();
170
+ $config = $this->config();
171
+ $cache->addChannelAlias($chanUrl, $alias);
172
+ }
173
+ $this->ui()->output("Successfully added: ".$alias);
174
+ } catch (Exception $e) {
175
+ $this->doError($command, $e->getMessage());
176
+ }
177
+ }
178
+
179
+ public function doLogin($command, $options, $params)
180
+ {
181
+
182
+ }
183
+
184
+ public function doLogout($command, $options, $params)
185
+ {
186
+
187
+ }
188
+
189
+ }
lib/Mage/Connect/Command/Channels_Header.php ADDED
@@ -0,0 +1,105 @@
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_Connect
23
+ * @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ $commands = array(
28
+ 'list-channels' => array(
29
+ 'summary' => 'List Available Channels',
30
+ 'function' => 'doList',
31
+ 'shortcut' => 'lc',
32
+ 'options' => array(),
33
+ 'doc' => '
34
+ List all available channels for installation.
35
+ ',
36
+ ),
37
+ 'channel-delete' => array(
38
+ 'summary' => 'Remove a Channel From the List',
39
+ 'function' => 'doDelete',
40
+ 'shortcut' => 'cde',
41
+ 'options' => array(),
42
+ 'doc' => '<channel name>
43
+ Delete a channel from the registry. You may not
44
+ remove any channel that has installed packages.
45
+ '
46
+ ),
47
+ 'channel-add' => array(
48
+ 'summary' => 'Add a Channel',
49
+ 'function' => 'doAdd',
50
+ 'shortcut' => 'ca',
51
+ 'options' => array(),
52
+ 'doc' => '<channel.xml>
53
+ Add a private channel to the channel list. Note that all
54
+ public channels should be synced using "update-channels".
55
+ Parameter may be either a local file or remote URL to a
56
+ channel.xml.
57
+ '
58
+ ),
59
+ 'channel-info' => array(
60
+ 'summary' => 'Retrieve Information on a Channel',
61
+ 'function' => 'doInfo',
62
+ 'shortcut' => 'ci',
63
+ 'options' => array(),
64
+ 'doc' => '<package>
65
+ List the files in an installed package.
66
+ '
67
+ ),
68
+ 'channel-alias' => array(
69
+ 'summary' => 'Specify an alias to a channel name',
70
+ 'function' => 'doAlias',
71
+ 'shortcut' => 'cha',
72
+ 'options' => array(),
73
+ 'doc' => '<channel> <alias>
74
+ Specify a specific alias to use for a channel name.
75
+ The alias may not be an existing channel name or
76
+ alias.
77
+ '
78
+ ),
79
+ 'channel-login' => array(
80
+ 'summary' => 'Connects and authenticates to remote channel server',
81
+ 'shortcut' => 'cli',
82
+ 'function' => 'doLogin',
83
+ 'options' => array(),
84
+ 'doc' => '<channel name>
85
+ Log in to a remote channel server. If <channel name> is not supplied,
86
+ the default channel is used. To use remote functions in the installer
87
+ that require any kind of privileges, you need to log in first. The
88
+ username and password you enter here will be stored in your per-user
89
+ PEAR configuration (~/.pearrc on Unix-like systems). After logging
90
+ in, your username and password will be sent along in subsequent
91
+ operations on the remote server.',
92
+ ),
93
+ 'channel-logout' => array(
94
+ 'summary' => 'Logs out from the remote channel server',
95
+ 'shortcut' => 'clo',
96
+ 'function' => 'doLogout',
97
+ 'options' => array(),
98
+ 'doc' => '<channel name>
99
+ Logs out from a remote channel server. If <channel name> is not supplied,
100
+ the default channel is used. This command does not actually connect to the
101
+ remote server, it only deletes the stored username and password from your user
102
+ configuration.',
103
+ ),
104
+ );
105
+
lib/Mage/Connect/Command/Config.php ADDED
@@ -0,0 +1,211 @@
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