/** * Saves the model to your database. If $data[$this->_primary_key] is empty, * it will do a database INSERT and assign the inserted row id to * $data[$this->_primary_key]. * * @param mixed $validation a manual validation object to combine the model properties with * @param mixed $commit indica se è necessario effetuare il commit delle query * * @return int * * @throws Kohana_Database_Exception */ public function save($validation = NULL, $commit = TRUE) { if ($this->_allow_rollback === FALSE) { return $this->_save($validation); } if (!AutoModeler::transaction_started()) { if (is_null(AutoModeler::base_autocommit()) or AutoModeler::base_autocommit() == '1') { AutoModeler::base_autocommit(AutoModeler::autocommit()); AutoModeler::autocommit(0); } Database::instance()->begin(); AutoModeler::$_transaction_started = TRUE; } try { $return = $this->_save($validation); if ($commit) { Database::instance()->commit(); AutoModeler::$_transaction_started = FALSE; // reimposta l'autocommit allo stato precedente if (!is_null(AutoModeler::base_autocommit())) { AutoModeler::autocommit(AutoModeler::base_autocommit()); } } } catch (Exception $e) { Database::instance()->rollback(); AutoModeler::base_autocommit(NULL, TRUE); AutoModeler::$_transaction_started = FALSE; throw new Kohana_Database_Exception($e->getMessage()); } return $return; }