/** * @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; }
/** * Rollback the whole transaction, even if this is a nested rollback * and reset the nested transaction count to 0. * * @return boolean Whether operation was successful. */ public function forceRollBack() { $return = true; if ($this->nestedTransactionCount) { // If we're in a transaction, always roll it back // regardless of nesting level. $return = $this->connection->rollBack(); // reset nested transaction count to 0 so that we don't // try to commit (or rollback) the transaction outside this scope. $this->nestedTransactionCount = 0; if ($this->useDebug) { $this->log('Rollback transaction'); } } return $return; }
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; } }
protected function tearDown() { $this->con->rollBack(); }