Exemple #1
0
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con);
     $database->insertSql(null, [__DIR__ . "/Config/create.sql", __DIR__ . "/Config/insert.sql"]);
     $this->loadBackOfficeTranslationResources();
     $this->createPopInImageFolder();
 }
 public function testCreateSqlRuleGeneration()
 {
     $generator = new RuleGenerator();
     $generator->doGenerate($this->event);
     // Test file generation
     $this->assertFileExists($createFile = $this->getStreamPath("Config/create.sql"));
     // Test that the table doesn't exist
     /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */
     $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'");
     $this->assertEquals(0, $stmt->count());
     // Test that the file has the correct behavior
     $db = new Database($this->con);
     $db->insertSql(null, [$createFile]);
     // Now it exists
     /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */
     $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'");
     $this->assertEquals(1, $stmt->count());
     // Insert a new value in the table
     $this->con->exec("INSERT INTO `example_table`(`visible`, `position`) VALUES(1, 42)");
     // Check that the value exists
     $stmt = $this->con->query("SELECT * FROM `example_table`");
     $this->assertEquals(1, $stmt->count());
     // Then test that it doesn't crash if we apply the script again
     $db = new Database($this->con);
     $db->insertSql(null, [$createFile]);
     // Check that the previous entry still exists ( proves that there is no DROP TABLE )
     $stmt = $this->con->query("SELECT * FROM `example_table`");
     $fetched = $stmt->fetch(\PDO::FETCH_ASSOC);
     $this->assertTrue(is_array($fetched));
     $this->assertArrayHasKey("position", $fetched);
     $this->assertArrayHasKey("visible", $fetched);
     $this->assertEquals("1", $fetched["visible"]);
     $this->assertEquals("42", $fetched["position"]);
 }
Exemple #3
0
    public function postActivation(ConnectionInterface $con = null)
    {
        $database = new Database($con);
        $database->insertSql(null, [__DIR__ . '/Config/insert.sql']);
        /* insert the images from image folder if first module activation */
        $module = $this->getModuleModel();
        if (ModuleImageQuery::create()->filterByModule($module)->count() == 0) {
            $this->deployImageFolder($module, sprintf('%s/media', __DIR__), $con);
        }
        /* set module description */
        $enUSDescription = <<<US_DESC
            Discover delivery Predict:
            <ul>
                <li>You place your order and choose to have it delivered with Predict by Exapaq</li>
                <li>Once your order is prepared, we send you an SMS with several choices of dates and delivery slots</li>
                <li>You select the date and the time slot that suits you by answering directly by SMS (price of a standard SMS) or by going to the space available on <a href="http://destinataires.exapaq.com">http://destinataires.exapaq.com</a> Recipient</li>
                <li>The day of delivery, you will receive an SMS reminding you the time slot.</li>
            </ul>
US_DESC;
        $frFRDescription = <<<FR_DESC
            Découvrez la livraison Predict :
            <ul>
                <li>Vous faites votre commande et choisissez de vous faire livrer avec Predict par Exapaq</li>
                <li>Une fois votre commande préparée, nous vous envoyons un SMS avec plusieurs choix de dates et créneaux horaires de livraison</li>
                <li>Vous sélectionnez la date et le créneau qui vous conviennent le mieux en répondant directement par SMS (prix d’un SMS standard) ou en allant sur l’Espace Destinataire disponible sur <a href="http://destinataires.exapaq.com">http://destinataires.exapaq.com</a></li>
                <li>Le jour de la livraison, vous recevez un SMS vous rappelant le créneau horaire.</li>
            </ul>
FR_DESC;
        $this->getModuleModel()->setLocale()->setDescription($enUSDescription)->setLocale("fr_FR")->setDescription($frFRDescription)->save();
    }
