当前位置: 首页>>代码示例>>PHP>>正文


PHP Connection::commit方法代码示例

本文整理汇总了PHP中Doctrine\DBAL\Connection::commit方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::commit方法的具体用法?PHP Connection::commit怎么用?PHP Connection::commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\DBAL\Connection的用法示例。


在下文中一共展示了Connection::commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: exportData

 public function exportData($export, $reporter)
 {
     $this->conn->beginTransaction();
     try {
         $lastExportedAt = (int) $export['lastExportedAt'];
         $areas = $this->conn->fetchAll('SELECT a.`id`, a.`name`, t.`id` AS `territoryId`, t.`name` AS `territoryName`, a.`customData`, a.`lastUpdatedAt` ' . 'FROM `' . CoreTables::AREA_TBL . '` a ' . 'INNER JOIN `' . CoreTables::TERRITORY_TBL . '` t ON t.`id` = a.`territoryId` ' . 'WHERE a.`projectId` = :projectId AND a.`statusId` = :statusId', [':projectId' => $export['projectId'], ':statusId' => $export['areaStatusId']]);
         $block = new ExportBlock();
         foreach ($areas as $area) {
             $block->addId($area['id']);
             if ($area['lastUpdatedAt'] > $lastExportedAt) {
                 $area['customData'] = json_decode($area['customData']);
                 $block->addUpdatedId($area['id']);
                 $block->addUpdate($area);
             }
         }
         $event = new ExportEvent($export['projectId'], $export['lastExportedAt'], $reporter);
         $event->addBlock('area', $block);
         $event = $this->eventDispatcher->dispatch(ExportEvents::EXPORT_ONGOING, $event);
         $this->conn->executeQuery('UPDATE `' . ExportTables::DATA_EXPORT_TBL . '` SET `lastExportedAt` = :time WHERE `id` = :id', [':time' => time(), ':id' => $export['id']]);
         $this->conn->commit();
         return $event->output();
     } catch (Exception $ex) {
         $this->conn->rollBack();
         throw $ex;
     }
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:26,代码来源:ExportEngine.php

示例2: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     if (!is_file($file)) {
         throw new RuntimeException('File does not exists');
     }
     $verbose = $output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL;
     if (!$verbose) {
         $this->logger->pushHandler(new NullHandler());
     }
     try {
         $this->connection->beginTransaction();
         $result = $this->importService->import(file_get_contents($file));
         $this->connection->commit();
         $output->writeln('Import successful!');
         $output->writeln('The following actions were done:');
         $output->writeln('');
         foreach ($result as $message) {
             $output->writeln('- ' . $message);
         }
     } catch (\Exception $e) {
         $this->connection->rollback();
         $output->writeln('An exception occured during import. No changes are applied to the database.');
         $output->writeln('');
         $output->writeln('Message: ' . $e->getMessage());
         $output->writeln('Trace: ' . $e->getTraceAsString());
     }
     if (!$verbose) {
         $this->logger->popHandler();
     }
 }
开发者ID:apioo,项目名称:fusio-impl,代码行数:31,代码来源:ImportCommand.php

示例3: push

 public function push(array $list)
 {
     $this->create();
     $this->connection->beginTransaction();
     $statement = $this->connection->prepare("\n            INSERT INTO `{$this->table}`(`path`)\n            VALUES (:path)\n        ");
     foreach ($list as $path) {
         $statement->execute(compact('path'));
     }
     $this->connection->commit();
 }
开发者ID:Scrapynizer,项目名称:SearchSkillDeveloper,代码行数:10,代码来源:PathProcessRepository.php

