From 821b758429dac79121a3e7acc29bb9c48df33dd4 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Mon, 31 May 2010 15:40:13 -0400 Subject: [PATCH] Add shorthand for adding created_at/updated_at to a table. Credit to http://github.com/maintainable/framework/commit/2875fa7ccd8d6cb8176097bf2c2c00a756326649 Also change Rdo to use created_at/updated_at instead of created/updated --- .../Db/lib/Horde/Db/Adapter/Base/TableDefinition.php | 9 +++++++++ framework/Rdo/lib/Horde/Rdo/Mapper.php | 20 +++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php b/framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php index 005422dc5..4f26e453d 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php +++ b/framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php @@ -140,6 +140,15 @@ class Horde_Db_Adapter_Base_TableDefinition implements ArrayAccess, IteratorAggr } /** + * Adds created_at and updated_at columns to the table. + */ + public function timestamps() + { + return $this->column('created_at', 'datetime') + ->column('updated_at', 'datetime'); + } + + /** * Use __call to provide shorthand column creation ($this->integer(), etc.) */ public function __call($method, $arguments) diff --git a/framework/Rdo/lib/Horde/Rdo/Mapper.php b/framework/Rdo/lib/Horde/Rdo/Mapper.php index 649930691..e3da2aaba 100644 --- a/framework/Rdo/lib/Horde/Rdo/Mapper.php +++ b/framework/Rdo/lib/Horde/Rdo/Mapper.php @@ -25,19 +25,18 @@ abstract class Horde_Rdo_Mapper implements Countable { /** - * If this is true and fields named created and updated are - * present, Rdo will automatically set creation and last updated - * timestamps. Timestamps are always GMT for portability. + * If this is true and fields named created_at and updated_at are present, + * Rdo will automatically set creation and last updated timestamps. + * Timestamps are always GMT for portability. * * @var boolean */ protected $_setTimestamps = true; /** - * What class should this Mapper create for objects? Defaults to - * the Mapper subclass' name minus "Mapper". So if the Rdo_Mapper - * subclass is UserMapper, it will default to trying to create - * User objects. + * What class should this Mapper create for objects? Defaults to the Mapper + * subclass' name minus "Mapper". So if the Rdo_Mapper subclass is + * UserMapper, it will default to trying to create User objects. * * @var string */ @@ -319,8 +318,8 @@ abstract class Horde_Rdo_Mapper implements Countable // always set. if ($this->_setTimestamps) { $time = gmmktime(); - $fields['created'] = $time; - $fields['updated'] = $time; + $fields['created_at'] = $time; + $fields['updated_at'] = $time; } // Filter out any extra fields. @@ -377,7 +376,7 @@ abstract class Horde_Rdo_Mapper implements Countable // If configured to record update time, set it here. if ($this->_setTimestamps) { - $fields['updated'] = gmmktime(); + $fields['updated_at'] = gmmktime(); } // Filter out any extra fields. @@ -528,5 +527,4 @@ abstract class Horde_Rdo_Mapper implements Countable $this->_defaultSort = $sort; return $this; } - } -- 2.11.0