Add shorthand for adding created_at/updated_at to a table.
authorChuck Hagenbuch <chuck@horde.org>
Mon, 31 May 2010 19:40:13 +0000 (15:40 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Mon, 31 May 2010 19:40:13 +0000 (15:40 -0400)
Credit to http://github.com/maintainable/framework/commit/2875fa7ccd8d6cb8176097bf2c2c00a756326649
Also change Rdo to use created_at/updated_at instead of created/updated

framework/Db/lib/Horde/Db/Adapter/Base/TableDefinition.php
framework/Rdo/lib/Horde/Rdo/Mapper.php

index 005422d..4f26e45 100644 (file)
@@ -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)
index 6499306..e3da2aa 100644 (file)
 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;
     }
-
 }