{"id":25738359,"url":"https://github.com/blackstareye/wp_transactionmanager","last_synced_at":"2026-05-15T09:48:13.542Z","repository":{"id":201036330,"uuid":"380818319","full_name":"Blackstareye/wp_transactionmanager","owner":"Blackstareye","description":"This is a tiny helper class to perform transaction based queries (ACID) to the wordpress database. You can use commit and rollback like you are used to do with native database connection.","archived":false,"fork":false,"pushed_at":"2021-06-27T20:34:58.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-10-18T17:46:52.331Z","etag":null,"topics":["blackeye","blackstareye","php","transaction","wordpress","wordpress-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Blackstareye.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-06-27T19:05:05.000Z","updated_at":"2023-10-18T17:46:53.840Z","dependencies_parsed_at":null,"dependency_job_id":"d7498493-a529-4892-b241-733d58a7caa1","html_url":"https://github.com/Blackstareye/wp_transactionmanager","commit_stats":null,"previous_names":["blackstareye/wp_transactionmanager"],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blackstareye%2Fwp_transactionmanager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blackstareye%2Fwp_transactionmanager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blackstareye%2Fwp_transactionmanager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Blackstareye%2Fwp_transactionmanager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Blackstareye","download_url":"https://codeload.github.com/Blackstareye/wp_transactionmanager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240811086,"owners_count":19861349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blackeye","blackstareye","php","transaction","wordpress","wordpress-plugin"],"created_at":"2025-02-26T07:30:08.053Z","updated_at":"2026-05-15T09:48:08.482Z","avatar_url":"https://github.com/Blackstareye.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/Tu6B89Cc3","https://www.patreon.com/black_eye_s"],"categories":[],"sub_categories":[],"readme":"\u003c!-- PROJECT LOGO --\u003e\r\n\u003cbr /\u003e\r\n\u003cp align=\"center\"\u003e\r\n\r\n  \u003ch3 align=\"center\"\u003ePHP Wordpress Transaction Modul\u003c/h3\u003e\r\n\r\n  \u003cp align=\"center\"\u003e\r\n    This is a tiny helper class to perform transaction based  queries (ACID) to the wordpress database.  You can use commit and rollback like you are used to do with native database connection.\r\n    \u003cbr /\u003e\r\n    \u003ca href=\"https://github.com/Blackstareye/wp_transactionmanager/issues\"\u003eReport Bug\u003c/a\u003e\r\n    ·\r\n    \u003ca href=\"https://github.com/Blackstareye/wp_transactionmanager/issues\"\u003eRequest Feature\u003c/a\u003e\r\n  \u003c/p\u003e\r\n\u003c/p\u003e\r\n\r\n\u003c!-- TABLE OF CONTENTS --\u003e\r\n\u003cdetails open=\"open\"\u003e\r\n  \u003csummary\u003e\u003ch2 style=\"display: inline-block\"\u003eTable of Contents\u003c/h2\u003e\u003c/summary\u003e\r\n  \u003col\u003e\r\n    \u003cli\u003e\r\n      \u003ca href=\"#about-the-project\"\u003eAbout The Project\u003c/a\u003e\r\n    \u003c/li\u003e\r\n    \u003cli\u003e\r\n      \u003ca href=\"#getting-started\"\u003eGetting Started\u003c/a\u003e\r\n    \u003c/li\u003e\r\n    \u003cli\u003e\u003ca href=\"#backstory\"\u003eBackstory\u003c/a\u003e\u003c/li\u003e\r\n    \u003cli\u003e\u003ca href=\"#methods\"\u003eMethods\u003c/a\u003e\u003c/li\u003e\r\n    \u003cli\u003e\u003ca href=\"#roadmap\"\u003eRoadmap\u003c/a\u003e\u003c/li\u003e\r\n    \u003cli\u003e\u003ca href=\"#contributing\"\u003eContributing\u003c/a\u003e\u003c/li\u003e\r\n    \u003cli\u003e\u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\u003c/li\u003e\r\n    \u003cli\u003e\u003ca href=\"#contact\"\u003eContact\u003c/a\u003e\u003c/li\u003e\r\n    \u003cli\u003e\u003ca href=\"#support\"\u003esupport\u003c/a\u003e\u003c/li\u003e\r\n  \u003c/ol\u003e\r\n\u003c/details\u003e\r\n\r\n\u003c!-- ABOUT THE PROJECT --\u003e\r\n## About The Project\r\n\r\nThis PHP class will give you the ability to use\r\n\r\n* update\r\n* insert\r\n* delete\r\n* vanilla sql\r\n* prepared sql\r\n\r\nqueries in a transaction based way **in wordpress**. So you are able to manual rollback or commit your queries.\r\n\r\nI also implemented a rollback if there were any errors in the execution of the query.\r\nIn this case, a rollback will be executed and an error state will be set.\r\nIf there is an error state, it is not possible to execute any other queries. This will prevent a inconsistent database.\r\n\r\nYou have to manually reset it if you want to perform a query in the same task where you encountered the error (not recommended).\r\n\r\n### Getting Started\r\n\r\nUse the Manager like this:\r\n\r\n```php\r\n        //instantiate\r\n        $transaction = new TransactionManager();\r\n        //commit\r\n        $transaction-\u003ebeginTransaction();\r\n        $transaction-\u003eperformTransaction_use_query(\"INSERT INTO $test_table_name (test_data) VALUES (1)\");\r\n        $transaction-\u003ecommit();\r\n\r\n        //Rollback\r\n        $transaction-\u003ebeginTransaction();\r\n        $transaction-\u003eperformTransaction_use_query(\"INSERT INTO $test_table_name (test_data) VALUES (0)\");\r\n        $transaction-\u003erollback();\r\n```\r\n\r\n## Backstory\r\n\r\nI realized that Wordpress does not have the ability to perform transaction based data queries.\r\n\r\n### Quick The more you know\r\n\r\nStill I can't believe that wordpress, a well known blog framework, does not use database transactions.\r\nThey just use the autocommit feature of the underlying database.\r\nSo if you have 2  update requests on the same data record, you will have a race condition unless wordpress prevents this on the administration page layer.\r\nAlso if you have a complex isolated sql query batch to run, you have to delete every affected line if you encountered an error.\r\n**BUT** this is not necessary if you use commit and rollbacks.\r\n\r\n### Why do you need that - A little story\r\n\r\nSo I wanted to implement a Database Migration Tool so  if I have an major update in my plugin which affects the database structure, I can perform a database migration too. But What if it fails or there is a bug? If I would use the vanilla database commands like update_postmeta I  would have to store every affected record and somehow *undo* my actions. This is messy af and also very likely to produce some inconsistency in the database.\r\nSo I wanted to have a transaction based behaviour like I am used to in non wordpress applications.\r\n\r\nSidenote:\r\nYeah my usecase  is an not so common thing todo in wordpress, but I needed it and heres the solution if you also need something like that.\r\n\r\n### Methods\r\n\r\n#### constructor\r\n\r\nIf you have a logging handler (like Monolog) you can initialize it here and uncomment the logging lines in the code.\r\n\r\n#### resetError\r\n\r\nresets the error state.\r\n\r\n#### setError\r\n\r\nSets the Manager in error state. Now it is not possible to perform any transaction based queries.\r\n\r\n#### error\r\n\r\nIncreases the error count and (if set) writes an info into the logging file.\r\n\r\n#### beginTransaction\r\n\r\nThis starts the transaction mode. Now every query is not directly commited.\r\n\r\nIt uses the standard mysql **START TRANSACTION** command.\r\n\r\n#### rollback\r\n\r\n**Undo's** the queries that were run before between using begin transaction and  rollback.\r\n\r\n#### commit\r\n\r\nMakes your executed queries persistent.\r\n\r\n#### performTransaction_use_prepare\r\n\r\nRuns  an [prepared](https://developer.wordpress.org/reference/classes/wpdb/prepare//) SQL query. If it fails it rollbacks. And enables the error state.\r\n\r\n#### performTransaction_use_query\r\n\r\nExecutes the query in transaction mode.\r\nIf it fails it rollbacks. And enables the error state.\r\n\r\n#### performTransaction_insert\r\n\r\nExecutes the [wp-\u003einsert](https://developer.wordpress.org/reference/classes/wpdb/insert/) in transaction mode.\r\nIf it fails it rollbacks. And enables the error state.\r\n\r\n#### performTransaction_update\r\n\r\nExecutes the [wp-\u003eupdate](https://developer.wordpress.org/reference/classes/wpdb/update/) in transaction mode.\r\nIf it fails it rollbacks. And enables the error state.\r\n\r\n#### performTransaction_delete\r\n\r\nExecutes the [wp-\u003edelete](https://developer.wordpress.org/reference/classes/wpdb/delete/) in transaction mode.\r\nIf it fails it rollbacks. And enables the error state.\r\n\r\n#### testTransactionModule\r\n\r\nThis tests if the transaction mode is possible with your underlying db.\r\nYou have to use xDebug and your database client so you can monitor if everything runs well.\r\n\r\nOnly after a commit, the data should be visible.\r\nNeither after a rollback nor before commiting.\r\n\r\n## Roadmap\r\n\r\n* make the readme prettier\r\n* develop a wordpress plugin with filter-hooks for transaction handling.\r\n\r\nSee the [open issues](https://github.com/Blackstareye/wp_transactionmanager/issues) for a list of proposed features (and known issues).\r\n\r\n\u003c!-- CONTRIBUTING --\u003e\r\n## Contributing\r\n\r\nIf you have an idea for amazing feature or a nice way to do things more easily in bash you can submit it like the following:\r\n\r\n1. Fork the Project\r\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\r\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\r\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\r\n5. Open a Pull Request\r\n\r\n## License\r\n\r\nDistributed under the GPL version 3. See `LICENSE` for more information.\r\n\r\n\u003c!-- Images are licensed under the License [Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)](https://creativecommons.org/licenses/by-nc-nd/4.0/) --\u003e\r\n\r\n\u003c!-- CONTACT --\u003e\r\n## Contact\r\n\r\nBlackeye - [@BlackeyeM](https://twitter.com/BlackeyeM) - private_blackeye+transaction@posteo.de\r\n\r\nProject Link: [https://github.com/Blackstareye/wp_transactionmanager](https://github.com/Blackstareye/wp_transactionmanager)\r\n\r\n\u003c!-- ACKNOWLEDGEMENTS --\u003e\r\n## Support\r\n\r\nIf you like what I am doing, you can support me with a little Tip / Donation on those pages:\r\n\r\n* [instantgaming](https://www.instant-gaming.com/igr/blackeyes/)  \r\n* [Tipee Donation](https://www.tipeeestream.com/blackeye/donation)\r\n* [BuyMeACoffee](https://www.buymeacoffee.com/Tu6B89Cc3)\r\n* [Patreon](https://www.patreon.com/black_eye_s)\r\n\r\nYou can also just **share** this repo or any other repo  from me if you like it :) This is also a great kind of support.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackstareye%2Fwp_transactionmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblackstareye%2Fwp_transactionmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblackstareye%2Fwp_transactionmanager/lists"}