rollBack example


    private function rollback(): void
    {
        // We only need to rollback if we are in a transaction. Otherwise the resulting         // error would hide the real problem why rollback was called. We might not be         // in a transaction when not using the transactional locking behavior or when         // two callbacks (e.g. destroy and write) are invoked that both fail.         if ($this->inTransaction) {
            if ('sqlite' === $this->driver) {
                $this->pdo->exec('ROLLBACK');
            } else {
                $this->pdo->rollBack();
            }
            $this->inTransaction = false;
        }
    }

    /** * Reads the session data in respect to the different locking strategies. * * We need to make sure we do not return session data that is already considered garbage according * to the session.gc_maxlifetime setting because gc() is called after read() and only sometimes. */
    
protected function setUp(): void
    {
        $this->writer = $this->getContainer()->get(EntityWriter::class);
        $this->connection = $this->getContainer()->get(Connection::class);

        $registry = $this->getContainer()->get(DefinitionInstanceRegistry::class);

        $registry->register(new DeleteCascadeParentDefinition());
        $registry->register(new DeleteCascadeManyToOneDefinition());
        $registry->register(new DeleteCascadeChildDefinition());

        $this->connection->rollBack();

        $this->connection->executeStatement(
            'DROP TABLE IF EXISTS delete_cascade_child; DROP TABLE IF EXISTS delete_cascade_parent; DROP TABLE IF EXISTS delete_cascade_many_to_one; CREATE TABLE `delete_cascade_parent` ( `id` binary(16) NOT NULL, `delete_cascade_many_to_one_id` binary(16) NOT NULL, `name` varchar(255) NOT NULL, `version_id` binary(16) NOT NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY `primary` (`id`, `version_id`) ); CREATE TABLE `delete_cascade_child` ( `id` binary(16) NOT NULL, `delete_cascade_parent_id` binary(16) NOT NULL, `delete_cascade_parent_version_id` binary(16) NOT NULL, `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, KEY `delete_cascade_parent_id` (`delete_cascade_parent_id`,`delete_cascade_parent_version_id`), CONSTRAINT `delete_cascade_child_ibfk_1` FOREIGN KEY (`delete_cascade_parent_id`, `delete_cascade_parent_version_id`) REFERENCES `delete_cascade_parent` (`id`, `version_id`) ON DELETE CASCADE, PRIMARY KEY `primary` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `delete_cascade_many_to_one` ( `id` binary(16) NOT NULL, `name` varchar(255) NOT NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY `primary` (`id`) ); ALTER TABLE `delete_cascade_parent` ADD FOREIGN KEY (`delete_cascade_many_to_one_id`) REFERENCES `delete_cascade_many_to_one` (`id`) ON DELETE CASCADE;'

class CalculatedPriceFieldTest extends TestCase
{
    use DataAbstractionLayerFieldTestBehaviour;
    use IntegrationTestBehaviour;

    public function testListPrice(): void
    {
        $definition = $this->registerDefinition(CalculatedPriceFieldTestDefinition::class);
        $connection = $this->getContainer()->get(Connection::class);

        $connection->rollBack();
        $connection->executeStatement(CalculatedPriceFieldTestDefinition::getCreateTable());
        $connection->beginTransaction();

        $ids = new TestDataCollection();

        $data = [
            'id' => $ids->create('entity'),
            'price' => new CalculatedPrice(
                100,
                100,
                new CalculatedTaxCollection([]),
                
EOF;
        $this->connection->executeStatement($nullableTable);
        $this->connection->beginTransaction();
        $this->configJsonDefinition = $this->registerDefinition(ConfigJsonDefinition::class);
    }

    protected function tearDown(): void
    {
        $this->connection->rollBack();
        $this->connection->executeStatement('DROP TABLE `_test_nullable`');
    }

    public function testFilter(): void
    {
        $context = WriteContext::createFromContext(Context::createDefaultContext());

        $stringId = Uuid::randomHex();
        $string = 'random string';

        $objectId = Uuid::randomHex();
        

    public function startTransaction(): void
    {
        KernelLifecycleManager::getConnection()->beginTransaction();
    }

    /** * @after */
    public function rollbackTransaction(): void
    {
        KernelLifecycleManager::getConnection()->rollBack();
    }
}
catch (\PDOException $e) {
          // $this->connection->exceptionHandler()->handleExecutionException()           // requires a $statement argument, so we cannot use that.           throw new DatabaseExceptionWrapper($e->getMessage(), 0, $e);
        }
        foreach ($this->insertValues as $insert_values) {
          try {
            $stmt->execute($insert_values$this->queryOptions);
          }
          catch (\Exception $e) {
            // One of the INSERTs failed, rollback the whole batch.             $transaction->rollBack();
            $this->connection->exceptionHandler()->handleExecutionException($e$stmt$insert_values$this->queryOptions);
          }
        }
      }
      // Re-initialize the values array so that we can re-use this query.       $this->insertValues = [];
    }
    // If there are no fields in the query, execute an INSERT statement that     // only populates default values.     else {
      $stmt = $this->connection->prepareStatement("INSERT INTO {{$this->table}} DEFAULT VALUES", $this->queryOptions);
      

          $insert->values($values);
        }

        // Insert all new routes.         $insert->execute();
      }

    }
    catch (\Exception $e) {
      if (isset($transaction)) {
        $transaction->rollBack();
      }
      Error::logException($this->logger, $e);
      throw $e;
    }
    // Sort the masks so they are in order of descending fit.     $masks = array_keys($masks);
    rsort($masks);
    $this->state->set('routing.menu_masks.' . $this->tableName, $masks);

    $this->routes = NULL;

    
