PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Mage/Connect/Command/Remote.php

https://bitbucket.org/claudiu_marginean/magento-hg-mirror
PHP | 226 lines | 144 code | 28 blank | 54 comment | 21 complexity | 6f959617993d58aec974d578921b6212 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  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. final class Mage_Connect_Command_Remote
  27. extends Mage_Connect_Command
  28. {
  29. /**
  30. * List-upgrades callback
  31. * @param srting $command
  32. * @param array $options
  33. * @param array $params
  34. * @return void
  35. */
  36. public function doListUpgrades($command, $options, $params)
  37. {
  38. $this->cleanupParams($params);
  39. try {
  40. $packager = new Mage_Connect_Packager();
  41. $ftp = empty($options['ftp']) ? false : $options['ftp'];
  42. if($ftp) {
  43. list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
  44. } else {
  45. $cache = $this->getSconfig();
  46. $config = $this->config();
  47. }
  48. if(!empty($params[0])) {
  49. $channels = $params[0];
  50. $cache->getChannel($channels);
  51. } else {
  52. $channels = $cache->getChannelNames();
  53. }
  54. $ups = $packager->getUpgradesList($channels, $cache, $config);
  55. if(count($ups)) {
  56. $data = array($command => array('data'=>$ups));
  57. } else {
  58. $data = "No upgrades available";
  59. }
  60. $this->ui()->output($data);
  61. } catch(Exception $e) {
  62. $this->doError($command, $e->getMessage());
  63. }
  64. }
  65. /**
  66. * List available
  67. * @param $command
  68. * @param $options
  69. * @param $params
  70. * @return unknown_type
  71. */
  72. public function doListAvailable($command, $options, $params)
  73. {
  74. $this->cleanupParams($params);
  75. try {
  76. $packager = new Mage_Connect_Packager();
  77. $ftp = empty($options['ftp']) ? false : $options['ftp'];
  78. if($ftp) {
  79. list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
  80. } else {
  81. $cache = $this->getSconfig();
  82. $config = $this->config();
  83. }
  84. if(!empty($params[0])) {
  85. $channels = array($params[0]);
  86. $cache->getChannel($channels[0]);
  87. } else {
  88. $channels = $cache->getChannelNames();
  89. }
  90. $packs = array();
  91. foreach ($channels as $channel) {
  92. try {
  93. $chan = $cache->getChannel($channel);
  94. $uri = $cache->chanUrl($channel);
  95. $rest = $this->rest();
  96. $rest->setChannel($uri);
  97. $packages = $rest->getPackages();
  98. if(!count($packages)) {
  99. $this->ui()->output("Channel '{$channel}' has no packages");
  100. continue;
  101. }
  102. $packs[$channel]['title'] = "Packages for channel '".$channel."':";
  103. foreach($packages as $p) {
  104. $packageName = $p['n'];
  105. $releases = array();
  106. foreach($p['r'] as $k=>$r) {
  107. $releases[$r] = $rest->shortStateToLong($k);
  108. }
  109. $packs[$channel]['packages'][$packageName]['releases'] = $releases;
  110. }
  111. } catch (Exception $e) {
  112. $this->doError($command, $e->getMessage());
  113. }
  114. }
  115. $dataOut = array();
  116. $dataOut[$command]= array('data'=>$packs);
  117. $this->ui()->output($dataOut);
  118. } catch(Exception $e) {
  119. $this->doError($command, $e->getMessage());
  120. }
  121. }
  122. /**
  123. * Download command callback
  124. *
  125. * @param string $command
  126. * @param array $options
  127. * @param array $params
  128. * @return void
  129. */
  130. public function doDownload($command, $options, $params)
  131. {
  132. $this->cleanupParams($params);
  133. //$this->splitPackageArgs($params);
  134. try {
  135. if(count($params) < 2) {
  136. throw new Exception("Arguments should be: channel Package");
  137. }
  138. $channel = $params[0];
  139. $package = $params[1];
  140. $packager = $this->getPackager();
  141. $ftp = empty($options['ftp']) ? false : $options['ftp'];
  142. if($ftp) {
  143. list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
  144. } else {
  145. $cache = $this->getSconfig();
  146. $config = $this->config();
  147. }
  148. $chan = $cache->getChannel($channel);
  149. $uri = $cache->chanUrl($channel);
  150. $rest = $this->rest();
  151. $rest->setChannel($uri);
  152. $c = $rest->getReleases($package);
  153. if(!count($c)) {
  154. throw new Exception("No releases found for package");
  155. }
  156. $version = $cache->detectVersionFromRestArray($c);
  157. $dir = $config->getChannelCacheDir($channel);
  158. $file = $dir.DIRECTORY_SEPARATOR.$package."-".$version.".tgz";
  159. $rest->downloadPackageFileOfRelease($package, $version, $file);
  160. if($ftp) {
  161. @unlink($config->getFilename());
  162. @unlink($cache->getFilename());
  163. }
  164. $this->ui()->output("Saved to: ". $file);
  165. } catch (Exception $e) {
  166. if($ftp) {
  167. @unlink($config->getFilename());
  168. @unlink($cache->getFilename());
  169. }
  170. $this->doError($command, $e->getMessage());
  171. }
  172. }
  173. /**
  174. * Clear cache command callback
  175. * @param string $command
  176. * @param array $options
  177. * @param array $params
  178. * @return void
  179. */
  180. public function doClearCache($command, $options, $params)
  181. {
  182. $this->cleanupParams($params);
  183. try {
  184. $packager = new Mage_Connect_Packager();
  185. $ftp = empty($options['ftp']) ? false : $options['ftp'];
  186. if($ftp) {
  187. list($cache, $ftpObj) = $packager->getRemoteCache($ftp);
  188. $cache->clear();
  189. $packager->writeToRemoteCache($cache, $ftpObj);
  190. } else {
  191. $cache = $this->getSconfig();
  192. $cache->clear();
  193. }
  194. } catch (Exception $e) {
  195. $this->doError($command, $e->getMessage());
  196. }
  197. }
  198. }