示例4: closeTransaction

 /**
  * Closes the transaction. If the transaction has been marked to rollback, it is rolled back. Otherwise
  * it is committed. The method does nothing, if the transaction is not open.
  */
 public function closeTransaction()
 {
     if ($this->inTransaction) {
         $this->inTransaction = false;
         if ($this->shouldCommit) {
             $this->conn->commit();
         } else {
             $this->conn->rollBack();
         }
         $this->shouldCommit = true;
     }
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:16,代码来源:Transaction.php

示例5: performCommit

 protected function performCommit($identifier = NULL)
 {
     if ($identifier === NULL) {
         return $this->conn->commit();
     }
     $this->conn->createSavepoint($identifier);
 }
开发者ID:koolkode,项目名称:database,代码行数:7,代码来源:Connection.php

示例6: fixVersion

 /**
  * @param string $version
  * @param \DateTime $apply_at
  * @throws \Exception
  */
 public function fixVersion($version, \DateTime $apply_at = null)
 {
     if ($apply_at === null) {
         $apply_at = new \DateTime();
     }
     $this->createTable();
     $this->doctrine->beginTransaction();
     try {
         $this->doctrine->delete(self::TABLE_NAME, array('version' => $version));
         $this->doctrine->insert(self::TABLE_NAME, array('version' => $version, 'apply_at' => $apply_at->format('Y-m-d\\TH:i:s')));
         $this->doctrine->commit();
     } catch (\Exception $ex) {
         $this->doctrine->rollBack();
         throw $ex;
     }
 }
开发者ID:sickhye,项目名称:php-db-migrate,代码行数:21,代码来源:DbTable.php

示例7: commit

 /**
  * @param CommitId $commitId
  * @param Contract $streamContract
  * @param Identifier $streamId
  * @param $expectedStreamRevision
  * @param EventEnvelope[] $eventEnvelopes
  * @throws \Doctrine\DBAL\ConnectionException
  * @throws \Exception
  * @return void
  */
 public function commit(CommitId $commitId, Contract $streamContract, Identifier $streamId, $expectedStreamRevision, array $eventEnvelopes)
 {
     $this->connection->beginTransaction();
     $now = (new DateTimeImmutable('now', new DateTimeZone('UTC')))->format("Y-m-d H:i:s");
     try {
         $this->controlOptimisticConcurrency($streamContract, $streamId, $expectedStreamRevision);
         $nextStreamRevision = $expectedStreamRevision;
         foreach ($eventEnvelopes as $eventEnvelope) {
             $this->connection->executeQuery(Insert::into(self::TABLE_NAME), ['streamContract' => (string) $streamContract, 'streamId' => (string) $streamId, 'streamRevision' => ++$nextStreamRevision, 'eventContract' => (string) $eventEnvelope->getEventContract(), 'eventPayload' => (string) $eventEnvelope->getEventPayload(), 'eventId' => (string) $eventEnvelope->getEventId(), 'commitId' => $commitId, 'utcCommittedTime' => $now]);
         }
         $this->connection->commit();
     } catch (Exception $exception) {
         $this->connection->rollback();
         throw $exception;
     }
 }
开发者ID:dpsarrou,项目名称:EventCentric.Core,代码行数:26,代码来源:MySQLPersistence.php

示例8: massUpsert

 /**
  * Insert multiple rows, if a row with a duplicate key is found will update the row
  * This function assumes that 'id' is the primary key, and is used as a fallback for databases that don't support real upserts
  *
  * @param string $table
  * @param array $rows array of column => value
  * @param null $lastInsertId Optional reference to populate with the last auto increment id
  * @return int The number of affected rows
  *
  * @throws \Doctrine\DBAL\ConnectionException
  * @throws \Exception
  */
 public function massUpsert($table, array $rows, &$lastInsertId = null)
 {
     if (empty($rows)) {
         return 0;
     }
     $rowsToInsert = [];
     $rowsToUpdate = [];
     foreach ($rows as $row) {
         if (!empty($row['id'])) {
             $rowsToUpdate[] = $row;
         } else {
             $rowsToInsert[] = $row;
         }
     }
     $this->db->beginTransaction();
     try {
         $effected = $this->massInsert($table, $rowsToInsert);
         $lastInsertId = $this->getLastInsertId($table) - (count($rowsToInsert) - 1);
         foreach ($rowsToUpdate as $row) {
             $id = $row['id'];
             unset($row['id']);
             $effected += $this->db->update($this->db->quoteIdentifier($table), $this->quoteIdentifiers($row), ['id' => $id]);
         }
         $this->db->commit();
     } catch (\Exception $e) {
         $this->db->rollBack();
         throw $e;
     }
     return $effected;
 }
开发者ID:thewunder,项目名称:corma,代码行数:42,代码来源:QueryHelper.php

示例9: convertToCharacterSetAndCollation

 /**
  * Convert the tables in the current database to use given character set and collation.
  *
  * @param string $characterSet Character set to convert to
  * @param string $collation Collation to set, must be compatible with the character set
  * @param string $outputPathAndFilename
  * @param boolean $verbose
  * @throws ConnectionException
  * @throws DBALException
  */
 protected function convertToCharacterSetAndCollation($characterSet = 'utf8', $collation = 'utf8_unicode_ci', $outputPathAndFilename = null, $verbose = false)
 {
     $statements = ['SET foreign_key_checks = 0'];
     $statements[] = 'ALTER DATABASE ' . $this->connection->quoteIdentifier($this->persistenceSettings['backendOptions']['dbname']) . ' CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
     $tableNames = $this->connection->getSchemaManager()->listTableNames();
     foreach ($tableNames as $tableName) {
         $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' DEFAULT CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
         $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
     }
     $statements[] = 'SET foreign_key_checks = 1';
     if ($outputPathAndFilename === null) {
         try {
             $this->connection->beginTransaction();
             foreach ($statements as $statement) {
                 if ($verbose) {
                     $this->outputLine($statement);
                 }
                 $this->connection->exec($statement);
             }
             $this->connection->commit();
         } catch (\Exception $exception) {
             $this->connection->rollBack();
             $this->outputLine($exception->getMessage());
             $this->outputLine('[ERROR] The transaction was rolled back.');
         }
     } else {
         file_put_contents($outputPathAndFilename, implode(';' . PHP_EOL, $statements) . ';');
     }
 }
开发者ID:neos,项目名称:flow-development-collection,代码行数:39,代码来源:DatabaseCommandController.php

示例10: performInitialSetup

 /**
  * @inheritdoc
  */
 public function performInitialSetup()
 {
     $manager = $this->connection->getSchemaManager();
     $from = $manager->createSchema();
     $to = clone $from;
     $table = $to->createTable($this->getQueueTableName());
     $to->createSequence('job_seq');
     $table->addColumn($this->columns[JobReflector::PROPERTY_ID], 'integer', ['autoincrement' => true]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_QUEUE], 'string');
     $table->addColumn($this->columns[JobReflector::PROPERTY_CREATED], 'datetime');
     $table->addColumn($this->columns[JobReflector::PROPERTY_SCHEDULE], 'datetime');
     $table->addColumn($this->columns[JobReflector::PROPERTY_FAILED], 'boolean', ['notnull' => true, 'default' => false]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_FINISHED], 'datetime', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_RESULT], 'text', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_PROGRESS], 'decimal', ['notnull' => false, 'default' => null, 'precision' => 5, 'scale' => 2]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_LAST_ATTEMPT], 'datetime', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_TIMEOUT], 'datetime', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_RETRY_COUNT], 'integer');
     $table->addColumn($this->columns[JobReflector::PROPERTY_RETRY], 'boolean', ['notnull' => true, 'default' => false]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_PARAMETERS], 'text', ['notnull' => false, 'default' => null]);
     $table->addColumn($this->columns[JobReflector::PROPERTY_VERSION], 'integer');
     $table->addColumn($this->columns['__CLASS__'], 'string');
     $table->setPrimaryKey(array($this->columns[JobReflector::PROPERTY_ID]));
     $sql = $from->getMigrateToSql($to, $this->connection->getDatabasePlatform());
     $this->connection->beginTransaction();
     foreach ($sql as $query) {
         $this->connection->exec($query);
     }
     $this->connection->commit();
     return;
 }