Exemple #4
0
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con);
     $database->insertSql(null, [__DIR__ . "/Config/create.sql"]);
     $this->initializeConfig();
     $this->initializeMessage();
 }
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con->getWrappedConnection());
     $database->insertSql(null, [__DIR__ . '/Config/thelia.sql']);
     // Add order-invoice.before-discount hook if not already defined
     if (null === HookQuery::create()->findOneByCode('order-invoice.before-discount')) {
         try {
             $hookEvent = new HookCreateEvent();
             $hookEvent->setCode('order-invoice.before-discount')->setType(TemplateDefinition::FRONT_OFFICE)->setNative(false)->setActive(true)->setLocale('en_US')->setTitle("Before discount code form block");
             $this->getDispatcher()->dispatch(TheliaEvents::HOOK_CREATE, $hookEvent);
             if ($hookEvent->hasHook()) {
                 // Assign module to this hook
                 $moduleHookEvent = new ModuleHookCreateEvent();
                 $moduleHookEvent->setModuleId($this->getModuleId())->setHookId($hookEvent->getHook()->getId())->setClassname('creditaccount.order_invoice.hook')->setMethod('orderInvoiceForm');
                 // Activate module hook
                 $this->getDispatcher()->dispatch(TheliaEvents::MODULE_HOOK_CREATE, $moduleHookEvent);
                 if ($moduleHookEvent->hasModuleHook()) {
                     $event = new ModuleHookToggleActivationEvent($moduleHookEvent->getModuleHook());
                     $this->getDispatcher()->dispatch(TheliaEvents::MODULE_HOOK_TOGGLE_ACTIVATION, $event);
                 }
             }
         } catch (\Exception $ex) {
             throw new TheliaProcessException(Translator::getInstance()->trans("Failed to put module in 'order-invoice.before-discount' hook (%err)", ['%err' => $ex->getMessage()]), $ex);
         }
     }
 }
Exemple #6
0
 public function postActivation(ConnectionInterface $con = null)
 {
     $languages = LangQuery::create()->find();
     ConfigQuery::write(self::CONFIG_ENABLED, self::DEFAULT_ENABLED);
     ConfigQuery::write(self::CONFIG_THRESHOLD, self::DEFAULT_THRESHOLD);
     ConfigQuery::write(self::CONFIG_EMAILS, self::DEFAULT_EMAILS);
     // create new message
     if (null === MessageQuery::create()->findOneByName('stockalert_customer')) {
         $message = new Message();
         $message->setName('stockalert_customer')->setHtmlTemplateFileName('alert-customer.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('alert-customer.txt')->setTextLayoutFileName('')->setSecured(0);
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle($this->trans('Stock Alert - Customer', [], $locale));
             $message->setSubject($this->trans('Product {$product_title} is available again', [], $locale));
         }
         $message->save();
         $message = new Message();
         $message->setName('stockalert_administrator')->setHtmlTemplateFileName('alert-administrator.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('alert-administrator.txt')->setTextLayoutFileName('')->setSecured(0);
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle($this->trans('Stock Alert - Administrator', [], $locale));
             $message->setSubject($this->trans('Product {$product_title} is (nearly) out of stock', [], $locale));
         }
         $message->save();
     }
     try {
         RestockingAlertQuery::create()->findOne();
     } catch (\Exception $e) {
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . '/Config/thelia.sql']);
     }
 }
 public function postActivation(ConnectionInterface $con = null)
 {
     if (!self::getConfigValue('is_initialized', false)) {
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . "/Config/thelia.sql"]);
         self::setConfigValue('is_initialized', true);
     }
 }
 public function destroy(ConnectionInterface $con = null, $deleteModuleData = false)
 {
     parent::destroy($con, $deleteModuleData);
     if (!is_null($con) && $deleteModuleData === true) {
         $database = new Database($con);
         $database->insertSql(null, array(__DIR__ . '/Config/delete.sql'));
     }
 }
Exemple #9
0
 public function destroy(ConnectionInterface $con = null, $deleteModuleData = false)
 {
     if ($deleteModuleData) {
         $database = new Database($con);
         $database->execute('drop table `atos_currency`');
         MessageQuery::create()->findOneByName(self::CONFIRMATION_MESSAGE_NAME)->delete();
     }
 }
 public function destroy(ConnectionInterface $con = null, $deleteModuleData = false)
 {
     if (!$deleteModuleData) {
         return;
     }
     $database = new Database($con);
     $database->insertSql(null, [__DIR__ . "/Config/delete.sql"]);
 }
Exemple #11
0
 protected function updateToVersion($version, Database $database, Tlog $logger)
 {
     if (file_exists(THELIA_ROOT . '/setup/update/' . $version . '.sql')) {
         $logger->debug(sprintf('inserting file %s', $version . '$sql'));
         $database->insertSql(null, array(THELIA_ROOT . '/setup/update/' . $version . '.sql'));
         $logger->debug(sprintf('end inserting file %s', $version . '$sql'));
     }
     ConfigQuery::write('thelia_version', $version);
 }
 public function postActivation(ConnectionInterface $con = null)
 {
     try {
         OrderCommentQuery::create()->findOne();
     } catch (\Exception $e) {
         $database = new Database($con->getWrappedConnection());
         $database->insertSql(null, array(THELIA_ROOT . '/local/modules/OrderComment/Config/thelia.sql'));
     }
 }
