00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 require_once 'Varien/Pear/Package.php';
00029
00030
00031
00032
00033
00034
00035
00036
00037 class Mage_Adminhtml_Extensions_CustomController extends Mage_Adminhtml_Controller_Action
00038 {
00039 public function indexAction()
00040 {
00041 $this->_forward('edit');
00042 }
00043
00044 public function editAction()
00045 {
00046 $this->loadLayout();
00047
00048 $this->_setActiveMenu('system/extensions/custom');
00049
00050 $this->_addContent($this->getLayout()->createBlock('adminhtml/extensions_custom_edit'));
00051
00052 $this->_addLeft($this->getLayout()->createBlock('adminhtml/extensions_custom_edit_tabs'));
00053
00054 $this->renderLayout();
00055 }
00056
00057 public function resetAction()
00058 {
00059 Mage::getSingleton('adminhtml/session')->unsCustomExtensionPackageFormData();
00060 $this->_redirect('*/*/edit');
00061 }
00062
00063 public function loadAction()
00064 {
00065 $package = $this->getRequest()->getParam('id');
00066 if ($package) {
00067 $session = Mage::getSingleton('adminhtml/session');
00068 try {
00069 $data = $this->_loadPackageFile(Mage::getBaseDir('var') . DS . 'pear' . DS . $package);
00070
00071 $data = array_merge($data, array('file_name' => $package));
00072
00073 $session->setCustomExtensionPackageFormData($data);
00074 $session->addSuccess(Mage::helper('adminhtml')->__("Package %s data was successfully loaded", $package));
00075 }
00076 catch (Exception $e) {
00077 $session->addError($e->getMessage());
00078 }
00079 }
00080 $this->_redirect('*/*/edit');
00081 }
00082
00083 private function _loadPackageFile($filenameNoExtension)
00084 {
00085 $data = null;
00086
00087
00088 $filename = $filenameNoExtension . '.xml';
00089 if (file_exists($filename)) {
00090 $xml = simplexml_load_file($filename);
00091 $data = Mage::helper('core')->xmlToAssoc($xml);
00092 if (!empty($data)) {
00093 return $data;
00094 }
00095 }
00096
00097
00098 $filename = $filenameNoExtension . '.ser';
00099 if (!is_readable($filename)) {
00100 throw new Exception(Mage::helper('adminhtml')->__('Failed to load %1$s.xml or %1$s.ser', basename($filenameNoExtension)));
00101 }
00102 $contents = file_get_contents($filename);
00103 $data = unserialize($contents);
00104 if (!empty($data)) {
00105 return $data;
00106 }
00107
00108 throw new Exception('Failed to load package data.');
00109 }
00110
00111 public function saveAction()
00112 {
00113 $session = Mage::getSingleton('adminhtml/session');
00114 $p = $this->getRequest()->getPost();
00115
00116 if (!empty($p['_create'])) {
00117 $create = true;
00118 unset($p['_create']);
00119 }
00120
00121 if ($p['file_name'] == '') {
00122 $p['file_name'] = $p['name'];
00123 }
00124
00125 $session->setCustomExtensionPackageFormData($p);
00126 try {
00127 $ext = Mage::getModel('adminhtml/extension');
00128
00129 $ext->setData($p);
00130 $output = $ext->getPear()->getOutput();
00131 if ($ext->savePackage()) {
00132 $session->addSuccess('Package data was successfully saved');
00133 } else {
00134 $session->addError('There was a problem saving package data');
00135 $this->_redirect('*/*/edit');
00136 }
00137 if (empty($create)) {
00138 $this->_redirect('*/*/edit');
00139 } else {
00140 $this->_forward('create');
00141 }
00142 }
00143 catch(Mage_Core_Exception $e){
00144 $session->addError($e->getMessage());
00145 $this->_redirect('*/*');
00146 }
00147 catch(Exception $e){
00148 $session->addError($e->getMessage());
00149 $this->_redirect('*/*');
00150 }
00151 }
00152
00153 public function createAction()
00154 {
00155 $session = Mage::getSingleton('adminhtml/session');
00156 try {
00157 $p = $this->getRequest()->getPost();
00158 $session->setCustomExtensionPackageFormData($p);
00159 $ext = Mage::getModel('adminhtml/extension');
00160 $ext->setData($p);
00161 $result = $ext->createPackage();
00162 $pear = Varien_Pear::getInstance();
00163 if ($result) {
00164 $data = $pear->getOutput();
00165 $session->addSuccess($data[0]['output']);
00166 $this->_redirect('*/*');
00167 #$this->_forward('reset');
00168 } else {
00169 $session->addError($result->getMessage());
00170 $this->_redirect('*/*');
00171 }
00172 }
00173 catch(Mage_Core_Exception $e){
00174 $session->addError($e->getMessage());
00175 $this->_redirect('*/*');
00176 }
00177 catch(Exception $e){
00178 $session->addError($e->getMessage());
00179 $this->_redirect('*/*');
00180 }
00181 }
00182
00183 public function releaseAction()
00184 {
00185 #Varien_Pear::getInstance()->runHtmlConsole(array('command'=>'list-channels'));
00186 if (empty($_POST)) {
00187 $serFiles = @glob(Mage::getBaseDir('var').DS.'pear'.DS.'*.ser');
00188 if (!$serFiles) {
00189 return;
00190 }
00191 $pkg = new Varien_Object();
00192 echo '<html><head><style type="text/css">* { font:normal 12px Arial }</style></head>
00193 <body><form method="post"><table border="1" cellpadding="3" cellspacing="0"><thead>
00194 <tr><th>Update/Package</th><th>Version</th><th>State</th></tr>
00195 </thead><tbody>';
00196 foreach ($serFiles as $i=>$file) {
00197 $serialized = file_get_contents($file);
00198 $pkg->setData(unserialize($serialized));
00199 $n = $pkg->getName();
00200 echo '<tr><td><input type="checkbox" name="pkgs['.$i.'][name]" id="pkg_'.$i.'" value="'.$n.'"/>
00201 <label for="pkg_'.$i.'">'.$n.'</label>
00202 <input type="hidden" name="pkgs['.$i.'][file]" value="'.$file.'"/>
00203 </td>
00204 <td><input name="pkgs['.$i.'][release_version]" value="'.$pkg->getData('release_version').'"/></td>
00205 <td><input name="pkgs['.$i.'][release_stability]" value="'.$pkg->getData('release_stability').'"/></td>
00206 </tr>';
00207 #echo "<pre>"; print_r($pkg->getData()); echo "</pre>"; exit;
00208 }
00209 echo '</tbody></table><button type="submit">Save and Generate Packages</button></form></body></html>';
00210 } else {
00211 @set_time_limit(0);
00212 ob_implicit_flush();
00213 foreach ($_POST['pkgs'] as $r) {
00214 if (empty($r['name'])) {
00215 continue;
00216 }
00217 echo "<hr/><h4>".$r['name']."</h4>";
00218
00219 $ext = Mage::getModel('adminhtml/extension');
00220 $ext->setData(unserialize(file_get_contents($r['file'])));
00221 $ext->setData('release_version', $r['release_version']);
00222 $ext->setData('release_stability', $r['release_stability']);
00223 #echo "<pre>"; print_r($ext->getData()); echo "</pre>";
00224 $result = $ext->savePackage();
00225 if (!$result) {
00226 echo "ERROR while creating the package";
00227 continue;
00228 } else {
00229 echo "Package created; ";
00230 }
00231 $result = $ext->createPackage();
00232 $pear = Varien_Pear::getInstance();
00233 if ($result) {
00234 $data = $pear->getOutput();
00235 print_r($data[0]['output']);
00236 } else {
00237 echo "ERROR:";
00238 print_r($result->getMessage());
00239 }
00240 }
00241 echo '<hr/><a href="'.$_SERVER['REQUEST_URI'].'">Refresh</a>';
00242 }
00243 exit;
00244 }
00245
00246 protected function _isAllowed()
00247 {
00248 return Mage::getSingleton('admin/session')->isAllowed('system/extensions/custom');
00249 }
00250
00251
00252
00253
00254
00255 public function loadtabAction()
00256 {
00257 $this->getResponse()->setBody(
00258 $this->getLayout()->createBlock('adminhtml/extensions_custom_edit_tab_load')->toHtml()
00259 );
00260 }
00261
00262
00263
00264
00265
00266 public function gridAction()
00267 {
00268 $this->getResponse()->setBody(
00269 $this->getLayout()->createBlock('adminhtml/extensions_custom_edit_tab_grid')->toHtml()
00270 );
00271 }
00272
00273 }