]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/Twitter_synch_status.php
Merge branch '1.0.x'
[quix0rs-gnu-social.git] / plugins / TwitterBridge / Twitter_synch_status.php
index 69b8a780ad165c4ee6abb5cc72f5ed4902d782b8..9c61e7e7e0fd0f82052ddcc28ee0e5ed483a393c 100644 (file)
@@ -48,28 +48,39 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
  *
  * @see      DB_DataObject
  */
-
 class Twitter_synch_status extends Memcached_DataObject
 {
     public $__table = 'twitter_synch_status'; // table name
-    public $user_id;                         // int(4)  primary_key not_null
+    public $foreign_id;                         // int(4)  primary_key not_null
     public $timeline;                        // varchar(255)  primary_key not_null
     public $last_id;                         // bigint not_null
     public $created;                         // datetime not_null
+    public $modified;                        // datetime not_null
 
     /**
      * Get an instance by key
      *
-     * @param string $k Key to use to lookup (usually 'user_id' for this class)
+     * @param string $k Key to use to lookup (usually 'foreign_id' for this class)
      * @param mixed  $v Value to lookup
      *
-     * @return User_greeting_count object found, or null for no hits
-     *
+     * @return Twitter_synch_status object found, or null for no hits
      */
-
     function staticGet($k, $v=null)
     {
-        return Memcached_DataObject::staticGet('Twitter_synch_status', $k, $v);
+        throw new Exception("Use pkeyGet() for this class.");
+    }
+
+    /**
+     * Get an instance by compound primary key
+     *
+     * @param array $kv key-value pair array
+     *
+     * @return Twitter_synch_status object found, or null for no hits
+     *
+     */
+    function pkeyGet($kv)
+    {
+        return Memcached_DataObject::pkeyGet('Twitter_synch_status', $kv);
     }
 
     /**
@@ -80,13 +91,13 @@ class Twitter_synch_status extends Memcached_DataObject
      *
      * @return array array of column definitions
      */
-
     function table()
     {
-        return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'timeline' => DB_DATAOBJECT_STRING + DB_DATAOBJECT_NOTNULL,
+        return array('foreign_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
+                     'timeline' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
                      'last_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
-                     'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL
+                     'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
+                     'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL
                      );
     }
 
@@ -99,7 +110,6 @@ class Twitter_synch_status extends Memcached_DataObject
      *
      * @return array list of key field names
      */
-
     function keys()
     {
         return array_keys($this->keyTypes());
@@ -117,10 +127,9 @@ class Twitter_synch_status extends Memcached_DataObject
      *         'K' for primary key: for compound keys, add an entry for each component;
      *         'U' for unique keys: compound keys are not well supported here.
      */
-
     function keyTypes()
     {
-        return array('user_id' => 'K',
+        return array('foreign_id' => 'K',
                      'timeline' => 'K');
     }
 
@@ -134,16 +143,15 @@ class Twitter_synch_status extends Memcached_DataObject
      *
      * @return array magic three-false array that stops auto-incrementing.
      */
-
     function sequenceKey()
     {
         return array(false, false, false);
     }
 
-    static function getLastId($user_id, $timeline)
+    static function getLastId($foreign_id, $timeline)
     {
-        $tss = self::staticGet(array('user_id' => $user_id,
-                                     'timeline' => $timeline));
+        $tss = self::pkeyGet(array('foreign_id' => $foreign_id,
+                                   'timeline' => $timeline));
 
         if (empty($tss)) {
             return null;
@@ -152,28 +160,28 @@ class Twitter_synch_status extends Memcached_DataObject
         }
     }
 
-    static function setLastId($user_id, $timeline, $last_id)
+    static function setLastId($foreign_id, $timeline, $last_id)
     {
-        $tss = self::staticGet(array('user_id' => $user_id,
-                                     'timeline' => $timeline));
+        $tss = self::pkeyGet(array('foreign_id' => $foreign_id,
+                                   'timeline' => $timeline));
 
         if (empty($tss)) {
-
             $tss = new Twitter_synch_status();
 
-            $tss->user_id  = $user_id;
-            $tss->timeline = $timeline;
-            $tss->last_id  = $last_id;
+            $tss->foreign_id = $foreign_id;
+            $tss->timeline   = $timeline;
+            $tss->last_id    = $last_id;
+            $tss->created    = common_sql_now();
+            $tss->modified   = $tss->created;
 
             $tss->insert();
 
             return true;
-
         } else {
-
             $orig = clone($tss);
 
-            $tss->last_id = $last_id;
+            $tss->last_id  = $last_id;
+            $tss->modified = common_sql_now();
 
             $tss->update();