protected function execute(InputInterface $input, OutputInterface $output) { $this->init($input); // Main insert.sql file $content = file_get_contents(THELIA_SETUP_DIRECTORY . 'insert.sql.tpl'); $version = Version::parse(); $content = $this->parser->renderString($content, $version, false); if (false === file_put_contents(THELIA_SETUP_DIRECTORY . 'insert.sql', $content)) { $output->writeln("Can't write file " . THELIA_SETUP_DIRECTORY . 'insert.sql'); } else { $output->writeln("File " . THELIA_SETUP_DIRECTORY . 'insert.sql generated successfully.'); } // sql update files $finder = Finder::create()->name('*.tpl')->depth(0)->in(THELIA_SETUP_DIRECTORY . 'update' . DS . 'tpl'); /** @var \SplFileInfo $file */ foreach ($finder as $file) { $content = file_get_contents($file->getRealPath()); $content = $this->parser->renderString($content, [], false); $destination = THELIA_SETUP_DIRECTORY . 'update' . DS . 'sql' . DS . $file->getBasename('.tpl'); if (false === file_put_contents($destination, $content)) { $output->writeln("Can't write file " . $destination); } else { $output->writeln("File " . $destination . ' generated successfully.'); } } }
/** * @dataProvider compareProvider */ public function testCompare($version, $expression, $result, $strict = false, $message = null) { if (null === $message) { $message = sprintf("Version: %s, expression: %s, expected: %s", $version, $expression, $result ? "true" : "false"); } $this->assertSame($result, Tester::test($version, $expression, $strict), $message); }
public function configure() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, 'forcephone', AccessManager::UPDATE))) { return $response; } $configurationForm = $this->createForm('forcephone_configuration'); $message = null; try { $form = $this->validateForm($configurationForm); // Get the form field values $data = $form->getData(); foreach ($data as $name => $value) { if (is_array($value)) { $value = implode(';', $value); } ForcePhone::setConfigValue($name, $value); } // Log configuration modification $this->adminLogAppend("forcephone.configuration.message", AccessManager::UPDATE, "ForcePhone configuration updated"); // Redirect to the success URL, if ($this->getRequest()->get('save_mode') == 'stay') { // If we have to stay on the same page, redisplay the configuration page/ $url = '/admin/module/ForcePhone'; } else { // If we have to close the page, go back to the module back-office page. $url = '/admin/modules'; } return $this->generateRedirect(URL::getInstance()->absoluteUrl($url)); } catch (FormValidationException $ex) { $message = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { $message = $ex->getMessage(); } $this->setupFormErrorContext($this->getTranslator()->trans("ForcePhone configuration", [], ForcePhone::DOMAIN_NAME), $message, $configurationForm, $ex); // Before 2.2, the errored form is not stored in session if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) { return $this->render('module-configure', ['module_code' => 'ForcePhone']); } else { return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/ForcePhone')); } }
public function testVirtualProductDelivery() { $modulePath = THELIA_MODULE_DIR . "VirtualProductDelivery"; $moduleValidator = new ModuleValidator($modulePath, $this->getStubTranslator()); $moduleDescriptor = $moduleValidator->getModuleDescriptor(); $this->assertInstanceOf('SimpleXMLElement', $moduleDescriptor); $this->assertEquals("2", $moduleValidator->getModuleVersion()); $moduleDefinition = $moduleValidator->getModuleDefinition(); $this->assertInstanceOf('Thelia\\Module\\Validator\\ModuleDefinition', $moduleDefinition); $this->assertEquals("VirtualProductDelivery", $moduleDefinition->getCode()); $this->assertEquals("VirtualProductDelivery\\VirtualProductDelivery", $moduleDefinition->getNamespace()); $this->assertEquals(2, count($moduleDefinition->getLanguages())); $this->assertEquals(0, count($moduleDefinition->getDependencies())); $this->assertEquals(1, count($moduleDefinition->getAuthors())); $this->assertEquals("", $moduleDefinition->getDocumentation()); $this->assertEquals("", $moduleDefinition->getLogo()); $this->assertEquals("2.2.0", $moduleDefinition->getTheliaVersion()); $this->assertTrue(Version::test(Thelia::THELIA_VERSION, $moduleDefinition->getTheliaVersion(), false, ">=")); // validate $moduleValidator->validate(false); }
protected function checkModuleDependencies() { $errors = []; foreach ($this->moduleDefinition->getDependencies() as $dependency) { $module = ModuleQuery::create()->findOneByCode($dependency[0]); $pass = false; if (null !== $module) { if ($module->getActivate() === BaseModule::IS_ACTIVATED) { if ("" == $dependency[1] || Version::test($module->getVersion(), $dependency[1], false, ">=")) { $pass = true; } } } if (false === $pass) { if ('' !== $dependency[1]) { $errors[] = $this->getTranslator()->trans('%module (version: %version)', ['%module' => $dependency[0], '%version' => $dependency[1]]); } else { $errors[] = sprintf('%s', $dependency[0]); } } } if (count($errors) > 0) { $errorsMessage = $this->getTranslator()->trans('To activate module %name, the following modules should be activated first: %modules', ['%name' => $this->moduleDirName, '%modules' => implode(', ', $errors)]); throw new ModuleException($errorsMessage); } }
public function getWebVersion() { $url = "http://thelia.net/version.php"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($curl, CURLOPT_TIMEOUT, 5); $res = curl_exec($curl); try { if (Version::parse($res)) { return $res; } } catch (\Exception $e) { return null; } }
/** * @dataProvider exceptionParseProvider * @expectedException InvalidArgumentException */ public function testExceptionParse($version) { Tester::parse($version); }
public function process() { $this->updatedVersions = array(); $currentVersion = $this->getCurrentVersion(); $this->log('debug', "start update process"); if (true === $this->isLatestVersion($currentVersion)) { $this->log('debug', "You already have the latest version. No update available"); throw new UpToDateException('You already have the latest version. No update available'); } $index = array_search($currentVersion, $this->version); $this->connection->beginTransaction(); $database = new Database($this->connection); $version = null; try { $size = count($this->version); for ($i = ++$index; $i < $size; $i++) { $version = $this->version[$i]; $this->updateToVersion($version, $database); $this->updatedVersions[] = $version; } $currentVersion = Version::parse(); $this->log('debug', sprintf('setting database configuration to %s', $currentVersion['version'])); $updateConfigVersion = ['thelia_version' => $currentVersion['version'], 'thelia_major_version' => $currentVersion['major'], 'thelia_minus_version' => $currentVersion['minus'], 'thelia_release_version' => $currentVersion['release'], 'thelia_extr_version' => $currentVersion['extra']]; foreach ($updateConfigVersion as $name => $value) { ConfigQuery::write($name, $value); } $this->connection->commit(); $this->log('debug', 'update successfully'); } catch (\Exception $e) { $this->connection->rollBack(); $this->log('error', sprintf('error during update process with message : %s', $e->getMessage())); $ex = new UpdateException($e->getMessage(), $e->getCode(), $e->getPrevious()); $ex->setVersion($version); throw $ex; } $this->log('debug', 'end of update processing'); return $this->updatedVersions; }
public function configure() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, 'atos', AccessManager::UPDATE))) { return $response; } $configurationForm = $this->createForm('atos_configuration'); $message = null; try { $form = $this->validateForm($configurationForm); // Get the form field values $data = $form->getData(); foreach ($data as $name => $value) { if (is_array($value)) { $value = implode(';', $value); } Atos::setConfigValue($name, $value); } $merchantId = $data['atos_merchantId']; $this->checkExecutable('request'); $this->checkExecutable('response'); $this->copyDistFile('parmcom', $merchantId); $certificateFile = $this->copyDistFile('certif.fr', $merchantId); // Write certificate if (!@file_put_contents($certificateFile, $data['atos_certificate'])) { throw new FileException($this->getTranslator()->trans("Failed to write certificate data in file '%file'. Please check file permission", ['%file' => $certificateFile], Atos::MODULE_DOMAIN)); } // Log configuration modification $this->adminLogAppend("atos.configuration.message", AccessManager::UPDATE, "Atos configuration updated"); // Redirect to the success URL, if ($this->getRequest()->get('save_mode') == 'stay') { // If we have to stay on the same page, redisplay the configuration page/ $url = '/admin/module/Atos'; } else { // If we have to close the page, go back to the module back-office page. $url = '/admin/modules'; } return $this->generateRedirect(URL::getInstance()->absoluteUrl($url)); } catch (FormValidationException $ex) { $message = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { $message = $ex->getMessage(); } $this->setupFormErrorContext($this->getTranslator()->trans("Atos configuration", [], Atos::MODULE_DOMAIN), $message, $configurationForm, $ex); // Before 2.2, the errored form is not stored in session if (Version::test(Thelia::THELIA_VERSION, '2.2', false, "<")) { return $this->render('module-configure', ['module_code' => 'Atos']); } else { return $this->generateRedirect(URL::getInstance()->absoluteUrl('/admin/module/Atos')); } }