Exemple #13
0
 public function destroy(ConnectionInterface $con = null, $deleteModuleData = false)
 {
     // Delete config table and messages if required
     if ($deleteModuleData) {
         $database = new Database($con);
         $database->execute("DROP TABLE ?", PayzenConfigTableMap::TABLE_NAME);
         MessageQuery::create()->findOneByName(self::CONFIRMATION_MESSAGE_NAME)->delete();
     }
 }
Exemple #14
0
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con);
     // Create tables and insert data it not exist
     try {
         InseeGeoMunicipalityQuery::create()->findOne();
     } catch (PropelException $e) {
         $database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql', __DIR__ . DS . 'Config' . DS . 'insert.sql', __DIR__ . DS . 'Config' . DS . 'insert_city_0.sql', __DIR__ . DS . 'Config' . DS . 'insert_city_1.sql', __DIR__ . DS . 'Config' . DS . 'insert_city_2.sql', __DIR__ . DS . 'Config' . DS . 'insert_city_3.sql', __DIR__ . DS . 'Config' . DS . 'insert_city_18_0.sql', __DIR__ . DS . 'Config' . DS . 'insert_city_18_1.sql', __DIR__ . DS . 'Config' . DS . 'insert_city_18_2.sql', __DIR__ . DS . 'Config' . DS . 'insert_city_18_3.sql']);
     }
 }
 public function postActivation(ConnectionInterface $con = null)
 {
     try {
         DealerTeamQuery::create()->findOne();
     } catch (\Exception $e) {
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . "/Config/thelia.sql"]);
     }
     $this->addResource(self::RESOURCES_TEAM);
 }
Exemple #16
0
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con->getWrappedConnection());
     // Insert email message
     $database->insertSql(null, array(__DIR__ . "/Config/setup.sql"));
     /* insert the images from image folder if not already done */
     $moduleModel = $this->getModuleModel();
     if (!$moduleModel->isModuleImageDeployed($con)) {
         $this->deployImageFolder($moduleModel, sprintf('%s/images', __DIR__), $con);
     }
 }
 /**
  * @param ConnectionInterface $con
  */
 public function postActivation(ConnectionInterface $con = null)
 {
     /* insert the images from image folder if first module activation */
     $module = $this->getModuleModel();
     if (ModuleImageQuery::create()->filterByModule($module)->count() == 0) {
         $this->deployImageFolder($module, sprintf('%s/images', __DIR__), $con);
     }
     /* set module title */
     $this->setTitle($module, array("en_US" => "Transfer", "fr_FR" => "Virement"));
     $database = new Database($con->getWrappedConnection());
     $database->insertSql(null, array(__DIR__ . "/Config/thelia.sql"));
 }
 public function preActivation(ConnectionInterface $con = null)
 {
     try {
         // Try find Acl DB Model
         AclQuery::create()->findOne();
         CustomerGroupAclQuery::create()->findOne();
     } catch (\Exception $e) {
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
     }
     return true;
 }
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con);
     $database->insertSql(null, [__DIR__ . "/Config/create.sql", __DIR__ . "/Config/insert.sql"]);
     // Creating the folder for diaporama
     $fs = new Filesystem();
     $diaporamaImagesFolder = Diaporamas::getDiaporamaImagesFolder();
     !$fs->exists($diaporamaImagesFolder) and $fs->mkdir($diaporamaImagesFolder);
     // Activate the Smarty filter for shortcodes
     $smartyFilter = SmartyFilterQuery::create()->findOneByCode(self::SMARTY_FILTER);
     if (!(is_null($smartyFilter) or $smartyFilter->getActive())) {
         $smartyFilter->setActive(true);
         $smartyFilter->save();
     }
 }
 public function preActivation(ConnectionInterface $con = null)
 {
     $injectSql = false;
     try {
         $item = CustomDeliverySliceQuery::create()->findOne();
     } catch (\Exception $ex) {
         // the table doest not exist
         $injectSql = true;
     }
     if (true === $injectSql) {
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . '/Config/thelia.sql']);
     }
     return true;
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $connection = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
     $connection = $connection->getWrappedConnection();
     $tables = $connection->query("SHOW TABLES");
     $connection->query("SET FOREIGN_KEY_CHECKS = 0");
     foreach ($tables as $table) {
         $connection->query(sprintf("DROP TABLE `%s`", $table[0]));
     }
     $connection->query("SET FOREIGN_KEY_CHECKS = 1");
     $database = new Database($connection);
     $output->writeln(array('', '<info>starting reloaded database, please wait</info>'));
     $database->insertSql();
     $output->writeln(array('', '<info>Database reloaded with success</info>', ''));
 }