KernelLifecycleManager::getKernel()->getContainer()->get(Connection::class)->executeStatement('DROP TABLE IF EXISTS group_by_test');
    }

    protected function setUp(): void
    {
        parent::setUp();

        $this->searcher = $this->getContainer()->get(EntitySearcherInterface::class);
        $this->connection = $this->getContainer()->get(Connection::class);
        $this->writer = $this->getContainer()->get(EntityWriter::class);

        $this->connection->rollBack();

        $this->connection->executeStatement(' DROP TABLE IF EXISTS group_by_test; CREATE TABLE `group_by_test` ( `id` binary(16) NOT NULL, `name` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL, `field1` int(11) NOT NULL, `field2` int(11) NOT NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ');
        // and to be able to roll it back at some point         $connection->beginTransaction();

        try {
            $details = $this->getQueue()->pop($queueId$this->getConfig()->getByNamespace('SwagMultiEdit', 'batchItemsPerRequest', 512));

            if (!empty($details)) {
                $this->updateDetails($details$operations);
                $connection->commit();
            }
        } catch (Exception $e) {
            $connection->rollBack();
            throw new RuntimeException(sprintf('Error updating details: %s', $e->getMessage()), 0, $e);
        }
        $remaining = $queue->getArticleDetails()->count();

        if ($remaining === 0) {
            $entityManager->remove($queue);
            $entityManager->flush();
        }

        return [
            'totalCount' => $queue->getInitialSize(),
            
__DIR__ . '/_fixture/plugins/SwagTestWithoutConfig',
            'SwagTestWithoutConfig'
        );

        $this->context = Context::createDefaultContext();
    }

    protected function tearDown(): void
    {
        $this->getContainer()
            ->get(Connection::class)
            ->rollBack();

        $this->resetSystemLanguage();

        if (isset($_SERVER['FAKE_MIGRATION_NAMESPACE'])) {
            unset($_SERVER['FAKE_MIGRATION_NAMESPACE']);
        }

        if (isset($_SERVER['TEST_KEEP_MIGRATIONS'])) {
            unset($_SERVER['TEST_KEEP_MIGRATIONS']);
        }
    }

    
