示例#1
0
 /**
  * Create test database and provide information for database access
  * @throws Exception
  */
 protected function setupTestDatabase()
 {
     // create database, same name as magento database, only appending '_test'
     if (false === $this->createDatabase($this->config->getDbName() . '_test')) {
         throw new Exception('Could not create test database');
     }
     // set access information in local.xml.phpunit
     $file = $this->config->getTarget() . '/app/etc/local.xml.phpunit';
     $db = sprintf('<dbname><\\![CDATA[%s_test]]><\\/dbname>', $this->config->getDbName());
     $cmd = sprintf('sed -i "s/<dbname>.*<\\/dbname>/%s/g" %s', $db, $file);
     exec($cmd, $result, $return);
     if (0 !== $return) {
         Logger::error('Failed to set db name for unit testing framework');
     }
     // unify base url, as ecomdev/magento needs it with protocol and trailing slash given
     $baseUrl = ltrim($this->config->getMagentoBaseUrl(), 'http://');
     $baseUrl = rtrim($baseUrl, '/');
     $baseUrl = "http://{$baseUrl}/";
     $baseUrl = '<base_url>' . str_replace('/', '\\/', $baseUrl) . '<\\/base_url>';
     $cmd = sprintf('sed -i "s/<base_url>.*<\\/base_url>/%s/g" %s', $baseUrl, $file);
     exec($cmd, $result, $return);
     if (0 !== $return) {
         Logger::error('Failed to set base url for unit testing framework');
     }
 }
示例#2
0
 public function execute()
 {
     $filename = $this->config->getTarget() . '/robots.txt';
     $lines = $this->config->plugins->RobotsTxt->lines->toArray();
     if (false === file_put_contents($filename, implode(PHP_EOL, $lines))) {
         Logger::error('An error occured while creating robots.txt', array(), false);
     }
 }
示例#3
0
 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()));
     }
 }
示例#4
0
 public function execute()
 {
     Mage::app('admin');
     if (!Mage::getSingleton('fastsimpleimport/import')) {
         Logger::error('Could not create dummy products. Please add extension %s to be installed', array('git://github.com/avstudnitz/AvS_FastSimpleImport.git'), false);
         return;
     }
     $settings = $this->config->plugins->{$this->getPluginName()};
     $countOfSimpleProducts = 0;
     $countOfConfigurableProducts = 0;
     $countOfBundleProducts = 0;
     $countOfGroupedProducts = 0;
     $countOfVirtualProducts = 0;
     $countOfDownloadProducts = 0;
     if ($settings instanceof \Zend_Config) {
         if ($settings->simpleProducts) {
             $countOfSimpleProducts = $settings->simpleProducts;
         }
         if ($settings->configurableProducts) {
             $countOfConfigurableProducts = $settings->configurableProducts;
         }
         if ($settings->bundleProducts) {
             $countOfBundleProducts = $settings->bundleProducts;
         }
         if ($settings->groupedProducts) {
             $countOfGroupedProducts = $settings->groupedProducts;
         }
         if ($settings->virtualProducts) {
             $countOfVirtualProducts = $settings->virtualProducts;
         }
         if ($settings->downloadProducts) {
             $countOfDownloadProducts = $settings->downloadProducts;
         }
     } else {
         $countOfSimpleProducts = $settings;
     }
     $data = array();
     $data = $this->getSimpleProducts($countOfSimpleProducts);
     /*
      * @todo
     $data = array_merge($data, $this->getConfigurableProducts($countOfConfigurableProducts));
     $data = array_merge($data, $this->getBundleProducts($countOfBundleProducts));
     $data = array_merge($data, $this->getGroupedProducts($countOfGroupedProducts));
     $data = array_merge($data, $this->getVirtualProducts($countOfVirtualProducts));
     $data = array_merge($data, $this->getDownloadProducts($countOfDownloadProducts));
     */
     $this->import($data);
 }
 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);
     }
 }
示例#6
0
 public function execute()
 {
     Mage::app('admin');
     $settings = $this->config->plugins->{$this->getPluginName()};
     if ($settings instanceof \Zend_Config) {
         foreach ($settings as $sku => $setting) {
             if ($setting instanceof \Zend_Config) {
                 $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
                 if (!$product->getId()) {
                     Logger::error('Product with SKU %s not found', array($sku), false);
                     continue;
                 }
                 $this->modifyProduct($product, $setting);
             } else {
                 Logger::error('Invalid configuration for SKU %s', array($sku), false);
             }
         }
     } else {
         Logger::error('Invalid configuration for plugin %s', array($this->getPluginName()), false);
     }
 }
示例#7
0
 protected function _getProcesses($setting)
 {
     $processes = array();
     if ($setting == 'all') {
         $collection = $this->_getIndexer()->getProcessesCollection();
         foreach ($collection as $process) {
             $processes[] = $process;
         }
     } else {
         if (!empty($setting)) {
             foreach ($setting as $code) {
                 $process = $this->_getIndexer()->getProcessByCode(trim($code));
                 if (!$process) {
                     Logger::error('Unknown indexer with code %s', array(trim($code)), false);
                 } else {
                     $processes[] = $process;
                 }
             }
         }
     }
     return $processes;
 }
