public function storeMigrationContext($migrationName, array $context)
    {
        $this->createTableIfNeeded();

        // select for update

        // annoyingly enough, neither Doctrine nor EZP provide built in support for 'FOR UPDATE' in their query builders...
        // at least the doctrine one allows us to still use parameter binding when we add our sql particle
        $conn = $this->getConnection();

        $qb = $conn->createQueryBuilder();
        $qb->select('*')
            ->from($this->tableName, 'm')
            ->where('migration = ?');
        $sql = $qb->getSQL() . ' FOR UPDATE';

        $conn->beginTransaction();

        $stmt = $conn->executeQuery($sql, array($migrationName));
        $existingMigrationData = $stmt->fetch(\PDO::FETCH_ASSOC);

        if (is_array($existingMigrationData)) {
            // context exists

            $conn->update(
                $this->tableName,
                array(
                    'context' => $this->contextToString($context),
                    'insertion_date' => time(),
                ),
                array('migration' => $migrationName)
            );
            $conn->commit();

        } else {
            // context did not exist. Create it!

            // commit immediately, to release the lock and avoid deadlocks
            $conn->commit();

            $conn->insert($this->tableName, array(
                'migration' => $migrationName,
                'context' => $this->contextToString($context),
                'insertion_date' => time(),
            ));
        }
    }
public function storeMigrationContext($migrationName, array $context)
    {
        $this->createTableIfNeeded();

        // select for update

        // annoyingly enough, neither Doctrine nor EZP provide built in support for 'FOR UPDATE' in their query builders...
        // at least the doctrine one allows us to still use parameter binding when we add our sql particle
        $conn = $this->getConnection();

        $qb = $conn->createQueryBuilder();
        $qb->select('*')
            ->from($this->tableName, 'm')
            ->where('migration = ?');
        $sql = $qb->getSQL() . ' FOR UPDATE';

        $conn->beginTransaction();

        $stmt = $conn->executeQuery($sql, array($migrationName));
        $existingMigrationData = $stmt->fetch(\PDO::FETCH_ASSOC);

        if (is_array($existingMigrationData)) {
            // context exists

            $conn->update(
                $this->tableName,
                array(
                    'context' => $this->contextToString($context),
                    'insertion_date' => time(),
                ),
                array('migration' => $migrationName)
            );
            $conn->commit();

        } else {
            // context did not exist. Create it!

            // commit immediately, to release the lock and avoid deadlocks
            $conn->commit();

            $conn->insert($this->tableName, array(
                'migration' => $migrationName,
                'context' => $this->contextToString($context),
                'insertion_date' => time(),
            ));
        }
    }
public function storeMigrationContext ( $ migrationName , array $ context ) { $ this -> createTableIfNeeded ( ) ; // select for update // annoyingly enough, neither Doctrine nor EZP provide built in support for 'FOR UPDATE' in their query builders... // at least the doctrine one allows us to still use parameter binding when we add our sql particle $ conn = $ this -> getConnection ( ) ; $ qb = $ conn -> createQueryBuilder ( ) ; $ qb -> select ( '*' ) -> from ( $ this -> tableName , 'm' ) -> where ( 'migration = ?' ) ; $ sql = $ qb -> getSQL ( ) . ' FOR UPDATE' ; $ conn -> beginTransaction ( ) ; $ stmt = $ conn -> executeQuery ( $ sql , array ( $ migrationName ) ) ; $ existingMigrationData = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ; if ( is_array ( $ existingMigrationData ) ) { // context exists $ conn -> update ( $ this -> tableName , array ( 'context' => $ this -> contextToString ( $ context ) , 'insertion_date' => time ( ) , ) , array ( 'migration' => $ migrationName ) ) ; $ conn -> commit ( ) ; } else { // context did not exist. Create it! // commit immediately, to release the lock and avoid deadlocks $ conn -> commit ( ) ; $ conn -> insert ( $ this -> tableName , array ( 'migration' => $ migrationName , 'context' => $ this -> contextToString ( $ context ) , 'insertion_date' => time ( ) , ) ) ; } }
Stores a migration context

@param string $migrationName
@param array $context
Stores a migration context