Possible bug with PHP library?
Possible bug with PHP library?
When using the postCreate event, it seems its not truely after an entry is submitted to the database.
I have test this by creating a function to run a manual query to check for the entry and nothing is returned.
->on('postCreate', function ($editor, $id, &$values, &$row) {
$this->checkEntry($id);
})
function checkEntry($id) {
$dbData = $this->db->query("SELECT * FROM sections WHERE id = $id LIMIT 1;")->getRow();
dump($dbData);
exit();
}
it returns null, nothing found. Im not sure if this is intentional or not, I still have the id and data, but my concern is that if for whatever reason the database doesnt accept the entry, then I would fire an event for something that doesnt exist.
Any thoughts Allan?
thanks
This question has an accepted answers - jump to answer
Answers
Yes, Editor operates, by default, with the database in a transaction. It is not until the transaction is committed that any other queries that are not in that transaction will see the updated results. This is good for data integrity since if any query in the transaction fails it just rolls back to the previous state rather than leaving it in an undefined state.
The easiest way to resolve this is to disable transactions -
->transaction(false)
before the->process(...)
call.Alternatively, use
$editor->db()
to get the current db instance in the transaction which will give you the latest data.Allan