0

This is what I'm trying to do:

I save my item in the model, then I call a method that can throw an exception if something goes wrong.

If I catch the exception, I want to rollback, this is my override of the save method:

public function save($data) {
    $db = JFactory::getDbo();
    $db->transactionStart();
    $retVal = parent::save($data);
    if ($retVal) {
        try {
            $this->_doSomething();
            $db->transactionCommit();
        } catch (Exception $exc) {
            $db->transactionRollback();
            JFactory::getApplication('administrator')
            ->enqueueMessage($exc->getMessage(), 'error');
            return false;// THIS MAKES ROLLBACK FAIL, TO MAKE IT WORK I HAVE TO COMMENT THIS.
        }
    }
    return $retVal;
}

It only works if my method returns true anyway.

To me it should be more correct that the method in this case returns false, because the saving is not done and because if it returns true, Joomla outputs a misleading message as if saving succeded. But if it does rollback somehow it fails.

What makes rollback fail if the method save() returns false?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.