diff --git a/classes/model/soft.php b/classes/model/soft.php index 5579dc63f..3f947368b 100644 --- a/classes/model/soft.php +++ b/classes/model/soft.php @@ -1,4 +1,16 @@ + * @package Orm + * @author Fuel Development Team */ class Model_Soft extends Model { diff --git a/classes/model/temporal.php b/classes/model/temporal.php index 7612799dc..602c19488 100644 --- a/classes/model/temporal.php +++ b/classes/model/temporal.php @@ -1,11 +1,24 @@ + * @package Orm + * @author Fuel Development Team */ class Model_Temporal extends Model { @@ -330,9 +343,10 @@ private static function getNonTimestampPks() /** * Overrides the save method to allow temporal models to be - * @param type $cascade - * @param type $use_transaction - * @return type + * @param boolean $cascade + * @param boolean $use_transaction + * @param boolean $skip_temporal Skips temporal filtering on initial inserts. Should not be used! + * @return boolean */ public function save($cascade = null, $use_transaction = false) { @@ -368,45 +382,33 @@ public function save($cascade = null, $use_transaction = false) if (count($diff[0]) > 0) { - self::disable_primary_key_check(); - $this->{$timestamp_end_name} = $current_timestamp; - self::enable_primary_key_check(); + //Take a copy of this model + $revision = clone $this; - //If we cannot save then don't bother updating anything else to prevent bad data in the database. - if ( ! parent::save($cascade, $use_transaction) ) - { - return false; - } + //Give that new model an end time of the current time after resetting back to the old data + $revision->set($this->_original); - //Take a copy before resetting - $newModel = clone $this; + self::disable_primary_key_check(); + $revision->{$timestamp_end_name} = $current_timestamp; + self::enable_primary_key_check(); - //Reset the current model and update the timestamp - $this->reset(); + //save that, now we have our archive + self::enable_id_only_primary_key(); + $revision_result = $revision->overwrite(false, $use_transaction); + self::disable_id_only_primary_key(); - //Construct a copy of this model and save that with a 0 timestamp - //Copy the PKs - foreach ($this->primary_key() as $pk) + if ( ! $revision_result) { - if ($pk != $timestamp_start_name && $pk != $timestamp_end_name) - { - $newModel->{$pk} = $this->{$pk}; - } + //If the revision did not save then stop the process so the user can do something. + return false; } - //Then update the timestamps - static::disable_primary_key_check(); - $newModel->{$timestamp_start_name} = $current_timestamp; - $newModel->{$timestamp_end_name} = $max_timestamp; - static::enable_primary_key_check(); - - $result = $newModel->save(); + //Now that the old data is saved update the current object so its end timestamp is now + self::disable_primary_key_check(); + $this->{$timestamp_start_name} = $current_timestamp; + self::enable_primary_key_check(); - //Make sure $this is repopulated correctly (So Id's are present) - foreach($this->properties() as $proptery => $settings) - { - $this->_data[$proptery] = $newModel->{$proptery}; - } + $result = parent::save($cascade, $use_transaction); return $result; } diff --git a/classes/query/soft.php b/classes/query/soft.php index 87c629c94..83c71566d 100644 --- a/classes/query/soft.php +++ b/classes/query/soft.php @@ -18,6 +18,7 @@ * Overrides the default Query object to allow for custom soft delete filtering on queries. * * @package Orm + * @author Fuel Development Team */ class Query_Soft extends Query { diff --git a/classes/query/temporal.php b/classes/query/temporal.php index 841da1864..96bdd0c34 100644 --- a/classes/query/temporal.php +++ b/classes/query/temporal.php @@ -1,4 +1,16 @@ + * @package Orm + * @author Fuel Development Team */ class Query_Temporal extends Query { diff --git a/config/orm.php b/config/orm.php index c7ba547ee..2837a2adf 100644 --- a/config/orm.php +++ b/config/orm.php @@ -1,5 +1,5 @@ '2038-01-18 22:14:08', - 'sql_max_timestamp_unix' => '2147483647', + 'sql_max_timestamp_unix' => 2147483647, );