Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * Format a file name.
  *
  * @return void
  * @todo error handling
  */
 public function updateProjectName()
 {
     try {
         $project = EcrProjectHelper::getProject();
         $this->response->message = EcrProjectHelper::formatFileName($project, JFactory::getApplication()->input->getString('cst_format'));
     } catch (Exception $e) {
         $this->response->status = 1;
         $this->response->message = $e->getMessage();
         $this->response->debug = $e->getTraceAsString();
     }
     echo $this->response;
     jexit();
 }