Beispiel #1
0
 function doUpdate($command, $options, $params)
 {
     $tmpdir = $this->config->get('temp_dir');
     if (!file_exists($tmpdir)) {
         require_once 'System.php';
         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
         $err = System::mkdir(array('-p', $tmpdir));
         PEAR::staticPopErrorHandling();
         if (PEAR::isError($err)) {
             return $this->raiseError('channel-add: temp_dir does not exist: "' . $tmpdir . '" - You can change this location with "pear config-set temp_dir"');
         }
     }
     if (!is_writable($tmpdir)) {
         return $this->raiseError('channel-add: temp_dir is not writable: "' . $tmpdir . '" - You can change this location with "pear config-set temp_dir"');
     }
     $reg =& $this->config->getRegistry();
     if (sizeof($params) != 1) {
         return $this->raiseError("No channel file specified");
     }
     $lastmodified = false;
     if ((!file_exists($params[0]) || is_dir($params[0])) && $reg->channelExists(strtolower($params[0]))) {
         $c = $reg->getChannel(strtolower($params[0]));
         if (PEAR::isError($c)) {
             return $this->raiseError($c);
         }
         $this->ui->outputData("Updating channel \"{$params['0']}\"", $command);
         $dl =& $this->getDownloader(array());
         // if force is specified, use a timestamp of "1" to force retrieval
         $lastmodified = isset($options['force']) ? false : $c->lastModified();
         PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
         $contents = $dl->downloadHttp('http://' . $c->getName() . '/channel.xml', $this->ui, $tmpdir, null, $lastmodified);
         PEAR::staticPopErrorHandling();
         if (PEAR::isError($contents)) {
             return $this->raiseError('Cannot retrieve channel.xml for channel "' . $c->getName() . '" (' . $contents->getMessage() . ')');
         }
         list($contents, $lastmodified) = $contents;
         if (!$contents) {
             $this->ui->outputData("Channel \"{$params['0']}\" is up to date");
             return;
         }
         $contents = implode('', file($contents));
         if (!class_exists('PEAR_ChannelFile')) {
             require_once 'PEAR/ChannelFile.php';
         }
         $channel = new PEAR_ChannelFile();
         $channel->fromXmlString($contents);
         if (!$channel->getErrors()) {
             // security check: is the downloaded file for the channel we got it from?
             if (strtolower($channel->getName()) != strtolower($c->getName())) {
                 if (isset($options['force'])) {
                     $this->ui->log(0, 'WARNING: downloaded channel definition file' . ' for channel "' . $channel->getName() . '" from channel "' . strtolower($c->getName()) . '"');
                 } else {
                     return $this->raiseError('ERROR: downloaded channel definition file' . ' for channel "' . $channel->getName() . '" from channel "' . strtolower($c->getName()) . '"');
                 }
             }
         }
     } else {
         if (strpos($params[0], '://')) {
             $dl =& $this->getDownloader();
             PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
             $loc = $dl->downloadHttp($params[0], $this->ui, $tmpdir, null, $lastmodified);
             PEAR::staticPopErrorHandling();
             if (PEAR::isError($loc)) {
                 return $this->raiseError("Cannot open " . $params[0] . ' (' . $loc->getMessage() . ')');
             } else {
                 list($loc, $lastmodified) = $loc;
                 $contents = implode('', file($loc));
             }
         } else {
             $fp = false;
             if (file_exists($params[0])) {
                 $fp = fopen($params[0], 'r');
             }
             if (!$fp) {
                 return $this->raiseError("Cannot open " . $params[0]);
             }
             $contents = '';
             while (!feof($fp)) {
                 $contents .= fread($fp, 1024);
             }
             fclose($fp);
         }
         if (!class_exists('PEAR_ChannelFile')) {
             require_once 'PEAR/ChannelFile.php';
         }
         $channel = new PEAR_ChannelFile();
         $channel->fromXmlString($contents);
     }
     $exit = false;
     if (count($errors = $channel->getErrors(true))) {
         foreach ($errors as $error) {
             $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message']));
             if (!$exit) {
                 $exit = $error['level'] == 'error' ? true : false;
             }
         }
         if ($exit) {
             return $this->raiseError('Invalid channel.xml file');
         }
     }
     if (!$reg->channelExists($channel->getName())) {
         return $this->raiseError('Error: Channel "' . $channel->getName() . '" does not exist, use channel-add to add an entry');
     }
     $ret = $reg->updateChannel($channel, $lastmodified);
     if (PEAR::isError($ret)) {
         return $ret;
     }
     if (!$ret) {
         return $this->raiseError('Updating Channel "' . $channel->getName() . '" in registry failed');
     }
     $this->config->setChannels($reg->listChannels());
     $this->config->writeConfigFile();
     $this->ui->outputData('Update of Channel "' . $channel->getName() . '" succeeded');
 }