getConfig();
$this->getSingleConfig();
$this->getFrontend();
}
/**
* Destructor, sends Console footer if Console started
*/
public function __destruct()
{
if ($this->_consoleStarted) {
$this->_consoleFooter();
}
}
/**
* 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 boolean|Mage_Connect_Error
*/
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;
}
}
/**
* Set remote Config by URI
*
* @param $uri
* @return Maged_Connect
*/
public function setRemoteConfig($uri)
{
$this->getConfig()->remote_config=$uri;
return $this;
}
/**
* Show Errors
*
* @param array $errors Error messages
* @return Maged_Connect
*/
public function showConnectErrors($errors)
{
echo '';
return $this;
}
/**
* Run Mage_Connect_Command with html output console style
*
* @throws Maged_Exception
* @param array|string|Maged_Model $runParams command, options, params, comment, success_callback, failure_callback
* @return bool|Mage_Connect_Error
*/
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')) {
$this->_consoleHeader();
}
echo htmlspecialchars($run->get('comment')).'
';
if ($command = $run->get('command')) {
$result = $this->run($command, $run->get('options'), $run->get('params'));
if ($this->getFrontend()->hasErrors()) {
echo "
CONNECT ERROR: ";
foreach ($this->getFrontend()->getErrors(false) as $error) {
echo nl2br($error[1]);
echo '
';
}
}
echo '';
} else {
$result = false;
}
if ($this->getFrontend()->getErrors() || !$run->get('no-footer')) {
//$this->_consoleFooter();
$fe->setLogStream($oldLogStream);
}
return $result;
}
/**
* Show HTML Console Header
*
* @return void
*/
protected function _consoleHeader() {
if (!$this->_consoleStarted) {
?>