/**
  * @param string $xml
  *
  * @return Database|boolean
  */
 public function applyXml($xml, $changeRequired = false)
 {
     $this->readDatabase();
     $builder = new QuickBuilder();
     $builder->setIdentifierQuoting(true);
     $builder->setPlatform($this->database->getPlatform());
     $builder->setSchema($xml);
     $database = $builder->getDatabase();
     $database->setSchema('migration');
     $database->setPlatform($this->database->getPlatform());
     $diff = DatabaseComparator::computeDiff($this->database, $database);
     if (false === $diff) {
         if ($changeRequired) {
             throw new BuildException(sprintf("No changes in schema to current database: \nSchema database:\n%s\n\nCurrent Database:\n%s", $database, $this->database));
         }
         return false;
     }
     $sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
     $this->con->beginTransaction();
     if (!$sql) {
         throw new BuildException(sprintf('Ooops. There is a diff between current database and schema xml but no SQL has been generated. Change: %s', $diff));
     }
     $statements = SqlParser::parseString($sql);
     foreach ($statements as $statement) {
         try {
             $stmt = $this->con->prepare($statement);
             $stmt->execute();
         } catch (\Exception $e) {
             throw new BuildException(sprintf("Can not execute SQL: \n%s\nFrom database: \n%s\n\nTo database: \n%s\n", $statement, $this->database, $database), null, $e);
         }
     }
     $this->con->commit();
     return $database;
 }
 /**
  * @param string $xml
  *
  * @return Database
  */
 public function applyXml($xml)
 {
     $this->readDatabase();
     $builder = new QuickBuilder();
     $builder->setPlatform($this->database->getPlatform());
     $builder->setSchema($xml);
     $database = $builder->getDatabase();
     $database->setSchema('migration');
     $database->setPlatform($this->database->getPlatform());
     $diff = DatabaseComparator::computeDiff($this->database, $database);
     if (false === $diff) {
         return null;
     }
     $sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
     $this->con->beginTransaction();
     $statements = SqlParser::parseString($sql);
     foreach ($statements as $statement) {
         try {
             $stmt = $this->con->prepare($statement);
             $stmt->execute();
         } catch (\Exception $e) {
             $this->con->rollBack();
             throw new BuildException(sprintf("Can not execute SQL: \n%s\nFrom database: \n%s\n\nTo database: \n%s\n", $statement, $this->database, $database), null, $e);
         }
     }
     $this->con->commit();
     return $database;
 }
 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);
         }
     }
 }
 /**
  * @param \Propel\Runtime\Adapter\AdapterInterface $adapter
  *
  * @return \Propel\Runtime\Connection\ConnectionInterface
  */
 public function getWriteConnection(AdapterInterface $adapter = null)
 {
     if (null === $this->connection) {
         $this->connection = ConnectionFactory::create($this->configuration, $adapter);
         $this->connection->setName($this->getName());
     }
     return $this->connection;
 }
 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 #6
0
 /**
  * Gets ID for specified sequence name.
  *
  * @param     ConnectionInterface $con
  * @param     string  $name
  *
  * @return    integer
  */
 public function getId(ConnectionInterface $con, $name = null)
 {
     if ($name === null) {
         throw new InvalidArgumentException("Unable to fetch next sequence ID without sequence name.");
     }
     $stmt = $con->query("SELECT nextval(" . $con->quote($name) . ")");
     $row = $stmt->fetch(PDO::FETCH_NUM);
     return $row[0];
 }
 public function initConnection(ConnectionInterface $con, array $settings)
 {
     $con->query('PRAGMA foreign_keys = ON');
     parent::initConnection($con, $settings);
     //add regex support
     $con->sqliteCreateFunction('regexp', function ($pattern, $value) {
         mb_regex_encoding('UTF-8');
         return false !== mb_ereg($pattern, $value) ? 1 : 0;
     });
 }
