本文整理汇总了PHP中Nette\Database\Context::beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:PHP Context::beginTransaction方法的具体用法?PHP Context::beginTransaction怎么用?PHP Context::beginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Database\Context
的用法示例。
在下文中一共展示了Context::beginTransaction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processUpdate
/**
* @param \NetteAddons\Model\Importers\IAddonVersionsImporter
* @param string
* @param int
*/
private function processUpdate(IAddonVersionsImporter $addonVersionImporter, $url, $id)
{
try {
$this->db->beginTransaction();
$addon = $addonVersionImporter->getAddon($url);
/** @var \Nette\Database\Table\ActiveRow $row */
$row = $this->db->table('addons')->get($id);
if (!$row) {
$this->db->rollBack();
return;
}
$row->update(array('composerVendor' => $addon->getComposerVendor(), 'composerName' => $addon->getComposerName(), 'shortDescription' => Strings::truncate($addon->getPerex(), 250), 'stars' => $addon->getStars()));
$this->db->table('addons_versions')->where('addonId = ?', $id)->delete();
$row = $this->db->table('addons_resources')->where('addonId = ? AND type = ?', $id, AddonResources::RESOURCE_PACKAGIST)->fetch();
if ($row) {
if ($addon->getPackagist() === null) {
$row->delete();
} else {
$row->update(array('resource' => $addon->getPackagist()));
}
} elseif ($addon->getPackagist() !== null) {
$this->db->table('addons_resources')->insert(array('addonId' => $id, 'type' => AddonResources::RESOURCE_PACKAGIST, 'resource' => $addon->getPackagist()));
}
$row = $this->db->table('addons_resources')->where('addonId = ? AND type = ?', $id, AddonResources::RESOURCE_GITHUB)->fetch();
if ($row) {
if ($addon->getGithub() === null) {
$row->delete();
} else {
$row->update(array('resource' => $addon->getGithub()));
}
} elseif ($addon->getGithub() !== null) {
$this->db->table('addons_resources')->insert(array('addonId' => $id, 'type' => AddonResources::RESOURCE_GITHUB, 'resource' => $addon->getGithub()));
}
foreach ($addon->getVersions() as $version) {
/** @var \Nette\Database\Table\ActiveRow $row */
$row = $this->db->table('addons_versions')->insert(array('addonId' => $id, 'version' => $version->getVersion(), 'license' => implode(', ', $version->getLicenses()), 'distType' => 'zip', 'distUrl' => 'https://nette.org', 'updatedAt' => new DateTime(), 'composerJson' => ''));
if (!$row) {
$this->db->rollBack();
return;
}
foreach ($version->getDependencies() as $dependency) {
// @todo addon link
$this->db->table('addons_dependencies')->insert(array('versionId' => $row->id, 'packageName' => $dependency->getDependencyName(), 'version' => $dependency->getDependencyVersion(), 'type' => $dependency->getType()));
}
}
$this->db->commit();
} catch (\Exception $e) {
Debugger::log($e);
$this->db->rollBack();
}
}
示例2: actionDefault
public function actionDefault()
{
try {
$this->db->beginTransaction();
$this->db->table('addons_resources')->delete();
foreach ($this->db->table('addons') as $addon) {
$this->updateAddon($addon);
}
$this->db->commit();
} catch (\PDOException $e) {
Debugger::log($e);
$this->db->rollBack();
}
}
示例3: register
public function register($username, $password)
{
try {
$this->database->beginTransaction();
$this->database->table(self::TABLE_NAME)->insert(array(self::COLUMN_USERNAME => $username, self::COLUMN_PASSWORD_HASH => "xxx"));
$row = $this->database->table(self::TABLE_NAME)->select(self::COLUMN_DATE)->where(self::COLUMN_USERNAME, $username)->fetch();
$hash = md5($password . $row[self::COLUMN_DATE]);
$this->database->table(self::TABLE_NAME)->where(self::COLUMN_USERNAME, $username)->update(array(self::COLUMN_PASSWORD_HASH => $hash));
$this->database->commit();
} catch (\Exception $ex) {
$this->database->rollBack();
throw $ex;
}
}
示例4: beginTransaction
/**
* @return void
*/
public function beginTransaction()
{
if ($this->config->isNestedTransactions()) {
if ($this->transactionLevel == 0) {
$this->context->beginTransaction();
} elseif ($this->transactionLevel > 0) {
$this->context->query("SAVEPOINT level{$this->transactionLevel}");
} else {
throw new InvalidStateException("Negative transaction level. Check if each commit/rollBack has its corresponding beginTransaction.");
}
$this->transactionLevel++;
} else {
$this->context->beginTransaction();
}
}
示例5: beginTransaction
public function beginTransaction()
{
$hash = spl_object_hash($this->databaseContext);
if (!isset(self::$transactions[$hash])) {
$this->databaseContext->beginTransaction();
self::$transactions[$hash] = TRUE;
}
}
示例6: parseAndRunFile
/**
* Import taken from Adminer, slightly modified
*
* @param string $query
* @return int number of done queries OR array in case of error
*
* @author Jakub Vrána, Jan Tvrdík, Michael Moravec, Martin Lukeš
* @license Apache License
*/
private function parseAndRunFile($query)
{
$delimiter = ';';
$offset = 0;
$state = array();
try {
$this->db->beginTransaction();
while ($query != '') {
if (!$offset && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) {
$delimiter = $match[1];
$query = substr($query, strlen($match[0]));
} else {
preg_match('(' . preg_quote($delimiter) . '|[\'`"]|/\\*|-- |#|$)', $query, $match, PREG_OFFSET_CAPTURE, $offset);
// should always match
$found = $match[0][0];
$offset = $match[0][1] + strlen($found);
if (!$found && rtrim($query) === '') {
break;
}
if (!$found || $found == $delimiter) {
// end of a query
$q = substr($query, 0, $match[0][1]);
//change definer (must be previously definened)
if (!empty($this->definerUser) || !empty($this->definerHost)) {
$definerMatches = array();
preg_match('/(DEFINER\\s*=\\s*)(`[^`]+`)@(`[^`]+`)/', $q, $definerMatches);
$newUser = empty($this->definerUser) ? $definerMatches[2] : $this->definerUser;
$newHost = empty($this->definerHost) ? $definerMatches[3] : $this->definerHost;
$q = preg_replace('/(DEFINER\\s*=\\s*)(`[^`]+`)@(`[^`]+`)/', '$1`' . $newUser . '`@`' . $newHost . '`', $q);
}
$state[] = $this->db->query($q);
$query = substr($query, $offset);
$offset = 0;
} else {
// find matching quote or comment end
while (preg_match('~' . ($found == '/*' ? '\\*/' : (preg_match('~-- |#~', $found) ? "\n" : "{$found}|\\\\.")) . '|$~s', $query, $match, PREG_OFFSET_CAPTURE, $offset)) {
//! respect sql_mode NO_BACKSLASH_ESCAPES
$s = $match[0][0];
$offset = $match[0][1] + strlen($s);
if ($s[0] !== '\\') {
break;
}
}
}
}
}
$this->db->commit();
$result = count($state);
} catch (\Exception $ex) {
$this->db->rollBack();
$result = array("message" => $ex->getMessage(), "sql" => $q);
}
$this->db->query('USE `' . $this->dbName . '`');
// revert used database
return $result;
}
示例7: push
public function push()
{
$this->db->beginTransaction();
//Insert
foreach ($this->toInsert as $key => $value) {
$this->getTable()->insert(array("key" => $key, "value" => $value));
}
//Update
foreach ($this->toUpdate as $key => $value) {
$this->getTable()->where("key", $key)->update(array("value" => $value));
}
//Delete
if (count($this->toDelete)) {
$this->getTable()->where('key', $this->toDelete)->delete();
}
$this->db->commit();
//PTT
$this->fetched = $this->toInsert = $this->toUpdate = array();
//Clean
}
示例8: addTranslation
/**
* @param string $idf
* @param int $amountType
* @param string $translation
* @return DatabaseTranslator
*/
private function addTranslation($idf, $amountType, $translation)
{
try {
$this->database->beginTransaction();
$this->database->table(self::TABLE_TRANS)->insert(array('idf' => $idf, 'lang' => $this->lang, 'amount_type' => $amountType, 'translation' => $translation));
$this->database->commit();
} catch (\PDOException $e) {
$this->database->rollBack();
throw $e;
}
$this->invalidate(TRUE);
return $this;
}
示例9: submittedMedia
public function submittedMedia(\Cotel\Form\MediaForm $form)
{
$values = $form->getValues();
$tags = array_filter(preg_split('/\\s+/', $values->tags));
$this->database->beginTransaction();
$this->database->query('INSERT INTO urls', array('url' => $values->url, 'title' => $values->title, 'published' => new \DateTime($values->published), 'added' => new \DateTime('now')));
$urlId = $this->database->getInsertId();
$tagIds = array();
foreach ($tags as $tag) {
$this->database->query('INSERT INTO tags ? ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id)', array('tag' => $tag));
$this->database->query('INSERT INTO url_tags', ['url_id' => $urlId, 'tag_id' => $this->database->getInsertId()]);
}
$this->database->commit();
$this->redirect('this');
}
示例10: addHodnoceni
public function addHodnoceni($id, $hodnoceni, $ip)
{
if (abs($hodnoceni) != 1) {
return;
}
$this->database->beginTransaction();
$h = $this->getHodnoceniByIp($id, $ip);
if (empty($h)) {
$arr = array("clanek_id" => $id, "hodnoceni" => $hodnoceni, "ip" => $ip);
$this->database->query("INSERT INTO hodnoceni ", $arr);
$this->database->commit();
} else {
$this->database->rollBack();
}
}
示例11: beginTransaction
public function beginTransaction()
{
$this->database->beginTransaction();
}
示例12: beginTransaction
public function beginTransaction()
{
$this->context->beginTransaction();
}