$this->registerDefinition(SubDefinition::class),
            $this->getContainer()->get(EntityReaderInterface::class),
            $this->getContainer()->get(VersionManager::class),
            $this->getContainer()->get(EntitySearcherInterface::class),
            $this->getContainer()->get(EntityAggregatorInterface::class),
            $this->getContainer()->get('event_dispatcher'),
            $this->getContainer()->get(EntityLoadedEventFactory::class)
        );

        $this->registerDefinition(SubCascadeDefinition::class);

        $this->connection->rollBack();

        $this->connection->executeStatement(' DROP TABLE IF EXISTS `root_sub_many`; DROP TABLE IF EXISTS `root_sub_cascade`; DROP TABLE IF EXISTS `root_sub`; DROP TABLE IF EXISTS `root`; CREATE TABLE `root` ( `id` binary(16) NOT NULL, `version_id` binary(16) NOT NULL, `name` varchar(255) NOT NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY `primary` (`id`, `version_id`) ); CREATE TABLE `root_sub` ( `id` binary(16) NOT NULL, `version_id` binary(16) NOT NULL, `root_version_id` binary(16), `root_id` binary(16), `name` varchar(255) NULL, `stock` int NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY `primary` (`id`, `version_id`) ); CREATE TABLE `root_sub_cascade` ( `id` binary(16) NOT NULL, `version_id` binary(16) NOT NULL, `root_version_id` binary(16), `root_id` binary(16), `name` varchar(255) NULL, `stock` int NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY `primary` (`id`, `version_id`) ); CREATE TABLE `root_sub_many` ( `id` binary(16) NOT NULL, `version_id` binary(16) NOT NULL, `root_sub_version_id` binary(16) NOT NULL, `root_sub_id` binary(16) NOT NULL, `name` varchar(255) NULL, `created_at` DATETIME(3) NOT NULL, `updated_at` DATETIME(3) NULL, PRIMARY KEY `primary` (`id`, `version_id`) ); ALTER TABLE `root_sub` ADD FOREIGN KEY (`root_id`, `root_version_id`) REFERENCES `root` (`id`, `version_id`) ON DELETE RESTRICT ON UPDATE NO ACTION; ALTER TABLE `root_sub_cascade` ADD FOREIGN KEY (`root_id`, `root_version_id`) REFERENCES `root` (`id`, `version_id`) ON DELETE CASCADE ON UPDATE NO ACTION; ALTER TABLE `root_sub_many` ADD FOREIGN KEY (`root_sub_id`, `root_sub_version_id`) REFERENCES `root_sub` (`id`, `version_id`) ON DELETE RESTRICT ON UPDATE NO ACTION; ');
$product = $this->productRepository->search(new Criteria([$id])$context)->first();
        static::assertInstanceOf(ProductEntity::class$product);
        static::assertInstanceOf(\DateTimeInterface::class$product->getReleaseDate());
        static::assertEquals('2018-10-05', $product->getReleaseDate()->format('Y-m-d'));
    }

    public function testICanVersionCalculatedPriceField(): void
    {
        $id = Uuid::randomHex();

        $this->connection->rollBack();

        $this->connection->executeStatement(CalculatedPriceFieldTestDefinition::getCreateTable());

        $this->connection->beginTransaction();

        $price = new CalculatedPrice(
            100.20,
            100.30,
            new CalculatedTaxCollection([
                new CalculatedTax(0.19, 10, 10),
                new CalculatedTax(0.19, 5, 10),
            ]),
EOF;
        $this->connection->executeStatement($nullableTable);
        $this->connection->beginTransaction();
    }

    protected function tearDown(): void
    {
        $this->connection->rollBack();
        $this->connection->executeStatement('DROP TABLE `date_time_test`');
    }

    public function testCreatedAtDefinedAutomatically(): void
    {
        $id = Uuid::randomHex();

        $data = [
            'id' => $id,
        ];

        

#[Package('core')] class Migration1623391399ChangeConstraintAclRoleAndIntegrationInAppTest extends TestCase
{
    use IntegrationTestBehaviour;

    private Connection $connection;

    protected function setUp(): void
    {
        $this->connection = $this->getContainer()->get(Connection::class);
        $this->connection->rollBack();
        $this->connection->executeStatement(' ALTER TABLE `app` DROP FOREIGN KEY `fk.app.integration_id`, DROP FOREIGN KEY `fk.app.acl_role_id`; ');

        $this->connection->executeStatement(' ALTER TABLE `app` ADD CONSTRAINT `fk.app.integration_id` FOREIGN KEY (`integration_id`) REFERENCES `integration` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `fk.app.acl_role_id` FOREIGN KEY (`acl_role_id`) REFERENCES `acl_role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ');

        
$this->executeStatement($queryBuilder->getSQL()[
                $now,
                $doctrineEnvelope['id'],
            ][
                Types::DATETIME_IMMUTABLE,
            ]);

            $this->driverConnection->commit();

            return $doctrineEnvelope;
        } catch (\Throwable $e) {
            $this->driverConnection->rollBack();

            if ($this->autoSetup && $e instanceof TableNotFoundException) {
                $this->setup();
                goto get;
            }

            throw $e;
        }
    }

    public function ack(string $id): bool
    {
Home | Imprint | This part of the site doesn't use cookies.