Exemple #8
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);
     }
 }
 public function delete(ConnectionInterface $con = null)
 {
     $con->beginTransaction();
     try {
         TestableAggregateCommentQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con);
         $con->commit();
         $this->setDeleted(true);
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
Exemple #10
0
 /**
  * @see       parent::setCharset()
  *
  * @param     PDO     $con
  * @param     string  $charset
  *
  * @throws    PropelException
  */
 public function setCharset(ConnectionInterface $con, $charset)
 {
     switch (strtolower($charset)) {
         case 'utf-8':
             $con->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_UTF8);
             break;
         case 'system':
             $con->setAttribute(PDO::SQLSRV_ATTR_ENCODING, PDO::SQLSRV_ENCODING_SYSTEM);
             break;
         default:
             throw new PropelException('only utf-8 or system encoding are supported by the pdo_sqlsrv driver');
     }
 }
Exemple #11
0
 /**
  * @param int $idCategoryNode
  *
  * @return void
  */
 public function updateBlocksAssignedToDeletedCategoryNode($idCategoryNode)
 {
     $this->connection->beginTransaction();
     $assignedBlocks = $this->getCmsBlocksByIdCategoryNode($idCategoryNode);
     foreach ($assignedBlocks as $idBlock => $blockTransfer) {
         //unique keys is on name, type and value therefore the name has to be changed
         $blockTransfer->setName($blockTransfer->getName() . '_' . CmsConstants::RESOURCE_TYPE_CATEGORY_NODE . '_deleted_' . $blockTransfer->getIdCmsBlock());
         $blockTransfer->setType(CmsConstants::RESOURCE_TYPE_STATIC);
         $blockTransfer->setValue(0);
         $this->saveBlockAndTouch($blockTransfer);
     }
     $this->connection->commit();
 }
 /**
  * Execute a list of DDL statements based on an array
  * Does not use transactions since they are not supported in DDL statements
  *
  * @param array               $statements a list of SQL statements
  * @param ConnectionInterface $connection a connection object
  *
  * @return integer the number of executed statements
  */
 protected static function executeStatements($statements, ConnectionInterface $connection)
 {
     $executed = 0;
     foreach ($statements as $statement) {
         $stmt = $connection->prepare($statement);
         if ($stmt instanceof StatementInterface) {
             // only execute if has no error
             $stmt->execute();
             $executed++;
         }
     }
     return $executed;
 }
 /**
  * @throws \Spryker\Zed\SequenceNumber\Business\Exception\InvalidSequenceNumberException
  *
  * @return int
  */
 protected function createNumber()
 {
     try {
         $this->connection->beginTransaction();
         $sequence = $this->getSequence();
         $idCurrent = $sequence->getCurrentId() + $this->randomNumberGenerator->generate();
         $sequence->setCurrentId($idCurrent);
         $sequence->save();
         $this->connection->commit();
     } catch (\Exception $e) {
         $this->connection->rollback();
         throw new InvalidSequenceNumberException('Could not generate sequence number. Make sure your settings are complete. Error: ' . $e->getMessage());
     }
     return $idCurrent;
 }
Exemple #14
0
 /**
  * Update all ancestor entries to reflect changes on this instance.
  *
  * @param ConnectionInterface $con
  *
  * @return \Propel\Bundle\PropelBundle\Model\Acl\ObjectIdentity $this
  */
 protected function updateAncestorsTree(ConnectionInterface $con = null)
 {
     $con->beginTransaction();
     $oldAncestors = ObjectIdentityQuery::create()->findAncestors($this, $con);
     $children = ObjectIdentityQuery::create()->findGrandChildren($this, $con);
     $children->append($this);
     if (count($oldAncestors)) {
         foreach ($children as $eachChild) {
             /*
              * Delete only those entries, that are ancestors based on the parent relation.
              * Ancestors of grand children up to the current node will be kept.
              */
             $query = ObjectIdentityAncestorQuery::create()->filterByObjectIdentityId($eachChild->getId())->filterByObjectIdentityRelatedByAncestorId($oldAncestors, Criteria::IN);
             if ($eachChild->getId() !== $this->getId()) {
                 $query->filterByAncestorId(array($eachChild->getId(), $this->getId()), Criteria::NOT_IN);
             } else {
                 $query->filterByAncestorId($this->getId(), Criteria::NOT_EQUAL);
             }
             $query->delete($con);
         }
     }
     // This is the new parent object identity!
     $parent = $this->getObjectIdentityRelatedByParentObjectIdentityId($con);
     if (null !== $parent) {
         $newAncestors = ObjectIdentityQuery::create()->findAncestors($parent, $con);
         $newAncestors->append($parent);
         foreach ($newAncestors as $eachAncestor) {
             // This collection contains the current object identity!
             foreach ($children as $eachChild) {
                 $ancestor = ObjectIdentityAncestorQuery::create()->filterByObjectIdentityId($eachChild->getId())->filterByAncestorId($eachAncestor->getId())->findOneOrCreate($con);
                 // If the entry already exists, next please.
                 if (!$ancestor->isNew()) {
                     continue;
                 }
                 if ($eachChild->getId() === $this->getId()) {
                     // Do not save() here, as it would result in an infinite recursion loop!
                     $this->addObjectIdentityAncestorRelatedByObjectIdentityId($ancestor);
                 } else {
                     // Save the new ancestor to avoid integrity constraint violation.
                     $ancestor->save($con);
                     $eachChild->addObjectIdentityAncestorRelatedByObjectIdentityId($ancestor)->save($con);
                 }
             }
         }
     }
     $con->commit();
     return $this;
 }
