PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Mage/Connect/Command/Config.php

https://gitlab.com/LisovyiEvhenii/ismextensions
PHP | 211 lines | 139 code | 20 blank | 52 comment | 24 complexity | 21dffa7fdf2323e24557a3b6d30c39b4 MD5 | raw file
  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@magento.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.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Connect
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. class Mage_Connect_Command_Config
  27. extends Mage_Connect_Command
  28. {
  29. const PARAM_KEY = 0;
  30. const PARAM_VAL = 1;
  31. /**
  32. * Show config variable
  33. * @param string $command
  34. * @param array $options
  35. * @param array $params
  36. * @return void
  37. */
  38. public function doConfigShow($command, $options, $params)
  39. {
  40. $this->cleanupParams($params);
  41. try {
  42. $values = array();
  43. $packager = $this->getPackager();
  44. $ftp = empty($options['ftp']) ? false : $options['ftp'];
  45. if($ftp) {
  46. list($config, $ftpObj) = $packager->getRemoteConfig($ftp);
  47. } else {
  48. $config = $this->config();
  49. }
  50. foreach( $config as $k=>$v ) {
  51. $values[$k] = $v;
  52. }
  53. if($ftp) {
  54. @unlink($config->getFilename());
  55. }
  56. $data = array($command => array('data'=>$values));
  57. $this->ui()->output($data);
  58. } catch (Exception $e) {
  59. if($ftp) {
  60. @unlink($config->getFilename());
  61. }
  62. return $this->doError($command, $e->getMessage());
  63. }
  64. }
  65. /**
  66. * Set config variable
  67. * @param string $command
  68. * @param array $options
  69. * @param array $params
  70. * @return void
  71. */
  72. public function doConfigSet($command, $options, $params)
  73. {
  74. $this->cleanupParams($params);
  75. try {
  76. if(count($params) < 2) {
  77. throw new Exception("Parameters count should be >= 2");
  78. }
  79. $key = strtolower($params[self::PARAM_KEY]);
  80. $val = strval($params[self::PARAM_VAL]);
  81. $packager = $this->getPackager();
  82. $ftp = empty($options['ftp']) ? false : $options['ftp'];
  83. if($ftp) {
  84. list($config, $ftpObj) = $packager->getRemoteConfig($ftp);
  85. } else {
  86. $config = $this->config();
  87. }
  88. if(!$config->hasKey($key)) {
  89. throw new Exception ("No such config variable: {$key}!");
  90. }
  91. if(!$config->validate($key, $val)) {
  92. $possible = $this->config()->possible($key);
  93. $type = $this->config()->type($key);
  94. $errString = "Invalid value specified for $key!";
  95. throw new Exception($errString);
  96. }
  97. if($ftp) {
  98. $packager->writeToRemoteConfig($config, $ftpObj);
  99. }
  100. $this->config()->$key = $val;
  101. $this->ui()->output('Success');
  102. } catch (Exception $e) {
  103. if($ftp) {
  104. @unlink($config->getFilename());
  105. }
  106. return $this->doError($command, $e->getMessage());
  107. }
  108. }
  109. /**
  110. * Get config var
  111. * @param string $command
  112. * @param array $options
  113. * @param array $params
  114. * @return void
  115. */
  116. public function doConfigGet($command, $options, $params)
  117. {
  118. $this->cleanupParams($params);
  119. try {
  120. if(count($params) < 1) {
  121. throw new Exception("Parameters count should be >= 1");
  122. }
  123. $packager = $this->getPackager();
  124. $ftp = empty($options['ftp']) ? false : $options['ftp'];
  125. if($ftp) {
  126. list($config, $ftpObj) = $packager->getRemoteConfig($ftp);
  127. } else {
  128. $config = $this->config();
  129. }
  130. $key = strtolower($params[self::PARAM_KEY]);
  131. if(!$config->hasKey($key)) {
  132. throw new Exception("No such config variable '{$key}'!");
  133. }
  134. if($ftp) {
  135. @unlink($config->getFilename());
  136. }
  137. $this->ui()->output($config->$key);
  138. } catch (Exception $e) {
  139. if($ftp) {
  140. @unlink($config->getFilename());
  141. }
  142. return $this->doError($command, $e->getMessage());
  143. }
  144. }
  145. /**
  146. * Config help
  147. * @param string $command
  148. * @param array $options
  149. * @param array $params
  150. * @return void
  151. */
  152. public function doConfigHelp($command, $options, $params)
  153. {
  154. try {
  155. $this->cleanupParams($params);
  156. if(count($params) < 1) {
  157. throw new Exception( "Parameters count should be >= 1");
  158. }
  159. $packager = $this->getPackager();
  160. $ftp = empty($options['ftp']) ? false : $options['ftp'];
  161. if($ftp) {
  162. list($config, $ftpObj) = $packager->getRemoteConfig($ftp);
  163. } else {
  164. $config = $this->config();
  165. }
  166. $key = strtolower($params[self::PARAM_KEY]);
  167. if(!$this->config()->hasKey($key)) {
  168. throw new Exception("No such config variable '{$key}'!");
  169. }
  170. $possible = $config->possible($key);
  171. $type = $config->type($key);
  172. $doc = $config->doc($key);
  173. if($ftp) {
  174. @unlink($config->getFilename());
  175. }
  176. $data = array();
  177. $data[$command]['data'] = array(
  178. 'name' => array('Variable name', $key),
  179. 'type' => array('Value type', $type),
  180. 'possible' => array('Possible values', $possible),
  181. 'doc' => $doc,
  182. );
  183. $this->ui()->output($data);
  184. } catch (Exception $e) {
  185. if($ftp) {
  186. @unlink($config->getFilename());
  187. }
  188. return $this->doError($command, $e->getMessage());
  189. }
  190. }
  191. }