示例#8
0
 /**
  * @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');
 }
示例#9
0
 /**
  * @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);
     }
 }
示例#10
0
 /**
  * Execute the MageCompatibility plugin
  */
 protected function _execute()
 {
     try {
         $this->_connectTagDatabase();
         $availableVersions = dibi::query('SELECT concat( m.edition, " ", m.version ) as Magento FROM magento m ORDER BY Magento')->fetchPairs();
         $supportedVersions = array();
         $extension = new Extension($this->_extensionPath);
         $methods = $extension->getUsedMagentoMethods();
         $classes = $extension->getUsedMagentoClasses();
         IssueHandler::addIssue(new Issue(array("extension" => $this->_extensionPath, "checkname" => $this->_pluginName, "type" => 'mage_compatibility', "comment" => sprintf('Extension uses %d classes and %d methods of Magento core', $classes->count(), $methods->count()), "failed" => true)));
         $incompatibleVersions = array();
         foreach ($availableVersions as $version) {
             $incompatibleVersions[$version] = array('classes' => array(), 'methods' => array(), 'constants' => array());
         }
         foreach ($classes as $class) {
             $class->setConfig($this->_settings);
             $supportedVersions = $class->getMagentoVersions();
             if (is_array($supportedVersions)) {
                 $tagIncompatibleVersions = array_diff($availableVersions, $supportedVersions);
                 foreach ($tagIncompatibleVersions as $version) {
                     $incompatibleVersions[$version]['classes'][] = $class->getName();
                 }
             }
         }
         foreach ($methods as $method) {
             $isExtensionMethod = false;
             $context = current($method->getContext());
             $method->setConfig($this->_settings);
             $supportedVersions = $method->getMagentoVersions();
             //echo $context['class'] . '->' . $method->getName() . ' ';
             if (false == is_array($supportedVersions)) {
                 continue;
             }
             $tagIncompatibleVersions = array_diff($availableVersions, $supportedVersions);
             foreach ($tagIncompatibleVersions as $version) {
                 $methodName = $method->getContext('class') . '->' . $method->getName() . '(' . implode(', ', $method->getParams()) . ')';
                 if ($extension->hasMethod($method->getName())) {
                     $methodName .= ' [maybe part of the extension]';
                     continue;
                 }
                 $incompatibleVersions[$version]['methods'][] = $methodName;
             }
         }
         $compatibleVersions = array();
         foreach ($incompatibleVersions as $version => $incompatibilities) {
             $message = '';
             $incompatibleClasses = array_unique($incompatibilities['classes']);
             $incompatibleMethods = array_unique($incompatibilities['methods']);
             $incompatibleConstants = array_unique($incompatibilities['constants']);
             if (0 < count($incompatibleClasses)) {
                 $message .= sprintf("<comment>The following classes are not compatible to Magento %s:</comment>\n  * %s\n", $version, implode("\n  * ", $incompatibleClasses));
             }
             if (0 < count($incompatibleMethods)) {
                 $message .= sprintf("<comment>The following methods are not compatible to Magento %s:</comment>\n  * %s\n", $version, implode("\n  * ", $incompatibleMethods));
             }
             if (0 < count($incompatibleConstants)) {
                 $message .= sprintf("<comment>The following constants are not compatible to Magento %s:</comment>\n  * %s\n", $version, implode("\n  * ", $incompatibleConstants));
             }
             if (0 < strlen($message)) {
                 IssueHandler::addIssue(new Issue(array("extension" => $this->_extensionPath, "checkname" => $this->_pluginName, "type" => 'mage_compatibility', "comment" => sprintf("<error>Extension is not compatible to Magento %s</error>\n%s", $version, $message), "failed" => true)));
             } else {
                 $compatibleVersions[] = $version;
             }
         }
         IssueHandler::addIssue(new Issue(array("extension" => $this->_extensionPath, "checkname" => $this->_pluginName, "type" => 'mage_compatibility', "comment" => 'Checked Magento versions: ' . implode(', ', $availableVersions) . "\n" . '* Extension seems to support following Magento versions: ' . implode(', ', $compatibleVersions), "failed" => false)));
         foreach (array_keys($incompatibleVersions) as $key) {
             if (0 == count($incompatibleVersions[$key]['classes']) && 0 == count($incompatibleVersions[$key]['methods']) && 0 == count($incompatibleVersions[$key]['constants'])) {
                 unset($incompatibleVersions[$key]);
             }
         }
         if ($this->_containsNoLatestVersion(array_keys($incompatibleVersions), 'CE')) {
             IssueHandler::addIssue(new Issue(array("extension" => $this->_extensionPath, "checkname" => $this->_pluginName, "type" => 'mage_compatibility', "comment" => sprintf('Extension supports Magento at least from CE version %s and EE version %s', $this->_settings->min->ce, $this->_settings->min->ee), "failed" => false)));
             return;
         }
     } catch (\Exception $e) {
         $this->setUnfinishedIssue();
         $message = is_array($e->getMessage()) ? $e->getMessage() : array($e->getMessage());
         Logger::error(implode(PHP_EOL, $message), array(), false);
         return;
     }
 }
示例#11
0
 /**
  * Clean test environment
  */
 protected function _cleanTestEnvironment()
 {
     if ($this->_settings->useJumpstorm == true) {
         try {
             // remove test source dir
             exec(sprintf('rm -rf %s', $this->_magentoTarget));
             //drop test databases
             $jumpstormConfig = new \Zend_Config_Ini($this->_settings->jumpstormIniFile, null, array('allowModifications' => true));
             $databaseConfig = $jumpstormConfig->common->db;
             if (0 == strlen($databaseConfig->password)) {
                 unset($databaseConfig->password);
             }
             $testDbNames = array($this->_testDbName, $this->_testDbName . '_test');
             foreach ($testDbNames as $dbName) {
                 $this->_dropTestDatabase($databaseConfig, $dbName);
             }
         } catch (\Exception $e) {
             Logger::error($e->getMessage(), array(), false);
         }
     }
 }