Exemple #15
0
 /**
  * @param ConnectionInterface $connection Propel connection
  */
 public function __construct(ConnectionInterface $connection, array $logMethods = array('beginTransaction', 'commit', 'rollBack', 'forceRollBack', 'exec', 'query', 'execute'))
 {
     if ($connection instanceof ProfilerConnectionWrapper) {
         $connection->setLogMethods($logMethods);
         $this->config = $connection->getProfiler()->getConfiguration();
         $this->handler = new TestHandler();
         if ($connection->getLogger() instanceof Logger) {
             $this->logger = $connection->getLogger();
             $this->logger->pushHandler($this->handler);
         } else {
             $this->errors[] = 'Supported only monolog logger';
         }
     } else {
         $this->errors[] = 'You need set ProfilerConnectionWrapper';
     }
 }
Exemple #16
0
 /**
  * @param \Generated\Shared\Transfer\UrlTransfer $urlTransfer
  *
  * @return \Generated\Shared\Transfer\UrlTransfer
  */
 public function saveUrlAndTouch(UrlTransfer $urlTransfer)
 {
     $this->connection->beginTransaction();
     $urlTransfer = $this->saveUrl($urlTransfer);
     $this->touchUrlActive($urlTransfer->getIdUrl());
     $this->connection->commit();
     return $urlTransfer;
 }
 /**
  * @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();
     }
 }
Exemple #18
0
 /**
  * @param string $itemType
  * @param string $itemEvent
  * @param int $idItem
  * @param bool $keyChange
  *
  * @return bool
  */
 public function saveTouchRecord($itemType, $itemEvent, $idItem, $keyChange = false)
 {
     $this->connection->beginTransaction();
     if ($keyChange) {
         $this->insertKeyChangeRecord($itemType, $idItem);
         if ($itemEvent === SpyTouchTableMap::COL_ITEM_EVENT_DELETED) {
             if (!$this->deleteKeyChangeActiveRecord($itemType, $idItem)) {
                 $this->insertTouchRecord($itemType, $itemEvent, $idItem, SpyTouchTableMap::COL_ITEM_EVENT_ACTIVE);
             }
         } else {
             $this->insertTouchRecord($itemType, $itemEvent, $idItem);
         }
     } else {
         $touchEntity = $this->touchQueryContainer->queryUpdateTouchEntry($itemType, $idItem)->findOneOrCreate();
         $this->saveTouchEntity($itemType, $idItem, $itemEvent, $touchEntity);
     }
     $this->connection->commit();
     return true;
 }
Exemple #19
0
 /**
  * @param \Generated\Shared\Transfer\RedirectTransfer $redirectTransfer
  *
  * @return \Generated\Shared\Transfer\RedirectTransfer
  */
 protected function createRedirectFromTransfer(RedirectTransfer $redirectTransfer)
 {
     $redirectEntity = new SpyUrlRedirect();
     $this->connection->beginTransaction();
     $redirectEntity->fromArray($redirectTransfer->toArray());
     $redirectEntity->save();
     $this->connection->commit();
     $redirectTransfer->setIdUrlRedirect($redirectEntity->getIdUrlRedirect());
     return $redirectTransfer;
 }
