Making a multiple different editor instances be one singular transaction

Making a multiple different editor instances be one singular transaction

Martyn.sMartyn.s Posts: 8Questions: 3Answers: 0

Hello there, I'm currently working on a system where I have the user create a new entry via one editor, and then immediately create the quantity child entries that they set in the initial editor. This is important because each cild entry has different data tied to and must be set on creation by the user.

I was wondering if there was a way to make all of this process one seamless transaction with my database, so that if the user decides to exit the child editor mid adding, the parent element and other already filled out child elements are rolled back to avoid data errors.

Thank you!

Answers

  • rf1234rf1234 Posts: 3,177Questions: 92Answers: 438
    edited September 8

    You should be able to do this using Editor's database methods. There is some documentation on them, but I couldn't find it right now. You would need to search in the Editor PHP files, I guess.

    How would I do it?
    - I would first turn off autocommit using Editor's db-handler
    - Then I would call beginTransaction()
    - Depending on the outcome of the user's work I would either
    - commit() the changes or
    - rollBack() the changes
    - finally I would turn autocommit back on.

    These are the methods my own db handler is providing for this. You would need to find Editor's methods though.

    public function autocommitOff(){
        return $this->dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, false);
    }
    public function autocommitOn(){
        return $this->dbh->setAttribute(PDO::ATTR_AUTOCOMMIT, true);
    }
    public function beginTransaction(){
        return $this->dbh->beginTransaction();
    }
    public function endTransaction(){
        if ( $this->dbh->inTransaction() ) {
            return $this->dbh->commit();
        }
    }
    public function inTransaction(){
        return $this->dbh->inTransaction();
    }
    public function cancelTransaction(){
        return $this->dbh->rollBack();
    }
    

    And here is something from the Editor docs. Good luck!
    https://editor.datatables.net/docs/2.3.2/php/classes/DataTables-Database-Query.html

Sign In or Register to comment.