Example #1
0
File: Atos.php Project: bibich/Atos
 public function update($currentVersion, $newVersion, ConnectionInterface $con = null)
 {
     // Migrate old configuration
     if (null === self::getConfigValue('atos_merchantId', null)) {
         if (null !== ($atosConfigs = ConfigQuery::create()->filterByName('atos_%', Criteria::LIKE)->find())) {
             /** @var Config $atosConfig */
             foreach ($atosConfigs as $atosConfig) {
                 Atos::setConfigValue($atosConfig->getName(), $atosConfig->getValue());
                 $atosConfig->delete($con);
             }
         }
     }
     parent::update($currentVersion, $newVersion, $con);
 }
Example #2
0
 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'));
     }
 }