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

/app/code/core/Mage/Connect/controllers/Adminhtml/Extension/CustomController.php

https://github.com/rgranadino/magento-mirror
PHP | 206 lines | 123 code | 14 blank | 69 comment | 12 complexity | 5b90d8153696c4020e3df29d8ae11b27 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@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) 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. * Extension controller
  28. *
  29. * @category Mage
  30. * @package Mage_Connect
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Connect_Adminhtml_Extension_CustomController extends Mage_Adminhtml_Controller_Action
  34. {
  35. /**
  36. * Redirect to edit Extension Package action
  37. *
  38. */
  39. public function indexAction()
  40. {
  41. $this->_title($this->__('System'))
  42. ->_title($this->__('Magento Connect'))
  43. ->_title($this->__('Package Extensions'));
  44. Mage::app()->getStore()->setStoreId(1);
  45. $this->_forward('edit');
  46. }
  47. /**
  48. * Edit Extension Package Form
  49. *
  50. */
  51. public function editAction()
  52. {
  53. $this->_title($this->__('System'))
  54. ->_title($this->__('Magento Connect'))
  55. ->_title($this->__('Package Extensions'))
  56. ->_title($this->__('Edit Extension'));
  57. $this->loadLayout();
  58. $this->_setActiveMenu('system/extension/custom');
  59. $this->renderLayout();
  60. }
  61. /**
  62. * Reset Extension Package form data
  63. *
  64. */
  65. public function resetAction()
  66. {
  67. Mage::getSingleton('connect/session')->unsCustomExtensionPackageFormData();
  68. $this->_redirect('*/*/edit');
  69. }
  70. /**
  71. * Load Local Extension Package
  72. *
  73. */
  74. public function loadAction()
  75. {
  76. $packageName = base64_decode(strtr($this->getRequest()->getParam('id'), '-_,', '+/='));
  77. if ($packageName) {
  78. $session = Mage::getSingleton('connect/session');
  79. try {
  80. $data = Mage::helper('connect')->loadLocalPackage($packageName);
  81. if (!$data) {
  82. Mage::throwException(Mage::helper('connect')->__('Failed to load the package data.'));
  83. }
  84. $data = array_merge($data, array('file_name' => $packageName));
  85. $session->setCustomExtensionPackageFormData($data);
  86. $session->addSuccess(
  87. Mage::helper('connect')->__('The package %s data has been loaded.', $packageName)
  88. );
  89. } catch (Exception $e) {
  90. $session->addError($e->getMessage());
  91. }
  92. }
  93. $this->_redirect('*/*/edit');
  94. }
  95. /**
  96. * Save Extension Package
  97. *
  98. */
  99. public function saveAction()
  100. {
  101. $session = Mage::getSingleton('connect/session');
  102. $p = $this->getRequest()->getPost();
  103. if (!empty($p['_create'])) {
  104. $create = true;
  105. unset($p['_create']);
  106. }
  107. if ($p['file_name'] == '') {
  108. $p['file_name'] = $p['name'];
  109. }
  110. $session->setCustomExtensionPackageFormData($p);
  111. try {
  112. $ext = Mage::getModel('connect/extension');
  113. /** @var $ext Mage_Connect_Model_Extension */
  114. $ext->setData($p);
  115. if ($ext->savePackage()) {
  116. $session->addSuccess(Mage::helper('connect')->__('The package data has been saved.'));
  117. } else {
  118. $session->addError(Mage::helper('connect')->__('There was a problem saving package data'));
  119. $this->_redirect('*/*/edit');
  120. }
  121. if (empty($create)) {
  122. $this->_redirect('*/*/edit');
  123. } else {
  124. Mage::app()->getStore()->setStoreId(1);
  125. $this->_forward('create');
  126. }
  127. } catch (Mage_Core_Exception $e){
  128. $session->addError($e->getMessage());
  129. $this->_redirect('*/*');
  130. } catch (Exception $e){
  131. $session->addException($e, Mage::helper('connect')->__('Failed to save the package.'));
  132. $this->_redirect('*/*');
  133. }
  134. }
  135. /**
  136. * Create new Extension Package
  137. *
  138. */
  139. public function createAction()
  140. {
  141. $session = Mage::getSingleton('connect/session');
  142. try {
  143. $p = $this->getRequest()->getPost();
  144. $session->setCustomExtensionPackageFormData($p);
  145. $ext = Mage::getModel('connect/extension');
  146. $ext->setData($p);
  147. $packageVersion = $this->getRequest()->getPost('version_ids');
  148. if (is_array($packageVersion)) {
  149. if (in_array(Mage_Connect_Package::PACKAGE_VERSION_2X, $packageVersion)) {
  150. $ext->createPackage();
  151. }
  152. if (in_array(Mage_Connect_Package::PACKAGE_VERSION_1X, $packageVersion)) {
  153. $ext->createPackageV1x();
  154. }
  155. }
  156. $this->_redirect('*/*');
  157. } catch(Mage_Core_Exception $e){
  158. $session->addError($e->getMessage());
  159. $this->_redirect('*/*');
  160. } catch(Exception $e){
  161. $session->addException($e, Mage::helper('connect')->__('Failed to create the package.'));
  162. $this->_redirect('*/*');
  163. }
  164. }
  165. /**
  166. * Load Grid with Local Packages
  167. *
  168. */
  169. public function loadtabAction()
  170. {
  171. $this->loadLayout();
  172. $this->renderLayout();
  173. }
  174. /**
  175. * Grid for loading packages
  176. *
  177. */
  178. public function gridAction()
  179. {
  180. $this->loadLayout();
  181. $this->renderLayout();
  182. }
  183. /**
  184. * Check is allowed access to actions
  185. *
  186. * @return bool
  187. */
  188. protected function _isAllowed()
  189. {
  190. return Mage::getSingleton('admin/session')->isAllowed('system/extensions/custom');
  191. }
  192. }