Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.0 Upgrade started throwing "There is no active transaction" #201

Closed
mumtazumair opened this issue Feb 9, 2022 · 6 comments · Fixed by #365
Closed

PHP 8.0 Upgrade started throwing "There is no active transaction" #201

mumtazumair opened this issue Feb 9, 2022 · 6 comments · Fixed by #365
Assignees
Labels
bug Something isn't working discussion topic is discussed before any action taken
Milestone

Comments

@mumtazumair
Copy link

As other frameworks also reported the same issue: doctrine/migrations#1202

I am facing this issue in Zend as well.

CREATE TABLE IF NOT EXISTS schema_update (
id_schema_update INT UNSIGNED NOT NULL AUTO_INCREMENT ,
module VARCHAR(25) NOT NULL ,
file VARCHAR(255) NOT NULL ,
duration int(10) NOT NULL COMMENT 'Duration in seconds that the migration takes executing',
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
statements TEXT DEFAULT NULL,
PRIMARY KEY (id_schema_update)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

Migration failed:
There is no active transaction
#0 /vendor/zendframework/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php(290): PDO->commit()
#1 /vendor/zendframework/zendframework1/library/Zend/Db/Adapter/Abstract.php(484): Zend_Db_Adapter_Pdo_Abstract->_commit()
#2 /library/Shm/Dao/Transaction.php(119): Zend_Db_Adapter_Abstract->commit()
#3 /application/modules/ext/maintenance/models/SchemaUpdate.php(207): Shm_Dao_Transaction->commit()
#4 /application/modules/ext/maintenance/models/SchemaUpdate.php(107): Maintenance_Model_SchemaUpdate->runMigrations(true)

Any help is much appreciated.

@hungtrinh
Copy link

Root cause here:
https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.pdo-mysql

Quick & dirty way to back behavior like before php 8.x

You need something like that, patch content of file

Zend/Db/Adapter/Pdo/Abstract.php

   /**
     * Commit a transaction.
     */
    protected function _commit()
    {
        $this->_connect();
        if (!$this->_connection->inTransaction()) {
            return;
        }
        $this->_connection->commit();
    }

    /**
     * Roll-back a transaction.
     */
    protected function _rollBack()
    {
        $this->_connect();
        if (!$this->_connection->inTransaction()) {
            return;
        }
        $this->_connection->rollBack();
    }

@grisha2217
Copy link

Root cause here: https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.pdo-mysql

Quick & dirty way to back behavior like before php 8.x

You need something like that, patch content of file

Zend/Db/Adapter/Pdo/Abstract.php

   /**
     * Commit a transaction.
     */
    protected function _commit()
    {
        $this->_connect();
        if (!$this->_connection->inTransaction()) {
            return;
        }
        $this->_connection->commit();
    }

    /**
     * Roll-back a transaction.
     */
    protected function _rollBack()
    {
        $this->_connect();
        if (!$this->_connection->inTransaction()) {
            return;
        }
        $this->_connection->rollBack();
    }

This is applies only for PDO? What's about mysqli?
After updating to php 8 & zf1 i get "SAVEPOINT DOES NOT EXISTS" sometimes

@hungtrinh
Copy link

yep, about issue SAVEPOINT DOES NOT EXISTS it's same root cause:
https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html

@pdolinaj
Copy link

pdolinaj commented Aug 6, 2023

That's a good fix! Can this be please added to master branch?

For now I just added overwrite in my composer file:

"scripts": {
    "post-install-cmd": [
      "@php -r \"copy('vendor-overrides/shardj/zf1-future/library/Zend/Db/Adapter/Pdo/Abstract.php', 'vendor/shardj/zf1-future/library/Zend/Db/Adapter/Pdo/Abstract.php');\""
    ],
    "post-update-cmd": [
      "@php -r \"copy('vendor-overrides/shardj/zf1-future/library/Zend/Db/Adapter/Pdo/Abstract.php', 'vendor/shardj/zf1-future/library/Zend/Db/Adapter/Pdo/Abstract.php');\""
    ]
  }

@develart-projects
Copy link
Collaborator

Anyone to create PR on this?

@develart-projects develart-projects added enhancement New feature or request discussion topic is discussed before any action taken labels Aug 10, 2023
@hungtrinh
Copy link

hungtrinh commented Aug 11, 2023

Anyone to create PR on this?

i'm here :D solution above. i'm thinking about write test case to cover this case, will create PR soon

@develart-projects develart-projects added this to the 1.23.1 milestone Aug 11, 2023
@develart-projects develart-projects added bug Something isn't working and removed enhancement New feature or request labels Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discussion topic is discussed before any action taken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants