Example #1
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;
 }
Example #2
0
 /**
  * Export templates to a tar.gz package.
  *
  * @param array $exports Index array of templates to export
  *
  * @throws Exception
  * @return boolean true on success
  */
 public static function exportTemplates($exports)
 {
     $tempDir = JFactory::getConfig()->get('tmp_path') . DS . uniqid('templateexport');
     $files = array();
     foreach ($exports as $type => $folders) {
         foreach ($folders as $folder) {
             $fileList = JFolder::files(ECRPATH_EXTENSIONTEMPLATES . DS . $type . DS . $folder, '.', true, true);
             foreach ($fileList as $path) {
                 $path = str_replace(ECRPATH_EXTENSIONTEMPLATES . DS, '', $path);
                 if (false == JFolder::exists(dirname($tempDir . DS . $path))) {
                     JFolder::create(dirname($tempDir . DS . $path));
                 }
                 if (false == JFile::copy(ECRPATH_EXTENSIONTEMPLATES . DS . $path, $tempDir . DS . $path)) {
                     throw new Exception(sprintf(jgettext('Unable to copy the file %s to %s'), ECRPATH_EXTENSIONTEMPLATES . DS . $path, $tempDir . DS . $path));
                 }
                 $files[] = $tempDir . DS . $path;
             }
         }
     }
     $xml = new SimpleXMLElement('<install type="ecrextensiontemplate" version="' . ECR_VERSION . '"/>');
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->formatOutput = true;
     $domnode = dom_import_simplexml($xml);
     $domnode = $doc->importNode($domnode, true);
     $domnode = $doc->appendChild($domnode);
     $result = $doc->saveXML();
     if (false == JFile::write($tempDir . DS . 'manifest.xml', $result)) {
         throw new Exception(sprintf(jgettext('Unable to write file %s'), $tempDir . DS . 'manifest.xml'));
     }
     $files[] = $tempDir . DS . 'manifest.xml';
     $fileName = 'ecr_extension_templates' . date('Ymd_His') . '.tar.gz';
     if (!JFolder::create(ECRPATH_EXPORTS . DS . 'templates')) {
         throw new Exception(sprintf(jgettext('Unable to create the folder %s'), ECRPATH_EXPORTS . DS . 'templates'));
     }
     $result = EcrArchive::createTgz(ECRPATH_EXPORTS . DS . 'templates' . DS . $fileName, $files, 'gz', $tempDir);
     //-- This means error
     if (!$result->listContent()) {
         throw new Exception(jgettext('Error creating archive'));
     }
     return true;
 }