/** * 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'); } }
/** * Create a MD5 checksum file. * * @throws EcrExceptionZiper * @return EcrProjectZiper */ private function createMD5() { if (!$this->preset->createMD5) { return $this; } $md5Str = ''; $fileList = JFolder::files($this->temp_dir, '.', true, true); foreach ($fileList as $file) { $file = JPath::clean($file); if ($this->preset->createMD5Compressed) { $path = str_replace($this->temp_dir . DS, '', $file); $parts = explode(DS, $path); $fName = array_pop($parts); $path = implode('/', $parts); $md5Str .= md5_file($file) . ' ' . $this->compressPath($path) . '@' . $fName . NL; } else { $md5Str .= md5_file($file) . ' ' . str_replace($this->temp_dir . DS, '', $file) . NL; } $md5Str = str_replace('\\', '/', $md5Str); } $subDir = JFolder::exists($this->temp_dir . DS . 'admin') ? 'admin' : 'site'; //-- @todo temp solution to put the md5 file in a sub folder for J! 1.6 not finding it... $subDir .= DS . 'install'; if (false == JFile::write($this->temp_dir . DS . $subDir . DS . 'MD5SUMS', $md5Str)) { throw new EcrExceptionZiper(__METHOD__ . ' - Can not create MD5SUMS File'); } $this->logger->logFileWrite('MD5SUMS', $this->temp_dir . DS . 'MD5SUMS', $md5Str); return $this; }
/** * Register an existing project. * * @param string $type Project type * @param string $name Project name * @param string $scope Project scope e.g. admin, site * * @return EcrProjectBase on success | false on error */ public function registerProject($type, $name, $scope = '') { //--Get component parameters $comParams = JComponentHelper::getParams('com_easycreator'); //-- Setup logging $options = array(); $opts = array('logging', 'hotlogging', 'files', 'profile'); foreach ($opts as $o) { if ($comParams->get($o)) { $options[] = $o; } } $options['fileName'] = date('ymd_Hi') . '_register.log'; $this->logger = EcrLogger::getInstance('ecr', $options); if (false == array_key_exists($type, EcrProjectHelper::getProjectTypes())) { JFactory::getApplication()->enqueueMessage(sprintf(jgettext('The project type %s is not defined yet'), $type), 'error'); $this->setError(sprintf(jgettext('The project type %s is not defined yet'), $type)); return false; } $project = EcrProjectHelper::newProject($type); $project->comName = $name; $project->scope = $scope; foreach (EcrEasycreator::$packFormats as $name => $ext) { if ($comParams->get($name)) { $project->buildOpts[$name] = '1'; } } for ($i = 1; $i < 5; $i++) { $project->buildOpts['custom_name_' . $i] = $comParams->get('custom_name_' . $i); } //-- Set the Joomla! compatibility version to the version we are actually running on $project->JCompat = ECR_JVERSION; $xmlPath = EcrProjectHelper::findManifest($project); if (false == $xmlPath) { JFactory::getApplication()->enqueueMessage(jgettext('No manifest file found'), 'error'); $this->setError(jgettext('No manifest file found')); return false; } $data = EcrProjectHelper::parseXMLInstallFile(JPATH_ROOT . DS . $xmlPath); $project->name = $data->name; $this->logger->log('Registering: ' . $project->type . ' - ' . $project->name . '<br />' . 'aka "' . $project->comName . '"<br />scope: ' . $project->scope); $pXml = $project->update(); if (false == $pXml) { $this->logger->log('', 'Unable to create EasyCreator manifest'); $this->logger->writeLog(); return false; } else { $this->logger->log('EasyCreator manifest created'); $this->logger->logFileWrite('', '', $pXml); } $this->logger->log('FINISHED'); $this->logger->writeLog(); return $project; }
/** * 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; }