Exemple #22
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln(array('', 'Welcome to Thelia install process', 'You need information about your database configuration (host, username, password, database name, etc)', '', '<info>Caution : You are installing Thelia in cli mode, we verify some information, but this information are only available for the cli php sapi</info>', '<info>This informations can be different in your apache or cgi php.ini files</info>', ''));
     $this->checkPermission($output);
     $connectionInfo = array("host" => $input->getOption("db_host"), "dbName" => $input->getOption("db_name"), "username" => $input->getOption("db_username"), "password" => $input->getOption("db_password"));
     while (false === ($connection = $this->tryConnection($connectionInfo, $output))) {
         $connectionInfo = $this->getConnectionInfo($input, $output);
     }
     $database = new Database($connection);
     $database->createDatabase($connectionInfo["dbName"]);
     $output->writeln(array("", "<info>Creating Thelia database, please wait</info>", ""));
     $database->insertSql($connectionInfo["dbName"]);
     $output->writeln(array("", "<info>Database created without errors</info>", "<info>Creating file configuration, please wait</info>", ""));
     $this->createConfigFile($connectionInfo);
     $output->writeln(array("", "<info>Config file created with success. Your thelia is installed</info>", ""));
 }
 /**
  * @param ConnectionInterface $con
  */
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con);
     try {
         CustomerFamilyQuery::create()->findOne();
     } catch (\Exception $e) {
         $database->insertSql(null, array(__DIR__ . "/Config/thelia.sql"));
     }
     //Generate the 2 defaults customer_family
     //Customer
     self::getCustomerFamilyByCode(self::CUSTOMER_FAMILY_PARTICULAR, "Particulier", "fr_FR");
     self::getCustomerFamilyByCode(self::CUSTOMER_FAMILY_PARTICULAR, "Particular", "en_US");
     //Professional
     self::getCustomerFamilyByCode(self::CUSTOMER_FAMILY_PROFESSIONAL, "Professionnel", "fr_FR");
     self::getCustomerFamilyByCode(self::CUSTOMER_FAMILY_PROFESSIONAL, "Professional", "en_US");
 }
Exemple #24
0
 /**
  * @param ConnectionInterface|null $con
  * @throws \Exception
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con);
     $database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
     $currencies = json_decode(file_get_contents(__DIR__ . DS . 'Config' . DS . 'currency_codes.json'), true);
     $codes = [];
     foreach ($currencies as $currency) {
         if (!$this->isValidCurrency($codes, $currency)) {
             continue;
         }
         $currencyNumericCode = new CurrencyNumericCode();
         $currencyNumericCode->setCode($currency['AlphabeticCode'])->setNumericCode($currency['NumericCode'])->setMinorUnit($currency['MinorUnit'])->save($con);
         $codes[] = $currency['AlphabeticCode'];
     }
     $con->commit();
     $this->deployImageFolder($this->getModuleModel(), __DIR__ . DS . "templates" . DS . "backOffice" . DS . "default" . DS . "assets" . DS . "img", $con);
 }
 /**
  * @param ConnectionInterface $con
  */
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con->getWrappedConnection());
     $database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
     $languages = LangQuery::create()->find();
     if (null === MessageQuery::create()->findOneByName(self::MESSAGE_SEND_CONFIRMATION)) {
         $message = new Message();
         $message->setName(self::MESSAGE_SEND_CONFIRMATION)->setHtmlLayoutFileName('')->setHtmlTemplateFileName(self::MESSAGE_SEND_CONFIRMATION . '.html')->setTextLayoutFileName('')->setTextTemplateFileName(self::MESSAGE_SEND_CONFIRMATION . '.txt');
         foreach ($languages as $language) {
             /** @var Lang $language */
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle($this->trans('Order send confirmation', $locale));
             $message->setSubject($this->trans('Order send confirmation', $locale));
         }
         $message->save();
     }
 }
 public function update($currentVersion, $newVersion, ConnectionInterface $con)
 {
     if (file_exists(__DIR__ . "/Config/Update/{$newVersion}.sql")) {
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . "/Config/Update/{$newVersion}.sql"]);
     }
     if ($newVersion === "0.6") {
         $merchantId = self::getConfigValue('merchant_id');
         if (null !== $merchantId) {
             $googleShoppingAccount = new GoogleshoppingAccount();
             $googleShoppingAccount->setMerchantId($merchantId)->save();
             $googleShoppingProducts = GoogleshoppingProductSynchronisationQuery::create()->find();
             if (null !== $googleShoppingProducts) {
                 /** @var GoogleshoppingProductSynchronisation $googleShoppingProduct */
                 foreach ($googleShoppingProducts as $googleShoppingProduct) {
                     $googleShoppingProduct->setGoogleshoppingAccountId($googleShoppingAccount->getId())->save();
                 }
             }
         }
     }
 }
