Example #1
0
 /**
  * Process a SQL update file.
  *
  * @param EcrProjectBase $project        The project.
  * @param string         $installPath    Path to the project root.
  *
  * @return mixed
  */
 private function processSQLUpdate(EcrProjectBase $project, $installPath)
 {
     $dbType = 'mysql';
     $updater = new EcrDbUpdater($project, $dbType, $this->logger);
     if ($updater->versions) {
         $this->logger->log('Updating...');
         if ($updater->buildFromECRBuildDir()) {
             EcrHtml::message(jgettext('Update sql file has been written'));
         } else {
             EcrHtml::message(jgettext('Can not create the update sql file'), 'error');
         }
         return;
     }
     $this->logger->log('Initing...');
     $fileName = $project->version . '.sql';
     $fullPath = $installPath . '/sql/updates/' . $dbType . '/' . $fileName;
     if (JFile::exists($fullPath)) {
         EcrHtml::message(jgettext('Update sql already exists'), 'error');
         $this->logger->log('Update sql already exists in ' . $fullPath);
         return;
     }
     $contents = '';
     if (JFile::write($fullPath, $contents)) {
         EcrHtml::message(jgettext('Update sql file has been written'));
         $this->logger->logFileWrite('dbUpdate', $fullPath, $contents);
     } else {
         EcrHtml::message(jgettext('Can not create the update sql file'), 'error');
         $this->logger->logFileWrite('dbUpdate', $fullPath, $contents, 'Can not create the update sql file');
     }
 }
Example #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;
 }
Example #3
0
 /**
  * Insert a part to the project.
  *
  * @param array     $options   Options for inserting
  * @param EcrLogger $logger    The logger
  * @param boolean   $overwrite Overwrite existing files
  *
  * @return boolean
  */
 public function insertPart($options, EcrLogger $logger, $overwrite = false)
 {
     $input = JFactory::getApplication()->input;
     $element_scope = $input->getString('element_scope');
     $element_name = $input->getString('element_name');
     $element = $input->getString('element');
     if (false == isset($options->pathSource) || !$options->pathSource) {
         JFactory::getApplication()->enqueueMessage(jgettext('Invalid options'), 'error');
         $logger->log('Invalid options');
         return false;
     }
     /*
      * Define substitutes
      */
     $this->addSubstitute('ECR_ELEMENT_NAME', $element_name);
     $this->addSubstitute('ECR_LIST_POSTFIX', $this->listPostfix);
     /*
      * Process files
      */
     //-- @TODO ...
     $basePathDest = $element_scope == 'admin' ? JPATH_ADMINISTRATOR : JPATH_SITE;
     $basePathDest .= DS . 'components' . DS . $options->ecr_project;
     $files = JFolder::files($options->pathSource, '.', true, true, array('options', '.svn'));
     foreach ($files as $file) {
         $fName = str_replace($options->pathSource . DS, '', JPath::clean($file));
         $fName = str_replace('ecr_element_name', strtolower($element_name), $fName);
         $fName = str_replace('ecr_list_postfix', strtolower($this->listPostfix), $fName);
         //-- Check if file exists
         if (JFile::exists($basePathDest . DS . $fName) && !$overwrite) {
             //-- Replace AutoCode
             $ACName = "{$element_scope}.{$options->group}.{$options->part}.{$element}";
             if (array_key_exists($ACName, $this->autoCodes)) {
                 //-- Replace AutoCode
                 $fileContents = JFile::read($basePathDest . DS . $fName);
                 foreach ($this->autoCodes as $AutoCode) {
                     foreach ($AutoCode->codes as $key => $code) {
                         $fileContents = $AutoCode->replaceCode($fileContents, $key);
                     }
                 }
             } else {
                 JFactory::getApplication()->enqueueMessage(sprintf(jgettext('Autocode key %s not found'), $ACName), 'error');
                 return false;
             }
         } else {
             //-- Add new file(s)
             $fileContents = JFile::read($file);
             $subPackage = explode(DS, str_replace($options->pathSource . DS, '', $file));
             $subPackage = $subPackage[0];
             $subPackage = str_replace(JFile::getName($file), '', $subPackage);
             $subPackage = $subPackage ? $subPackage : 'Base';
             $this->addSubstitute('ECR_SUBPACKAGE', ucfirst($subPackage));
         }
         $this->substitute($fileContents);
         if (false == JFile::write($basePathDest . DS . $fName, $fileContents)) {
             JFactory::getApplication()->enqueueMessage(jgettext('Unable to write file'), 'error');
             return false;
         }
         $logger->logFileWrite($file, $basePathDest . DS . $fName, $fileContents);
     }
     if (!$this->update()) {
         return false;
     }
     return true;
 }
Example #4
0
 /**
  * Prints the log.
  *
  * @return string
  */
 public function printLog()
 {
     return $this->logger->printLog();
 }