Exemplo n.º 1
0
 private function prepareUpdate()
 {
     jimport('joomla.filesystem.archive');
     $buildsPath = $this->project->getZipPath();
     if (!JFolder::exists($buildsPath)) {
         return false;
     }
     $folders = JFolder::folders($buildsPath);
     if (!$folders) {
         return false;
     }
     $tmpPath = '';
     $tmpPath .= JFactory::getConfig()->get('tmp_path');
     $tmpPath .= '/' . $this->project->comName . '_update_' . time();
     $this->log('Temp path is set to ' . $tmpPath);
     if (!JFolder::create($tmpPath)) {
         EcrHtml::message('Unable to create temp folder for update', 'error');
         $this->log('Can not create the temp folder ' . $tmpPath);
         return false;
     }
     foreach ($folders as $folder) {
         JFolder::create($tmpPath . '/' . $folder);
         $this->log('Processing version ' . $folder);
         $files = JFolder::files($buildsPath . '/' . $folder);
         if (!$files) {
             continue;
         }
         $this->log(sprintf('Found %d package(s) ', count($files)));
         if (1 == count($files)) {
             //-- Only one file found in folder - take it
             $source = $buildsPath . '/' . $folder . '/' . $files[0];
         } else {
             //-- @todo tmp solution for multiple file :-?
             //-- ===echo 'more files found....picking '.$files[0];
             //-- Temp
             $source = $buildsPath . '/' . $folder . '/' . $files[0];
         }
         $this->log('Processing package: ' . $source);
         $destination = $tmpPath . '/' . $folder;
         if (!JArchive::extract($source, $destination)) {
             EcrHtml::message(sprintf('Unable to extract the package %s to %s', $source, $destination), 'error');
             return false;
         }
     }
     //foreach
     $this->tmpPath = $tmpPath;
     return true;
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @param EcrProjectBase $project
  * @param string         $adapter
  */
 public function __construct(EcrProjectBase $project, $adapter = 'mysql')
 {
     if (class_exists('easyLogger')) {
         $this->logger = EcrLogger::getInstance('ecr');
     }
     if (!$this->setAdapter($adapter)) {
         return false;
     }
     $buildsPath = $project->getZipPath();
     $this->log('Looking for versions in ' . $buildsPath);
     if (false == JFolder::exists($buildsPath)) {
         return;
     }
     $folders = JFolder::folders($buildsPath);
     $this->log(sprintf('Found %d version(s) ', count($folders)));
     if (!$folders) {
         return;
     }
     $this->versions = $folders;
     $this->project = $project;
 }
Exemplo n.º 3
0
 /**
  * Create the zip file.
  *
  * @throws EcrExceptionZiper
  * @return EcrProjectZiper
  */
 private function createArchive()
 {
     if (false == $this->validBuild) {
         return $this;
     }
     $zipTypes = array('Zip' => 'zip', 'Tgz' => 'tar.gz', 'Bz2' => 'bz2');
     $this->logger->log('Start adding files');
     if ($this->build_dir != ECRPATH_BUILDS) {
         $zipDir = $this->build_dir . DS . $this->project->version;
     } else {
         $zipDir = $this->build_dir . DS . $this->project->comName . DS . $this->project->version;
     }
     //-- Build the file list
     $files = JFolder::files($this->temp_dir, '.', true, true);
     $this->logger->log('TOTAL: ' . count($files) . ' files');
     if (false == JFolder::exists($zipDir)) {
         if (false == JFolder::create($zipDir)) {
             throw new EcrExceptionZiper(__METHOD__ . ' - ERROR creating folder ' . $zipDir);
         }
     }
     if (0 === strpos($this->project->getZipPath(), ECRPATH_BUILDS)) {
         $hrefBase = JURI::root() . str_replace(JPATH_ROOT, '', ECRPATH_BUILDS) . '/' . $this->project->comName . '/' . $this->project->version;
         $hrefBase = str_replace('/\\', '/', $hrefBase);
         $hrefBase = str_replace('\\', '/', $hrefBase);
     } else {
         $hrefBase = 'file://' . $this->project->getZipPath() . DIRECTORY_SEPARATOR . $this->project->version;
     }
     $customFileName = EcrProjectHelper::formatFileName($this->project, JFactory::getApplication()->input->getString('cst_format'));
     $fileName = $this->project->getFileName() . $customFileName;
     foreach ($zipTypes as $zipType => $ext) {
         if (false == $this->preset->{'archive' . $zipType}) {
             continue;
         }
         $this->logger->log('creating ' . $zipType);
         switch ($ext) {
             case 'zip':
                 //-- Translate win path to unix path - for PEAR..
                 $p = str_replace('\\', '/', $this->temp_dir);
                 if (false == EcrArchive::createZip($zipDir . DS . $fileName . '.zip', $files, $p)) {
                     throw new EcrExceptionZiper(__METHOD__ . ' - ERROR Packing routine for ' . $ext);
                 }
                 break;
             case 'bz2':
                 ecrLoadHelper('PEAR');
                 if (false == extension_loaded('bz2')) {
                     PEAR::loadExtension('bz2');
                 }
                 if (false == extension_loaded('bz2')) {
                     JFactory::getApplication()->enqueueMessage(jgettext('The extension "bz2" couldn\'t be found.'), 'error');
                     JFactory::getApplication()->enqueueMessage(jgettext('Please make sure your version of PHP was built with bz2 support.'), 'error');
                     $this->logger->log('PHP extension bz2 not found', 'PHP ERROR');
                 } else {
                     //-- Translate win path to unix path - for PEAR..
                     $p = str_replace('\\', '/', $this->temp_dir);
                     $result = $archive = EcrArchive::createTgz($zipDir . DS . $fileName . '.' . $ext, $files, 'bz2', $p);
                     if (!$result->listContent()) {
                         throw new EcrExceptionZiper(__METHOD__ . 'ERROR Packing routine for ' . $ext);
                     }
                 }
                 break;
             case 'tar.gz':
                 $result = $archive = EcrArchive::createTgz($zipDir . DS . $fileName . '.' . $ext, $files, 'gz', $this->temp_dir);
                 if (!$result->listContent()) {
                     throw new EcrExceptionZiper(__METHOD__ . 'ERROR Packing routine for ' . $ext);
                 }
                 break;
             default:
                 throw new EcrExceptionZiper(__METHOD__ . 'undefined packing type ' . $ext);
                 break;
         }
         $this->logger->log('Packing routine for ' . $ext . ' finished');
         $this->downloadLinks[] = $hrefBase . '/' . $fileName . '.' . $ext;
         /*
         $f = new EcrProjectZiperCreatedfile($zipDir.DS.$fileName.'.'.$ext);
         $this->createdFiles[] = $zipDir.DS.$fileName.'.'.$ext;
         $f = new EcrProjectZiperCreatedfile($zipDir.DS.$fileName.'.'.$ext);
         */
         $this->createdFiles[] = new EcrProjectZiperCreatedfile($zipDir . DS . $fileName . '.' . $ext, $hrefBase . '/' . $fileName . '.' . $ext);
     }
     return $this;
 }