public function save()
{
$identifier = $this->identifier();
$identifier = implode(', ', $identifier);
// If column aggregation is used on this model we will have $class_type defined. Ensure it's set model is loaded
if (!empty($this->class_type)) {
Doctrine::initializeModels($this->class_type);
}
$identifier = $this->identifier();
$identifier = implode(', ', $identifier);
// Look for Kohana errors, and if they exist, throw Bluebox_Validation_Exception
if (count(Bluebox_Controller::$validation->field_names()) > 0 and Bluebox_Controller::$validation->validate() == FALSE) {
Kohana::log('debug', 'Kohana validation failed while saving ' . get_class($this) . ' ' . $identifier, 1);
throw new Bluebox_Validation_Exception('Kohana validation failed on ' . get_class($this) . ' ' . $identifier, 1);
// re-throw
}
try {
// Store only the first record in this save event, making it available for any events that may need to know who started the save
if (!self::getBaseTransactionObject()) {
self::setBaseSaveObject($this);
$invalid = $this->checkValidation();
if (!empty($invalid)) {
throw new Doctrine_Validator_Exception($invalid);
}
}
parent::save();
// Done with any events that may use this
if (self::getBaseTransactionObject() == $this) {
self::setBaseSaveObject(NULL);
}
Kohana::log('debug', 'Saved record ' . get_class($this) . ' ' . $identifier);
return TRUE;
} catch (Doctrine_Validator_Exception $e) {
Kohana::log('error', 'Doctrine_Validator_Exception on record ' . get_class($this) . ' ' . $identifier . ': ' . $e->getMessage());
self::normalizeErrors($e);
return FALSE;
} catch (Doctrine_Transaction_Exception $e) {
Kohana::log('error', 'Doctrine_Transaction_Exception on record ' . get_class($this) . ' ' . $identifier . ': ' . $e->getMessage());
self::setBaseSaveObject(NULL);
throw new Doctrine_Transaction_Exception($e->getMessage());
return FALSE;
} catch (Doctrine_Connection_Exception $e) {
Kohana::log('error', 'Doctrine_Connection_Exception on record ' . get_class($this) . ' ' . $identifier . ': ' . $e->getMessage());
self::setBaseSaveObject(NULL);
throw new Doctrine_Connection_Exception($e->getMessage());
return FALSE;
} catch (Exception $e) {
Kohana::log('error', 'Unhandled ' . get_class($e) . ' on record ' . get_class($this) . ' ' . $identifier . ': ' . $e->getMessage());
self::setBaseSaveObject(NULL);
throw new Exception($e->getMessage());
return FALSE;
}
}