Exemple #27
0
 /**
  * Update method to execute sql script. Script must be in Config\Update
  *
  * @param string              $currentVersion
  * @param string              $newVersion
  * @param ConnectionInterface $con
  */
 public function update($currentVersion, $newVersion, ConnectionInterface $con)
 {
     $logger = Tlog::getInstance();
     /** @var string $moduleDir Need for include_once php file*/
     $moduleDir = __DIR__;
     $setupDir = __DIR__ . DS . 'Setup' . DS . 'Update';
     $finder = (new Finder())->files()->name('#.*?\\.sql#')->in($setupDir);
     $database = new Database($con);
     /** @var \Symfony\Component\Finder\SplFileInfo $updateSQLFile */
     foreach ($finder as $updateSQLFile) {
         if (version_compare($currentVersion, str_replace('.sql', '', $updateSQLFile->getFilename()), '<')) {
             $logger->info('executing file ' . $currentVersion . '.sql');
             $database->insertSql(null, [$updateSQLFile->getPathname()]);
             $logger->info('end executing file ' . $currentVersion . '.sql');
         }
     }
     // php update
     $filename = $setupDir . DS . $newVersion . '.php';
     if (file_exists($filename)) {
         $logger->info('executing file ' . $newVersion . '.php');
         include_once $filename;
         $logger->info('end executing file ' . $newVersion . '.php');
     }
 }
Exemple #28
0
 public function postActivation(ConnectionInterface $con = null)
 {
     $con->beginTransaction();
     try {
         if (null === ConfigQuery::read(static::CONFIG_API_KEY)) {
             $this->createConfigValue(static::CONFIG_API_KEY, ["fr_FR" => "Clé d'API pour mailjet", "en_US" => "Api key for mailjet"]);
         }
         if (null === ConfigQuery::read(static::CONFIG_API_SECRET)) {
             $this->createConfigValue(static::CONFIG_API_SECRET, ["fr_FR" => "Secret d'API pour mailjet", "en_US" => "Api secret for mailjet"]);
         }
         if (null === ConfigQuery::read(static::CONFIG_NEWSLETTER_LIST)) {
             $this->createConfigValue(static::CONFIG_NEWSLETTER_LIST, ["fr_FR" => "ALT de la liste de diffusion mailjet", "en_US" => "Diffusion list ALT of mailjet"]);
         }
         if (null === ConfigQuery::read(static::CONFIG_API_WS_ADDRESS)) {
             $this->createConfigValue(static::CONFIG_API_WS_ADDRESS, ["fr_FR" => "Adresse du webservice mailjet", "en_US" => "Address of the mailjet webservice"], "https://api.mailjet.com/v3/REST");
         }
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . "/Config/thelia.sql"]);
         $con->commit();
     } catch (\Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Exemple #29
0
 protected function manageSecret(Database $database)
 {
     $secret = TokenProvider::generateToken();
     $sql = "UPDATE `config` SET `value`=? WHERE `name`='form.secret'";
     $database->execute($sql, [$secret]);
 }
Exemple #30
0
 protected function updateToVersion($version, Database $database)
 {
     // sql update
     $filename = sprintf("%s%s%s", THELIA_SETUP_DIRECTORY, str_replace('/', DS, self::SQL_DIR), $version . '.sql');
     if (file_exists($filename)) {
         $this->log('debug', sprintf('inserting file %s', $version . '.sql'));
         $database->insertSql(null, [$filename]);
         $this->log('debug', sprintf('end inserting file %s', $version . '.sql'));
     }
     // php update
     $filename = sprintf("%s%s%s", THELIA_SETUP_DIRECTORY, str_replace('/', DS, self::PHP_DIR), $version . '.php');
     if (file_exists($filename)) {
         $this->log('debug', sprintf('executing file %s', $version . '.php'));
         include_once $filename;
         $this->log('debug', sprintf('end executing file %s', $version . '.php'));
     }
     $this->setCurrentVersion($version);
 }