Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 /**
  * @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;
 }
 protected function setUp()
 {
     // Initialize translator
     new Translator(new Container());
     $this->exportHandler = new ProductPricesExport(new Container());
     $this->importHandler = new ProductPricesImport(new Container());
     $this->con = Propel::getConnection();
     $this->con->beginTransaction();
 }
Exemplo n.º 4
0
 protected function setUp()
 {
     parent::setUp();
     // Start a transaction to revert all the modification after the test
     $this->con = Propel::getConnection();
     $this->con->beginTransaction();
     // Drop the table to be sure we have a clean environment
     $this->con->exec("SET FOREIGN_KEY_CHECKS = 0;");
     $this->con->exec("DROP TABLE IF EXISTS `example_table`");
 }
Exemplo n.º 5
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();
 }
Exemplo n.º 6
0
 /**
  * @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;
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
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;
 }
 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;
     }
 }
Exemplo n.º 11
0
 /**
  * @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;
 }
 /**
  * Overrides PDO::beginTransaction() to prevent errors due to already-in-progress transaction.
  *
  * @return boolean
  */
 public function beginTransaction()
 {
     $return = true;
     if (!$this->nestedTransactionCount) {
         $return = $this->connection->beginTransaction();
         if ($this->useDebug) {
             $this->log('Begin transaction');
         }
         $this->isUncommitable = false;
     }
     $this->nestedTransactionCount++;
     return $return;
 }
Exemplo n.º 13
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;
 }
 /**
  * @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();
 }
Exemplo n.º 15
0
 /**
  * @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;
 }
Exemplo n.º 16
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;
     }
 }
Exemplo n.º 17
0
 public static function importJsonPrice(SocolissimoDeliveryMode $deliveryMode, ConnectionInterface $con)
 {
     $areaPrices = self::getPrices($deliveryMode);
     $priceExist = SocolissimoPriceQuery::create()->filterByDeliveryModeId($deliveryMode->getId())->findOne();
     //If at least one price exist doesn't import the xml (or it will erase the user price)
     if (null !== $priceExist) {
         return;
     }
     $con->beginTransaction();
     try {
         foreach ($areaPrices as $areaId => $area) {
             foreach ($area['slices'] as $weight => $price) {
                 $slice = (new SocolissimoPrice())->setAreaId($areaId)->setWeightMax($weight)->setPrice($price)->setDeliveryModeId($deliveryMode->getId());
                 $slice->save();
             }
             $con->commit();
         }
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }