protected function modifyProduct(\Mage_Catalog_Model_Product $product, \Zend_Config $settings) { foreach ($settings as $attribute => $value) { $product->setData($attribute, $value); Logger::log('* change attribute <comment>%s</comment> of product #%d: "%s"', array($attribute, $product->getId(), $value)); } $product->save(); }
protected function _checkout($targetPath, $branch) { Logger::log('Git checkout %s', array($branch)); $command = sprintf('cd %s; git checkout %s 2>&1; cd -', $targetPath, $branch); exec($command, $result, $return); if (0 !== $return) { throw new Exception(implode(PHP_EOL, $result)); } }
public function execute() { Mage::app('admin'); \Mage_Core_Model_Resource_Setup::applyAllUpdates(); \Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); try { $this->setup(); } catch (Exception $e) { $msg .= $e->getMessage() . ' (' . $e->getFile() . ' l. ' . $e->getLine() . ")\n"; Logger::error('An error occured while initializing InitGermanSetup:', array(), false); Logger::log('%s (%s, line %s)', array($e->getMessage(), $e->getFile(), $e->getLine())); } }
public function copy($target, $branch = 'master') { if (!file_exists($this->_source)) { throw new Exception("Source directory does not exist: '{$this->_source}'"); } // make sure that source ends with directory separator // as we want to copy its contents, not the directory itself $this->_source = rtrim($this->_source, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; Logger::log('Copy files from %s', array($this->_source)); $command = sprintf('rsync -a -h %s %s 2>&1', $this->_source, $target); Logger::log($command); exec($command, $result, $return); if (0 !== $return) { throw new Exception("Could not copy files to {$target}"); } }
public function execute() { $settings = $this->config->plugins->ApplyConfigSettings; if ($settings instanceof \Zend_Config) { foreach ($this->config->plugins->ApplyConfigSettings as $name => $setting) { if ($setting instanceof \Zend_Config && $setting->path && isset($setting->value)) { Mage::getModel('eav/entity_setup', 'core_setup')->setConfigData($setting->path, $setting->value); Logger::log('* Applied setting %s', array($name)); } else { Logger::error('Did not apply setting %s', array($name), false); } } } else { Logger::error('Invalid configuration for plugin ApplyConfigSettings', array(), false); } }
public function execute() { $settings = $this->config->plugins->Reindex; if ($settings instanceof \Zend_Config) { $processes = $this->_getProcesses($settings); foreach ($processes as $process) { $code = $process->getIndexer()->getName(); /* @var $process Mage_Index_Model_Process */ try { Logger::comment('* rebuilding %s', array(trim($code))); //$process->reindexEverything(); Logger::log('* Index <info>%s</info> was rebuilt successfully', array(trim($code))); } catch (Mage_Core_Exception $e) { Logger::error('An error occured while rebuilding index %s: %s', array(trim($code), $e->getMessage()), false); } catch (Exception $e) { Logger::error('A strange error occured while rebuilding index %s: %s', array(trim($code), $e->getMessage()), false); } } } else { Logger::error('Invalid configuration for plugin Reindex', array(), false); } }
/** * @see vendor/symfony/src/Symfony/Component/Console/Command/Symfony\Component\Console\Command.Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output) { $this->preExecute($input, $output); $this->initMagento(); $plugins = $this->config->getPlugins(); foreach ($plugins as $name => $settings) { // check if plugin was defined in ini, but disabled if ('0' === $settings->enabled) { Logger::log('Skipping plugin "%s"', array($name)); continue; } // set path to plugin by convention $path = $this->getBasePath() . 'plugins' . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR; // load script file $file = $path . $name . '.php'; if (!file_exists($file)) { Logger::error('Could not find plugin "%s"', array($name), $stop = false); Logger::log('Expected it at path "%s"', array($path)); continue; } // load default jumpstorm config for plugin execution $pluginConfig = $this->config; $customIni = $settings->ini; if (null !== $customIni && file_exists($customIni)) { unset($settings->ini); // add custom config settings, if given $pluginConfig = new Config($customIni, null, array('allowModifications' => true)); $pluginConfig->merge($this->config); } Logger::comment(sprintf('Running plugin "%s"', $name)); $class = "{$name}\\{$name}"; $plugin = new $class($pluginConfig); $plugin->execute(); Logger::notice(sprintf('Finished running plugin "%s"', $name)); } Logger::notice('Done'); }
/** * @see vendor/symfony/src/Symfony/Component/Console/Command/Symfony\Component\Console\Command.Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output) { $this->config = new Config($input->getOption('config'), null, array('allowModifications' => true)); $this->config->setOutput($output); $this->config->setCommand($this); $this->config->setBaseDirPath($this->getBasePath()); if ($input->getOption('no-interaction')) { $this->config->disableInteractivity(); } Logger::setOutputInterface($output); if ($input->getOption('quiet')) { Logger::setVerbosity(Logger::VERBOSITY_NONE); } if ($input->getOption('verbose')) { Logger::setVerbosity(Logger::VERBOSITY_MAX); } if ($input->getOption('user-token')) { Logger::setToken($input->getOption('user-token')); $this->config->token = $input->getOption('user-token'); } if ($input->getOption('php-option')) { $this->config->phpOptions = explode(',', $input->getOption('php-option')); foreach ($this->config->phpOptions as $options) { list($option, $value) = explode('=', $options); ini_set($option, $value); } } $results = array(); foreach (explode(',', $input->getArgument('extensions')) as $extensionPath) { $extensionPath = realpath($extensionPath); //get vendor, name and version of extension $this->getExtensionAttributes($input, $extensionPath); $plugins = $this->config->getPlugins(); foreach ($plugins as $name => $settings) { $results[$extensionPath] = 0; // check if plugin was defined in ini, but disabled if ('0' === $settings->checkEnabled) { Logger::log('Skipping plugin "%s"', array($name)); continue; } // set path to plugin by convention $path = $this->getBasePath() . 'plugins' . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR; // load script file $file = $path . $name . '.php'; if (!file_exists($file)) { Logger::error('Could not find plugin "%s"', array($name), $stop = false); Logger::log('Expected it at path "%s"', array($path)); continue; } // load default judge config for plugin execution $pluginConfig = $this->config; $customIni = $settings->ini; if (null !== $customIni && file_exists($customIni)) { unset($settings->ini); // add custom config settings, if given $pluginConfig = new Config($customIni, null, array('allowModifications' => true)); $pluginConfig->merge($this->config); } $class = "{$name}\\{$name}"; $plugin = new $class($pluginConfig); Logger::addCheck($extensionPath, $name); Logger::registerCheck($extensionPath, $name); $plugin->execute($extensionPath); } //swap logger output $logger = $this->config->getLogger(); foreach ($logger as $name => $settings) { if ($name == 'output' && $settings === 'webservice' | $settings === 'console') { Logger::setLoggerOutput($settings); } if ($name == 'user') { Logger::setUser($settings); } if ($name == 'password') { Logger::setPassword($settings); } if ($name == 'host') { Logger::setHost($settings); } } Logger::printResults($extensionPath); $this->generateResultHtml($extensionPath); } }
/** * Create empty database. Any old database with the same name gets dropped. * @todo use built-in mysql commands instead of calling exec() * * @return boolean true on success, false otherwise */ protected function createDatabase($dbName) { // prepare mysql command: user, host and password $mysql = $this->prepareMysqlCommand(); // recreate database if it already exists Logger::log('Creating database %s', array($dbName)); exec(sprintf('%s -e \'DROP DATABASE IF EXISTS `%s`\'', $mysql, $dbName), $result, $return); exec(sprintf('%s -e \'CREATE DATABASE `%s`\'', $mysql, $dbName), $result, $return); return 0 === $return; }
/** * Extension files are installed to .modman directory before deployment, * so create that directory if necessary * * @return string Absolute path to extension directory */ private function createExtensionFolder() { $this->validateTarget($this->config->getTarget()); $folder = $this->getExtensionFolder(); if (!is_dir($folder)) { Logger::log('Creating extension folder %s', array($folder)); mkdir($folder); } return $folder; }
/** * Execute Magento's install.php * * @param string $target Absolute directory name (Magento root) * @throws Exception */ protected function runMageScript($target) { Logger::log("Executing installation via install.php"); $this->setPermissions($target); if (file_exists($target . '/app/etc/local.xml')) { unlink($target . '/app/etc/local.xml'); } $cmd = sprintf('php %s%sinstall.php -- ', $target, DIRECTORY_SEPARATOR); $cmd .= implode(' ', array('--license_agreement_accepted "yes"', '--locale "de_DE"', '--timezone "Europe/Berlin"', '--default_currency "EUR"', '--db_host "' . $this->config->getDbHost() . '"', '--db_name "' . $this->config->getDbName() . '"', '--db_user "' . $this->config->getDbUser() . '"', '--db_pass "' . $this->config->getDbPass() . '"', '--db_prefix "' . $this->config->getDbPrefix() . '"', '--session_save "files"', '--admin_frontend "admin"', '--url "' . $this->config->getMagentoBaseUrl() . '"', '--skip_url_validation', '--use_rewrites "yes"', '--use_secure "no"', '--secure_base_url "' . $this->config->getMagentoBaseUrl() . '"', '--use_secure_admin "no"', '--admin_firstname "' . $this->config->getAdminFirstname() . '"', '--admin_lastname "' . $this->config->getAdminLastname() . '"', '--admin_email "' . $this->config->getAdminEmail() . '"', '--admin_username "' . $this->config->getAdminUser() . '"', '--admin_password "' . $this->config->getAdminPass() . '"')); exec($cmd, $result, $return); if (0 !== $return) { throw new Exception(sprintf('Installation via install.php failed, result: %s', implode(PHP_EOL . ' ', $result))); } // reindexing data if (file_exists(sprintf('%s%sshell/indexer.php', $target, DIRECTORY_SEPARATOR))) { $cmd = sprintf('php %s%sshell/indexer.php reindexall', $target, DIRECTORY_SEPARATOR); exec($cmd, $result, $return); if (0 !== $return) { throw new Exception('Failed to rebuild index'); } } else { Logger::comment('Could not find indexer at %s/shell/indexer.php, but its existance depends on Magento version', array($target)); } $this->setPermissions($target); }
/** * Check if all prerequisites for running unit tests are fullfilled or can * be fulfilled by using Jumpstorm. * * @param string $extensionPath Path to the extension to be evaluated * @throws \Exception */ protected function _setupUnitTestEnvironment($extensionPath) { /** * getting the neccessary information like magento target from * the jumpstorm configuration even jumpstorm is not used to set up * the test environment */ if (!$this->_settings->jumpstormIniFile) { throw new \Exception("Required information missing in ini file: plugins.CodeCoverage.jumpstormIniFile"); } $jumpstormConfig = new \Zend_Config_Ini($this->_settings->jumpstormIniFile, null, array('allowModifications' => true)); // check if required ini section is given if (!$jumpstormConfig->common) { throw new \Exception("Required information missing in jumpstorm ini file: [common]"); } if ($this->_config->token) { $jumpstormConfig->common->magento->target = $jumpstormConfig->common->magento->target . '_' . $this->_config->token; $jumpstormConfig->common->db->name = $jumpstormConfig->common->db->name . '_' . $this->_config->token; } $this->_magentoTarget = rtrim($jumpstormConfig->common->magento->target, DIRECTORY_SEPARATOR); $this->_testDbName = $jumpstormConfig->common->db->name; // import test environment configuration from console: [extensions] section $jumpstormConfig->extensions = array('extension' => array('source' => $extensionPath)); // force (re)installation using jumpstorm if ($this->_settings->useJumpstorm) { $requiredSections = array('magento', 'unittesting'); foreach ($requiredSections as $section) { if (!$jumpstormConfig->{$section}) { throw new \Exception("Required information missing in jumpstorm ini file: [{$section}]"); } } $iniFile = 'tmp/jumpstorm' . (string) $this->_config->token . '.ini'; $writer = new \Zend_Config_Writer_Ini(); $writer->write($iniFile, $jumpstormConfig); $executable = 'vendor/netresearch/jumpstorm/jumpstorm'; $params = ''; if (Logger::VERBOSITY_MAX == Logger::getVerbosity()) { $params .= ' -v'; } $command = sprintf('%s magento -c %s %s', $executable, $iniFile, $params) . ' && ' . sprintf('%s unittesting -c %s %s', $executable, $iniFile, $params) . ' && ' . sprintf('%s extensions -c %s %s', $executable, $iniFile, $params); Logger::notice('Setting up Magento environment via Jumpstorm'); $output = $this->_executeCommand($command); if (Logger::VERBOSITY_MAX == Logger::getVerbosity()) { Logger::log(implode("\n", $output)); } unlink($iniFile); } }
/** * Sync extension files from .modman to target directories * * @param string $alias */ protected function deployExtension($alias) { // detect location of modman file, if available $modmanFile = $this->locateModmanFile(); if ($modmanFile) { // if modman file was found, deploy via modman // alias may have to be changed to subdirectory $pattern = sprintf("|^%s/(.+)/%s\$|", $this->extensionRootDir, 'modman'); preg_match($pattern, $modmanFile, $matches); $alias = $matches[1]; Logger::log('Deploying extension %s via modman', array($alias)); $command = sprintf('cd %s; modman deploy %s --force', $this->magentoRoot, $alias); exec($command, $result, $return); } else { // deploy via rsync otherwise Logger::log('Deploying extension %s via rsync', array($alias)); $command = sprintf('rsync -a -h --exclude="doc/*" --exclude="*.git" %s %s 2>&1', $this->extensionDir . DIRECTORY_SEPARATOR, $this->magentoRoot); exec($command, $result, $return); } if (0 !== $return) { throw new Exception("Could not deploy extension {$alias}"); } }