开发者ID:JackPrice,项目名称:phpq,代码行数:34,代码来源:DoctrineDBALDriver.php

示例11: completeTransaction

 /**
  */
 private function completeTransaction()
 {
     $this->connection->commit();
     foreach ($this->stagedEvents as $event) {
         $this->publish(self::EVENT_STORED, $event);
     }
     $this->stagedEvents = [];
 }
开发者ID:alexjohnporter,项目名称:eidetic,代码行数:10,代码来源:DBALEventStore.php

示例12: updateWebsite

 /**
  * Update Website SQL entry according to the BackBee installation.
  *
  * @param     array    Website configuration, must contains 'domain' and 'label' keys
  * @return    array|InvalidArgumentException  Returns domain and label set up in database or an Exception
  */
 public function updateWebsite($configuration)
 {
     if (!is_array($configuration) || !isset($configuration['domain']) || !isset($configuration['label'])) {
         throw new \InvalidArgumentException('array expected with domain and label keyes');
     }
     $domain = $configuration['domain'];
     $label = $configuration['label'];
     try {
         $this->connection->beginTransaction();
         $stmt = $this->connection->executeUpdate('UPDATE site SET server_name = ? , label = ?', array($domain, $label));
         $this->connection->commit();
     } catch (\PDOException $e) {
         $this->connection->rollback();
         throw new \RuntimeException($e->getMessage(), (int) $e->getCode(), $e);
     }
     return $configuration;
 }
开发者ID:Amalec78,项目名称:DemoBundle,代码行数:23,代码来源:DemoWebsiteLoader.php

示例13: commit

 /**
  * Runs the changes to the schema
  */
 public function commit()
 {
     $this->connection->beginTransaction();
     foreach ($this->getChanges() as $sql) {
         $this->connection->query($sql);
     }
     $this->connection->commit();
 }
开发者ID:KasaiDot,项目名称:FoolFrame,代码行数:11,代码来源:SchemaManager.php

示例14: commit

 /**
  * Commit a transaction.
  *
  * @return void
  */
 public function commit()
 {
     try {
         $this->connection->commit();
     } catch (DBALException $e) {
         throw new QueryException($e->getMessage(), $e->getCode(), $e);
     }
 }
开发者ID:nlescure,项目名称:ezpublish-kernel,代码行数:13,代码来源:ConnectionHandler.php

示例15: delete

 /**
  * Delete a workflow by its ID
  *
  * @param int $workflowId
  * @return void
  */
 public function delete($workflowId)
 {
     $this->conn->beginTransaction();
     try {
         // delete only those two, the rest should be deleted automatically through cascading foreign keys
         $this->conn->delete($this->options->variableHandlerTable(), array('workflow_id' => $workflowId));
         $this->conn->delete($this->options->workflowTable(), array('workflow_id' => $workflowId));
         $this->conn->commit();
     } catch (\Exception $e) {
         $this->conn->rollback();
     }
 }
开发者ID:beberlei,项目名称:Doctrine-Workflow,代码行数:18,代码来源:DefinitionStorage.php


注:本文中的Doctrine\DBAL\Connection::commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。