Exemple #20
0
 /**
  * Returns current database driver.
  *
  * @return string[]
  */
 protected function getDriver()
 {
     $driver = $this->con ? $this->con->getAttribute(\PDO::ATTR_DRIVER_NAME) : null;
     if (null === $driver && ($currentDSN = $this->getBuiltDsn())) {
         $driver = explode(':', $currentDSN)[0];
     }
     $db = strtolower(getenv('DB'));
     if (!$db || 'agnostic' === $db) {
         $db = 'mysql';
     }
     return $db ?: strtolower($driver);
 }
 /**
  * @param \Generated\Shared\Transfer\PageTransfer $pageTransfer
  * @param string $placeholder
  * @param string $value
  * @param \Generated\Shared\Transfer\LocaleTransfer|null $localeTransfer
  * @param bool $autoGlossaryKeyIncrement
  *
  * @return \Generated\Shared\Transfer\PageKeyMappingTransfer
  */
 public function addPlaceholderText(PageTransfer $pageTransfer, $placeholder, $value, LocaleTransfer $localeTransfer = null, $autoGlossaryKeyIncrement = true)
 {
     $template = $this->templateManager->getTemplateById($pageTransfer->getFkTemplate());
     $uniquePlaceholder = $placeholder . '-' . $pageTransfer->getIdCmsPage();
     $keyName = $this->generateGlossaryKeyName($template->getTemplateName(), $uniquePlaceholder, $autoGlossaryKeyIncrement);
     $this->connection->beginTransaction();
     $pageKeyMapping = $this->createGlossaryPageKeyMapping($pageTransfer, $placeholder, $keyName, $value, $localeTransfer);
     if (!$this->hasPagePlaceholderMapping($pageTransfer->getIdCmsPage(), $placeholder)) {
         $pageKeyMapping = $this->savePageKeyMapping($pageKeyMapping);
     }
     $this->connection->commit();
     return $pageKeyMapping;
 }
 /**
  * Detects the differences between current connected database and $pDatabase
  * and updates the schema. This does not DROP tables.
  *
  * @param Database $pDatabase
  */
 public function updateSchema($pDatabase)
 {
     $diff = DatabaseComparator::computeDiff($this->database, $pDatabase);
     $sql = $this->database->getPlatform()->getModifyDatabaseDDL($diff);
     $statements = SqlParser::parseString($sql);
     foreach ($statements as $statement) {
         if (strpos($statement, 'DROP') === 0) {
             // drop statements cause errors since the table doesn't exist
             continue;
         }
         $stmt = $this->con->prepare($statement);
         $stmt->execute();
     }
 }
