/** * Process install files. * * @throws EcrExceptionZiper * * @return EcrProjectZiper */ private function processInstall() { $installFiles = EcrProjectHelper::findInstallFiles($this->project); if (0 == count($installFiles['php'])) { return $this; } $srcDir = $this->temp_dir . DS . 'admin'; $destDir = $this->temp_dir . DS . 'install'; //-- Create 'install' folder in temp dir JFolder::create($destDir); //-- Copy install files from 'admin' to 'temp' foreach ($installFiles['php'] as $file) { $srcPath = $srcDir; $srcPath .= $file->folder ? DS . $file->folder : ''; $srcPath .= DS . $file->name; $destPath = $destDir; if ($file->folder == 'install') { $folder = ''; } else { $folder = str_replace('install' . DS, '', $file->folder); } if ($folder) { $destPath .= DS . $folder; //-- Create the folder JFolder::create($destPath); } if (JFile::copy($srcPath, $destPath . DS . $file->name)) { $this->logger->log('COPY INSTALL FILE<br />SRC: ' . $srcPath . '<br />DST: ' . $destPath . DS . $file->name); } else { $this->logger->log('COPY INSTALL FILE<br />SRC: ' . $srcPath . '<br />DST: ' . $destPath . DS . $file->name, 'ERROR copy file'); continue; } if (0 != strpos($file->name, 'install')) { continue; } if ($this->buildopts['createMD5']) { $format = 'po' == $this->project->langFormat ? '.po' : ''; $compressed = $this->buildopts['createMD5Compressed'] ? '_compressed' : ''; $fileContents = JFile::read(ECRPATH_EXTENSIONTEMPLATES . DS . 'std' . DS . 'md5check' . $compressed . $format . '.php'); $fileContents = str_replace('<?php', '', $fileContents); $this->project->addSubstitute('##ECR_MD5CHECK_FNC##', $fileContents); $fileContents = JFile::read(ECRPATH_EXTENSIONTEMPLATES . DS . 'std' . DS . 'md5check_call' . $format . '.php'); $fileContents = str_replace('<?php', '', $fileContents); $this->project->addSubstitute('##ECR_MD5CHECK##', $fileContents); $this->project->addSubstitute('ECR_COM_COM_NAME', $this->project->comName); $fileContents = JFile::read($destPath . DS . $file->name); $fileContents = $this->project->substitute($fileContents); } else { $this->project->addSubstitute('##ECR_MD5CHECK_FNC##', ''); $this->project->addSubstitute('##ECR_MD5CHECK##', ''); $fileContents = JFile::read($destPath . DS . $file->name); $fileContents = $this->project->substitute($fileContents); } if (JFile::write($destPath . DS . $file->name, $fileContents)) { $this->logger->logFileWrite('', 'install/install.php', $fileContents); } else { $this->logger->log('Failed to add MD5 install check routine to install.php', 'error'); } } //-- Delete install files from 'admin' foreach ($installFiles['php'] as $file) { $srcPath = $srcDir; $srcPath .= $file->folder ? DS . $file->folder : ''; $srcPath .= DS . $file->name; if (false == JFile::delete($srcPath)) { throw new EcrExceptionZiper(__METHOD__ . ' - Delete install file failed: ' . $srcPath); } $this->logger->log('INSTALL FILE DELETED<br />SRC: ' . $srcPath); } return $this; }
/** * Process install section. * * @throws Exception * @return EcrProjectManifest */ private function processInstall() { if ($this->project->type != 'component') { //-- Only components have install files //-- @todo change for 1.6 + ? return $this; } $installFiles = EcrProjectHelper::findInstallFiles($this->project); //-- PHP install scripts $this->manifest->addChild('scriptfile'); //-- SQL install scripts $install = $this->manifest->addChild('install'); $installSql = $install->addChild('sql'); $uninstall = $this->manifest->addChild('uninstall'); $uninstallSql = $uninstall->addChild('sql'); //-- J! 1.6+ update stuff $update = $this->manifest->addChild('update'); $updateSql = $update->addChild('schemas'); //-- SQL updates if (count($installFiles['sql_updates'])) { foreach ($installFiles['sql_updates'] as $file) { $schema = $updateSql->addChild('schemapath', $file->folder . '/' . $file->name); $schema->addAttribute('type', $file->name); } } //-- PHP if (count($installFiles['php'])) { if (count($installFiles['php']) > 2) { throw new Exception(sprintf('%s - Too many PHP install/uninstall files (%d)', __METHOD__, count($installFiles['php']))); } foreach ($installFiles['php'] as $file) { $dir = $file->folder ? $file->folder . '/' : ''; $dir = str_replace('\\', '/', $dir); if (strpos($file->name, 'install') === 0) { //-- Install $this->manifest->installfile = $dir . $file->name; } else { if (strpos($file->name, 'uninstall') === 0) { //-- Uninstall $this->manifest->uninstallfile = $dir . $file->name; } else { if (strpos($file->name, 'script') === 0) { //-- J 1.6 script file $this->manifest->scriptfile = $dir . $file->name; } else { throw new Exception(__METHOD__ . ' - Unsupported php file: ' . $file->name); } } } } } //-- SQL if (count($installFiles['sql'])) { foreach ($installFiles['sql'] as $file) { $dir = $file->folder ? $file->folder . '/' : ''; $dir = str_replace('\\', '/', $dir); if (strpos($file->name, 'install') === 0) { //--Install $sFile = $installSql->addChild('file', $dir . $file->name); } else { if (strpos($file->name, 'uninstall') === 0) { //--Uninstall $sFile = $uninstallSql->addChild('file', $dir . $file->name); } else { if (strpos($file->name, 'update') === 0) { //-- Update $sFile = $updateSql->addChild('file', $dir . $file->name); } else { throw new Exception(__METHOD__ . ' - Unsupported sql file: ' . $file->name); } } } $parts = explode('/', $dir); array_pop($parts); $driver = array_pop($parts); $sFile->addAttribute('driver', $driver); if (false == strpos($file->name, 'nonutf') && false == strpos($file->name, 'compat')) { $sFile->addAttribute('charset', 'utf8'); } } } return $this; }
/** * Install View. * * @return void */ private function install() { $this->installFiles = EcrProjectHelper::findInstallFiles($this->project); $this->setLayout('install'); }