Jump to content

PDO Transactions


pcreact
 Share

Recommended Posts

Hello,

I'm developing a module that takes a json string and uses it to create a tree of PW pages.

I build up the tree by assigning the parent of every new page.

I want this to happen on an all-or-nothing basis, does PW have some sort of wrapper for this or would I need to get hold of the connection object and do a $conn->beginTransaction()...?

Any help greatly appreciated,

Phil.

**Edit** - Sorry I just realised this should probably be in the API forum.

Link to comment
Share on other sites

Your best bet is to use the API directly rather than trying to go it alone with the DB driver. Though the dev branch (and upcoming PW 2.4) use the PDO driver and you could certainly manage your own transactions in there if you wanted to. But I'm not sure you need transactions to accomplish this. I'm also not sure what sort of fatal error you are expecting may occur during the creation of your tree? But if the data in the JSON has non-unique page names with the same parent or something, then it's certainly possible. So one route you could take would be to build your tree within a try/catch and if an exception occurs during the process of building your tree, have your catch call $pages->delete($rootPage, true); to perform a recursive delete on everything that was created. Another strategy could be to just make everything (or just your $rootPage) unpublished during creation, and published upon success. 

Link to comment
Share on other sites

Looking at implementing or using transactions is probably going to lead to a dead end. Transactions are not supported at the database level for tables that use the MyISAM storage engine (which all of the ProcessWire tables use) - at least, to my most recent knowledge of MySQL versions.

  • Like 1
Link to comment
Share on other sites

I think that it is okay to use InnoDB with ProcessWire though. At least, I seem to recall one person here had converted to it without issue. When ProcessWire was originally being developed, InnoDB did not support fulltext indexes, but apparently it does now. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...