getConfig(); $this->getSingleConfig(); $this->getFrontend(); } /** * Initialize instance * * @return Maged_Connect */ public static function getInstance() { if (!self::$_instance) { self::$_instance = new self; } return self::$_instance; } /** * Retrieve object of config and set it to Mage_Connect_Command * * @return Mage_Connect_Config */ public function getConfig() { if (!$this->_config) { $this->_config = new Mage_Connect_Config(); $ftp=$this->_config->__get('remote_config'); if(!empty($ftp)){ $packager = new Mage_Connect_Packager(); list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp); $this->_config=$config; $this->_sconfig=$cache; } $this->_config->magento_root = dirname(dirname(__FILE__)).DS.'..'; Mage_Connect_Command::setConfigObject($this->_config); } return $this->_config; } /** * Retrieve object of single config and set it to Mage_Connect_Command * * @param bool $reload * @return Mage_Connect_Singleconfig */ public function getSingleConfig($reload = false) { if(!$this->_sconfig || $reload) { $this->_sconfig = new Mage_Connect_Singleconfig($this->getConfig()->magento_root . DIRECTORY_SEPARATOR . $this->getConfig()->downloader_path . DIRECTORY_SEPARATOR . Mage_Connect_Singleconfig::DEFAULT_SCONFIG_FILENAME); } Mage_Connect_Command::setSconfig($this->_sconfig); return $this->_sconfig; } /** * Retrieve object of frontend and set it to Mage_Connect_Command * * @return Maged_Connect_Frontend */ public function getFrontend() { if (!$this->_frontend) { $this->_frontend = new Maged_Connect_Frontend(); Mage_Connect_Command::setFrontendObject($this->_frontend); } return $this->_frontend; } /** * Retrieve lof from frontend * * @return array */ public function getLog() { return $this->getFrontend()->getLog(); } /** * Retrieve output from frontend * * @return array */ public function getOutput() { return $this->getFrontend()->getOutput(); } /** * Clean registry * * @return Maged_Connect */ public function cleanSconfig() { $this->getSingleConfig()->clear(); return $this; } /** * Delete directory recursively * * @param string $path * @return Maged_Connect */ public function delTree($path) { if (@is_dir($path)) { $entries = @scandir($path); foreach ($entries as $entry) { if ($entry != '.' && $entry != '..') { $this->delTree($path.DS.$entry); } } @rmdir($path); } else { @unlink($path); } return $this; } /** * Run commands from Mage_Connect_Command * * @param string $command * @param array $options * @param array $params * @return */ public function run($command, $options=array(), $params=array()) { @set_time_limit(0); @ini_set('memory_limit', '256M'); if (empty($this->_cmdCache[$command])) { Mage_Connect_Command::getCommands(); /** * @var $cmd Mage_Connect_Command */ $cmd = Mage_Connect_Command::getInstance($command); if ($cmd instanceof Mage_Connect_Error) { return $cmd; } $this->_cmdCache[$command] = $cmd; } else { /** * @var $cmd Mage_Connect_Command */ $cmd = $this->_cmdCache[$command]; } $ftp=$this->getConfig()->remote_config; if(strlen($ftp)>0){ $options=array_merge($options, array('ftp'=>$ftp)); } $cmd->run($command, $options, $params); if ($cmd->ui()->hasErrors()) { return false; } else { return true; } } public function setRemoteConfig($uri) #$host, $user, $password, $path='', $port=null) { #$uri = 'ftp://' . $user . ':' . $password . '@' . $host . (is_numeric($port) ? ':' . $port : '') . '/' . trim($path, '/') . '/'; //$this->run('config-set', array(), array('remote_config', $uri)); //$this->run('config-set', array('ftp'=>$uri), array('remote_config', $uri)); $this->getConfig()->remote_config=$uri; return $this; } /** * * @param array $errors Error messages * @return Maged_Connect */ public function showConnectErrors($errors) { echo ''; return $this; } /** * Run Mage_COnnect_Command with html output console style * * @param array|Maged_Model $runParams command, options, params, * comment, success_callback, failure_callback */ public function runHtmlConsole($runParams) { if (function_exists('apache_setenv')) { apache_setenv('no-gzip', '1'); } @ini_set('zlib.output_compression', 0); @ini_set('implicit_flush', 1); for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); } ob_implicit_flush(); $fe = $this->getFrontend(); $oldLogStream = $fe->getLogStream(); $fe->setLogStream('stdout'); if ($runParams instanceof Maged_Model) { $run = $runParams; } elseif (is_array($runParams)) { $run = new Maged_Model_Connect_Request($runParams); } elseif (is_string($runParams)) { $run = new Maged_Model_Connect_Request(array('comment'=>$runParams)); } else { throw Maged_Exception("Invalid run parameters"); } if (!$run->get('no-header')) { ?>
get('comment')); if ($command = $run->get('command')) { $result = $this->run($command, $run->get('options'), $run->get('params')); if ($this->getFrontend()->hasErrors()) { echo "