コード例 #1
0
 /**
  * Runs the passed PEAR command for the package
  * with the id passed in the request.
  *
  * @param string $command The command to run
  * @param int $id The id of the package to do something with
  * @return string The name of the package the command was executed for
  */
 private function _runCommand($command = 'install')
 {
     // load the ID of the package to initialize and the package itself
     $id = $this->getRequest()->getParam('id');
     $package = Mage::getModel('manager/package');
     $package->load($id);
     // initialize the options for the PEAR installer
     $opts = array();
     // initialize the parameters for the PEAR installer
     $params = array($config = Mage::helper('manager')->getChannelAsString($package));
     // check the passed command
     switch ($command) {
         case Faett_Core_Interfaces_Service::COMMAND_INSTALL:
             if ((bool) Mage::getStoreConfig('manager/global/force')) {
                 $opts['force'] = true;
             }
             $this->_service->install($opts, $params);
             break;
         case Faett_Core_Interfaces_Service::COMMAND_UPGRADE:
             if ((bool) Mage::getStoreConfig('manager/global/force')) {
                 $opts['force'] = true;
             }
             $this->_service->upgrade($opts, $params);
             break;
         case Faett_Core_Interfaces_Service::COMMAND_UNINSTALL:
             $this->_service->uninstall($opts, $params);
             break;
         default:
             throw Faett_Manager_Exception_InvalidCommandException::create(Mage::helper('manager')->__('201.error.invalid-command', $command, $this->_getConfigUrl()));
     }
     // load the package information
     $info = $this->_service->packageInfo($package->getName(), $package->getChannel()->getAlias());
     // load the installed version
     if (array_key_exists('installed', $info)) {
         $package->setVersionInstalled($versionInstalled = $info['installed']);
     }
     // load the latest version
     if (is_array($info['releases'])) {
         $package->setVersionLatest($versionLatest = reset(array_keys($info['releases'])));
     }
     // set the package state
     $package->setState(Mage::helper('manager')->getPackageState($package));
     // update the package
     $package->save();
     // log a message with the message logged by PEAR
     Mage::log($this->_service->getUI()->getLogText());
     // return the package name
     return $package->getName();
 }