Mage_Connect_Packager::getRemoteConf PHP Method

getRemoteConf() public method

public getRemoteConf ( $ftpString )
    public function getRemoteConf($ftpString)
    {
        $ftpObj = new Mage_Connect_Ftp();
        $ftpObj->connect($ftpString);
        $cfgFile = "connect.cfg";
        $cacheFile = "cache.cfg";
        $wd = $ftpObj->getcwd();
        $remoteConfigExists = $ftpObj->fileExists($cfgFile);
        $tempConfigFile = uniqid($cfgFile . "_temp");
        if (!$remoteConfigExists) {
            $remoteCfg = new Mage_Connect_Config($tempConfigFile);
            $remoteCfg->store();
            $ftpObj->upload($cfgFile, $tempConfigFile);
        } else {
            $ftpObj->get($tempConfigFile, $cfgFile);
            $remoteCfg = new Mage_Connect_Config($tempConfigFile);
        }
        $ftpObj->chdir($wd);
        $remoteCacheExists = $ftpObj->fileExists($cacheFile);
        $tempCacheFile = uniqid($cacheFile . "_temp");
        if (!$remoteCacheExists) {
            $remoteCache = new Mage_Connect_Singleconfig($tempCacheFile);
            $remoteCache->clear();
            $ftpObj->upload($cacheFile, $tempCacheFile);
        } else {
            $ftpObj->get($tempCacheFile, $cacheFile);
            $remoteCache = new Mage_Connect_Singleconfig($tempCacheFile);
        }
        $ftpObj->chdir($wd);
        return array($remoteCache, $remoteCfg, $ftpObj);
    }

Usage Example

コード例 #1
0
 /**
  * List available
  * @param $command
  * @param $options
  * @param $params
  * @return unknown_type
  */
 public function doListAvailable($command, $options, $params)
 {
     $this->cleanupParams($params);
     try {
         $packager = new Mage_Connect_Packager();
         $ftp = empty($options['ftp']) ? false : $options['ftp'];
         if ($ftp) {
             list($cache, $config, $ftpObj) = $packager->getRemoteConf($ftp);
         } else {
             $cache = $this->getSconfig();
             $config = $this->config();
         }
         if (!empty($params[0])) {
             $channels = array($params[0]);
             $cache->getChannel($channels[0]);
         } else {
             $channels = $cache->getChannelNames();
         }
         $packs = array();
         foreach ($channels as $channel) {
             try {
                 $chan = $cache->getChannel($channel);
                 $uri = $cache->chanUrl($channel);
                 $rest = $this->rest();
                 $rest->setChannel($uri);
                 $packages = $rest->getPackages();
                 if (!count($packages)) {
                     $this->ui()->output("Channel '{$channel}' has no packages");
                     continue;
                 }
                 $packs[$channel]['title'] = "Packages for channel '" . $channel . "':";
                 foreach ($packages as $p) {
                     $packageName = $p['n'];
                     $releases = array();
                     foreach ($p['r'] as $k => $r) {
                         $releases[$r] = $rest->shortStateToLong($k);
                     }
                     $packs[$channel]['packages'][$packageName]['releases'] = $releases;
                 }
             } catch (Exception $e) {
                 $this->doError($command, $e->getMessage());
             }
         }
         $dataOut = array();
         $dataOut[$command] = array('data' => $packs);
         $this->ui()->output($dataOut);
     } catch (Exception $e) {
         $this->doError($command, $e->getMessage());
     }
 }
All Usage Examples Of Mage_Connect_Packager::getRemoteConf