Exemple #23
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;
     }
 }
 /**
  * @param \Spryker\Zed\Collector\Business\Exporter\Writer\Storage\TouchUpdaterSet $touchUpdaterSet
  * @param int $idLocale
  * @param \Propel\Runtime\Connection\ConnectionInterface|null $connection
  *
  * @return void
  */
 public function bulkDelete(TouchUpdaterSet $touchUpdaterSet, $idLocale, ConnectionInterface $connection = null)
 {
     $idsToDelete = [];
     foreach ($touchUpdaterSet->getData() as $key => $touchData) {
         $idTouch = $touchData[CollectorConfig::COLLECTOR_TOUCH_ID];
         if ($idTouch !== null) {
             $idsToDelete[$idTouch] = $idTouch;
         }
     }
     if (!empty($idsToDelete) && $connection !== null) {
         $sql = $this->bulkTouchDeleteQuery->addQuery($this->touchKeyTableName, static::FK_TOUCH, $idsToDelete)->getRawSqlString();
         $this->bulkTouchDeleteQuery->flushQueries();
         $connection->exec($sql);
     }
 }
 /**
  * Get a slave connection.
  *
  * If no slave connection exist yet, choose one configuration randomly in the
  * read configuration to open it.
  *
  * @param \Propel\Runtime\Adapter\AdapterInterface $adapter
  *
  * @return \Propel\Runtime\Connection\ConnectionInterface
  */
 public function getReadConnection(AdapterInterface $adapter = null)
 {
     if ($this->isForceMasterConnection()) {
         return $this->getWriteConnection($adapter);
     }
     if (null === $this->readConnection) {
         if (null === $this->readConfiguration) {
             $this->readConnection = $this->getWriteConnection($adapter);
         } else {
             $keys = array_keys($this->readConfiguration);
             $key = $keys[mt_rand(0, count($keys) - 1)];
             $configuration = $this->readConfiguration[$key];
             $this->readConnection = ConnectionFactory::create($configuration, $adapter);
             $this->readConnection->setName($this->getName());
         }
     }
     return $this->readConnection;
 }
 /**
  * @param int $idCategory
  * @param \Generated\Shared\Transfer\LocaleTransfer $localeTransfer
  *
  * @return void
  */
 public function deleteCategoryRecursive($idCategory, LocaleTransfer $localeTransfer)
 {
     $this->connection->beginTransaction();
     $this->removeMappings($idCategory);
     $categoryNodes = $this->categoryQueryContainer->queryAllNodesByCategoryId($idCategory)->find();
     foreach ($categoryNodes as $node) {
         $this->cmsFacade->updateBlocksAssignedToDeletedCategoryNode($node->getIdCategoryNode());
         //TODO: https://spryker.atlassian.net/browse/CD-540
         $children = $this->categoryQueryContainer->queryFirstLevelChildren($node->getIdCategoryNode())->find();
         foreach ($children as $child) {
             $this->deleteCategoryRecursive($child->getFkCategory(), $localeTransfer);
         }
         $nodeExists = $this->categoryQueryContainer->queryNodeById($node->getIdCategoryNode())->count() > 0;
         if ($nodeExists) {
             $this->categoryFacade->deleteNode($node->getIdCategoryNode(), $localeTransfer, true);
         }
     }
     $this->categoryFacade->deleteCategory($idCategory);
     $this->connection->commit();
 }
 /**
  * @param int $idNode
  * @param \Generated\Shared\Transfer\LocaleTransfer $locale
  * @param bool $deleteChildren
  *
  * @return int
  */
 public function deleteNode($idNode, LocaleTransfer $locale, $deleteChildren = false)
 {
     $this->connection->beginTransaction();
     // Order of execution matters, these must be called before node is deleted
     $this->removeNodeUrl($idNode, $locale);
     $this->touchCategoryDeleted($idNode);
     $hasChildren = $this->categoryTreeReader->hasChildren($idNode);
     if ($deleteChildren && $hasChildren) {
         $childNodes = $this->categoryTreeReader->getChildren($idNode, $locale);
         foreach ($childNodes as $childNode) {
             $this->deleteNode($childNode->getIdCategoryNode(), $locale, true);
         }
     }
     $result = $this->closureTableWriter->delete($idNode);
     $hasChildren = $this->categoryTreeReader->hasChildren($idNode);
     if (!$hasChildren) {
         $result = $this->nodeWriter->delete($idNode);
     }
     $this->touchNavigationUpdated();
     $this->connection->commit();
     return $result;
 }
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     ConnectionInterface $con A connection object
  *
  * @return   ChildGoogleshoppingProductSynchronisation A model object, or null if the key is not found
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT ID, PRODUCT_ID, TARGET_COUNTRY, LANG, SYNC_ENABLE, GOOGLESHOPPING_ACCOUNT_ID FROM googleshopping_product_synchronisation WHERE ID = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
         $obj = new ChildGoogleshoppingProductSynchronisation();
         $obj->hydrate($row);
         GoogleshoppingProductSynchronisationTableMap::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
 /**
  * Insert the row in the database.
  *
  * @param      ConnectionInterface $con
  *
  * @throws PropelException
  * @see doSave()
  */
 protected function doInsert(ConnectionInterface $con)
 {
     $modifiedColumns = array();
     $index = 0;
     // check the columns in natural order for more readable SQL queries
     if ($this->isColumnModified(CouponVersionTableMap::ID)) {
         $modifiedColumns[':p' . $index++] = '`ID`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::CODE)) {
         $modifiedColumns[':p' . $index++] = '`CODE`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::TYPE)) {
         $modifiedColumns[':p' . $index++] = '`TYPE`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_EFFECTS)) {
         $modifiedColumns[':p' . $index++] = '`SERIALIZED_EFFECTS`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::IS_ENABLED)) {
         $modifiedColumns[':p' . $index++] = '`IS_ENABLED`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::START_DATE)) {
         $modifiedColumns[':p' . $index++] = '`START_DATE`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::EXPIRATION_DATE)) {
         $modifiedColumns[':p' . $index++] = '`EXPIRATION_DATE`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::MAX_USAGE)) {
         $modifiedColumns[':p' . $index++] = '`MAX_USAGE`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::IS_CUMULATIVE)) {
         $modifiedColumns[':p' . $index++] = '`IS_CUMULATIVE`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::IS_REMOVING_POSTAGE)) {
         $modifiedColumns[':p' . $index++] = '`IS_REMOVING_POSTAGE`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::IS_AVAILABLE_ON_SPECIAL_OFFERS)) {
         $modifiedColumns[':p' . $index++] = '`IS_AVAILABLE_ON_SPECIAL_OFFERS`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::IS_USED)) {
         $modifiedColumns[':p' . $index++] = '`IS_USED`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::SERIALIZED_CONDITIONS)) {
         $modifiedColumns[':p' . $index++] = '`SERIALIZED_CONDITIONS`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::PER_CUSTOMER_USAGE_COUNT)) {
         $modifiedColumns[':p' . $index++] = '`PER_CUSTOMER_USAGE_COUNT`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::CREATED_AT)) {
         $modifiedColumns[':p' . $index++] = '`CREATED_AT`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::UPDATED_AT)) {
         $modifiedColumns[':p' . $index++] = '`UPDATED_AT`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::VERSION)) {
         $modifiedColumns[':p' . $index++] = '`VERSION`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::VERSION_CREATED_AT)) {
         $modifiedColumns[':p' . $index++] = '`VERSION_CREATED_AT`';
     }
     if ($this->isColumnModified(CouponVersionTableMap::VERSION_CREATED_BY)) {
         $modifiedColumns[':p' . $index++] = '`VERSION_CREATED_BY`';
     }
     $sql = sprintf('INSERT INTO `coupon_version` (%s) VALUES (%s)', implode(', ', $modifiedColumns), implode(', ', array_keys($modifiedColumns)));
     try {
         $stmt = $con->prepare($sql);
         foreach ($modifiedColumns as $identifier => $columnName) {
             switch ($columnName) {
                 case '`ID`':
                     $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
                     break;
                 case '`CODE`':
                     $stmt->bindValue($identifier, $this->code, PDO::PARAM_STR);
                     break;
                 case '`TYPE`':
                     $stmt->bindValue($identifier, $this->type, PDO::PARAM_STR);
                     break;
                 case '`SERIALIZED_EFFECTS`':
                     $stmt->bindValue($identifier, $this->serialized_effects, PDO::PARAM_STR);
                     break;
                 case '`IS_ENABLED`':
                     $stmt->bindValue($identifier, (int) $this->is_enabled, PDO::PARAM_INT);
                     break;
                 case '`START_DATE`':
                     $stmt->bindValue($identifier, $this->start_date ? $this->start_date->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
                     break;
                 case '`EXPIRATION_DATE`':
                     $stmt->bindValue($identifier, $this->expiration_date ? $this->expiration_date->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
                     break;
                 case '`MAX_USAGE`':
                     $stmt->bindValue($identifier, $this->max_usage, PDO::PARAM_INT);
                     break;
                 case '`IS_CUMULATIVE`':
                     $stmt->bindValue($identifier, (int) $this->is_cumulative, PDO::PARAM_INT);
                     break;
                 case '`IS_REMOVING_POSTAGE`':
                     $stmt->bindValue($identifier, (int) $this->is_removing_postage, PDO::PARAM_INT);
                     break;
                 case '`IS_AVAILABLE_ON_SPECIAL_OFFERS`':
                     $stmt->bindValue($identifier, (int) $this->is_available_on_special_offers, PDO::PARAM_INT);
                     break;
                 case '`IS_USED`':
                     $stmt->bindValue($identifier, (int) $this->is_used, PDO::PARAM_INT);
                     break;
                 case '`SERIALIZED_CONDITIONS`':
                     $stmt->bindValue($identifier, $this->serialized_conditions, PDO::PARAM_STR);
                     break;
                 case '`PER_CUSTOMER_USAGE_COUNT`':
                     $stmt->bindValue($identifier, (int) $this->per_customer_usage_count, PDO::PARAM_INT);
                     break;
                 case '`CREATED_AT`':
                     $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
                     break;
                 case '`UPDATED_AT`':
                     $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
                     break;
                 case '`VERSION`':
                     $stmt->bindValue($identifier, $this->version, PDO::PARAM_INT);
                     break;
                 case '`VERSION_CREATED_AT`':
                     $stmt->bindValue($identifier, $this->version_created_at ? $this->version_created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
                     break;
                 case '`VERSION_CREATED_BY`':
                     $stmt->bindValue($identifier, $this->version_created_by, PDO::PARAM_STR);
                     break;
             }
         }
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
     }
     $this->setNew(false);
 }
Exemple #30
0
 /**
  * Insert the row in the database.
  *
  * @param      ConnectionInterface $con
  *
  * @throws PropelException
  * @see doSave()
  */
 protected function doInsert(ConnectionInterface $con)
 {
     $modifiedColumns = array();
     $index = 0;
     $this->modifiedColumns[ContentTableMap::ID] = true;
     if (null !== $this->id) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . ContentTableMap::ID . ')');
     }
     // check the columns in natural order for more readable SQL queries
     if ($this->isColumnModified(ContentTableMap::ID)) {
         $modifiedColumns[':p' . $index++] = '`ID`';
     }
     if ($this->isColumnModified(ContentTableMap::VISIBLE)) {
         $modifiedColumns[':p' . $index++] = '`VISIBLE`';
     }
     if ($this->isColumnModified(ContentTableMap::POSITION)) {
         $modifiedColumns[':p' . $index++] = '`POSITION`';
     }
     if ($this->isColumnModified(ContentTableMap::CREATED_AT)) {
         $modifiedColumns[':p' . $index++] = '`CREATED_AT`';
     }
     if ($this->isColumnModified(ContentTableMap::UPDATED_AT)) {
         $modifiedColumns[':p' . $index++] = '`UPDATED_AT`';
     }
     if ($this->isColumnModified(ContentTableMap::VERSION)) {
         $modifiedColumns[':p' . $index++] = '`VERSION`';
     }
     if ($this->isColumnModified(ContentTableMap::VERSION_CREATED_AT)) {
         $modifiedColumns[':p' . $index++] = '`VERSION_CREATED_AT`';
     }
     if ($this->isColumnModified(ContentTableMap::VERSION_CREATED_BY)) {
         $modifiedColumns[':p' . $index++] = '`VERSION_CREATED_BY`';
     }
     $sql = sprintf('INSERT INTO `content` (%s) VALUES (%s)', implode(', ', $modifiedColumns), implode(', ', array_keys($modifiedColumns)));
     try {
         $stmt = $con->prepare($sql);
         foreach ($modifiedColumns as $identifier => $columnName) {
             switch ($columnName) {
                 case '`ID`':
                     $stmt->bindValue($identifier, $this->id, PDO::PARAM_INT);
                     break;
                 case '`VISIBLE`':
                     $stmt->bindValue($identifier, $this->visible, PDO::PARAM_INT);
                     break;
                 case '`POSITION`':
                     $stmt->bindValue($identifier, $this->position, PDO::PARAM_INT);
                     break;
                 case '`CREATED_AT`':
                     $stmt->bindValue($identifier, $this->created_at ? $this->created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
                     break;
                 case '`UPDATED_AT`':
                     $stmt->bindValue($identifier, $this->updated_at ? $this->updated_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
                     break;
                 case '`VERSION`':
                     $stmt->bindValue($identifier, $this->version, PDO::PARAM_INT);
                     break;
                 case '`VERSION_CREATED_AT`':
                     $stmt->bindValue($identifier, $this->version_created_at ? $this->version_created_at->format("Y-m-d H:i:s") : null, PDO::PARAM_STR);
                     break;
                 case '`VERSION_CREATED_BY`':
                     $stmt->bindValue($identifier, $this->version_created_by, PDO::PARAM_STR);
                     break;
             }
         }
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute INSERT statement [%s]', $sql), 0, $e);
     }
     try {
         $pk = $con->lastInsertId();
     } catch (Exception $e) {
         throw new PropelException('Unable to get autoincrement id.', 0, $e);
     }
     $this->setId($pk);
     $this->setNew(false);
 }