beginTransaction() public method

public beginTransaction ( ) : void
return void
 /**
  * @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();
     }
 }
 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();
     }
 }
Ejemplo n.º 3
0
 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;
     }
 }
Ejemplo n.º 4
0
 /**
  * @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();
     }
 }
Ejemplo n.º 5
0
 public function beginTransaction()
 {
     $hash = spl_object_hash($this->databaseContext);
     if (!isset(self::$transactions[$hash])) {
         $this->databaseContext->beginTransaction();
         self::$transactions[$hash] = TRUE;
     }
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }
Ejemplo n.º 7
0
 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
 }
 /**
  * @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;
 }
Ejemplo n.º 9
0
 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');
 }
Ejemplo n.º 10
0
 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();
     }
 }
Ejemplo n.º 11
0
 public function beginTransaction()
 {
     $this->database->beginTransaction();
 }
Ejemplo n.º 12
0
 public function beginTransaction()
 {
     $this->context->beginTransaction();
 }