PageRenderTime 41ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

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

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