/** * Copy the elements of a package. * * @throws EcrExceptionZiper * @return EcrProjectZiper */ private function copyPackageElements() { if ($this->project->type != 'package') { return $this; } if (0 == count($this->project->elements)) { return $this; } $this->logger->log('Copying Package elements'); foreach ($this->project->elements as $element => $path) { $this->ecr_project = JFactory::getApplication()->input->get('ecr_project'); //-- Get the project try { $project = EcrProjectHelper::getProject($element); } catch (Exception $e) { $this->logger->log('Unable to load the project ' . $element . ' - ' . $e->getMessage(), 'ERROR'); continue; } $ziper = new EcrProjectZiper(); $result = $ziper->create($project, $project->getPreset(), $this->buildopts); $files = $ziper->getCreatedFiles(); if (0 == count($files)) { $this->logger->log(sprintf('No packages files have been created for project %s', $element), 'ERROR', JLog::WARNING); continue; } $src = $files[0]->path; $fName = JFile::getName($src); //-- Set the elemnent path for manifest class $this->project->elements[$element] = $fName; $dest = $this->temp_dir . DS . $fName; if (JFile::copy($src, $dest)) { $this->logger->log(sprintf('Package %s copied from %s to %s', $element, $src, $dest)); } else { throw new EcrExceptionZiper(__METHOD__ . ' - ' . sprintf('Unable to create package %s try to copy from %s to %s', $element, $src, $dest)); } } return $this; }
/** * DoIt * * @throws Exception * @return void */ public function doExecute() { define('JPATH_BASE', THE_BUILD_PATH); define('JPATH_SITE', JPATH_BASE); define('JPATH_CACHE', JPATH_BASE . '/cache'); define('JPATH_ADMINISTRATOR', JPATH_BASE . '/administrator'); define('JPATH_COMPONENT', JPATH_ADMINISTRATOR . '/components/com_easycreator'); define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_COMPONENT); define('JPATH_INSTALLATION', ''); require JPATH_BASE . '/configuration.php'; require JPATH_BASE . '/libraries/cms/version/version.php'; $jversion = new JVersion(); define('JVERSION', $jversion->getShortVersion()); //-- Global constants require JPATH_COMPONENT . '/includes/defines.php'; //-- Global functions require JPATH_COMPONENT . '/includes/loader.php'; $buildOpts = array(); if ($this->input->get('v') || $this->input->get('verbose')) { $buildOpts[] = 'logging'; } if ($this->input->get('list')) { $this->printList(); return; } $projectName = $this->input->get('project'); if ('' == $projectName) { throw new Exception('Please specify a project with the option --project'); } $project = EcrProjectHelper::getProject($projectName); foreach ($project->buildOpts as $opt => $v) { //-- @todo this is ugly.. if ('1' == $v) { $buildOpts[] = $opt; } } $ziper = new EcrProjectZiper(); $preset = new EcrProjectModelBuildpreset(); $ziper->create($project, $preset, $buildOpts); $this->out('Finished =;)'); }
public function createPackage() { $input = JFactory::getApplication()->input; ob_start(); try { $result = new stdClass(); $buildopts = $input->get('buildopts', array(), 'array'); $presetName = $input->get('preset'); $buildOpts = array(); foreach ($buildopts as $v) { $buildOpts[$v] = true; } $project = EcrProjectHelper::getProject(); $ziper = new EcrProjectZiper(); $preset = $project->getPreset($presetName)->loadValues($buildopts); $result->result = $ziper->create($project, $preset, $buildOpts); $result->errors = $ziper->getErrors(); $result->downloadLinks = $ziper->getCreatedFiles(); $result->log = $ziper->printLog(); if ($result->errors) { $this->response->message = jgettext('Your ZIPfile has NOT been created'); $this->response->status = 1; $this->response->debug = '<ul><li>' . implode('</li><li>', $result->errors) . '</li></ul>'; } else { if (count($result->downloadLinks)) { $m = ''; $m .= jgettext('Your ZIPfile has been created sucessfully'); $m .= '<ul class="downloadLinks">'; $m .= '<li><strong>' . jgettext('Downloads') . '</strong></li>'; /* @var EcrProjectZiperCreatedfile $link */ foreach ($result->downloadLinks as $link) { $alt = $link->alternateDownload ? ' (<a href="' . $link->alternateDownload . '">' . $link->alternateDownload . '</a>)' : ''; $m .= '<li><a href="' . $link->downloadUrl . '">' . $link->name . '</a><' . $alt . '/li>'; } $m .= '</ul>'; $this->response->message = $m; } else { $this->response->message = jgettext('No download available'); $this->response->status = 1; } } if ($result->log) { $m = ''; $m .= '<div class="ecr_codebox_header" style="font-size: 1.4em;"' . 'onclick="toggleDiv(\'ecr_logdisplay\');">' . jgettext('Log File') . '</div>'; $m .= '<div id="ecr_logdisplay" style="display: none;">' . $result->log . '</div>'; $this->response->message .= $m; } } catch (Exception $e) { $this->response->debug = ECR_DEBUG ? nl2br($e) : ''; $this->response->message = $e->getMessage(); $this->response->status = 1; } $buffer = ob_get_clean(); if ($buffer) { $this->response->status = 1; $this->response->debug .= $buffer; } echo $this->response; jexit(); }