]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
some changes based on code review with zach
authorEvan Prodromou <evan@controlyourself.ca>
Wed, 10 Jun 2009 20:52:15 +0000 (13:52 -0700)
committerEvan Prodromou <evan@controlyourself.ca>
Wed, 10 Jun 2009 20:52:15 +0000 (13:52 -0700)
classes/Notice.php
classes/Notice_inbox.php
scripts/twitterstatusfetcher.php

index 895b5d2c71c8a3720587ec57a16abb62f0adf7cc..45ea7282343142b7b764b181923d2842de805bd5 100644 (file)
@@ -120,7 +120,8 @@ class Notice extends Memcached_DataObject
         }
     }
 
-    static function saveNew($profile_id, $content, $source=null, $is_local=1, $reply_to=null, $uri=null) {
+    static function saveNew($profile_id, $content, $source=null,
+                            $is_local=1, $reply_to=null, $uri=null, $created=null) {
 
         $profile = Profile::staticGet($profile_id);
 
@@ -166,7 +167,11 @@ class Notice extends Memcached_DataObject
                $notice->query('BEGIN');
 
                $notice->reply_to = $reply_to;
-               $notice->created = common_sql_now();
+        if (!empty($created)) {
+            $notice->created = $created;
+        } else {
+            $notice->created = common_sql_now();
+        }
                $notice->content = $final;
                $notice->rendered = common_render_content($final, $notice);
                $notice->source = $source;
index 8a27e174785101b9b52b6e3bf9211b3867e00ab2..673e187c7296694bbd228ef02f0e9ae3d6671298 100644 (file)
@@ -85,4 +85,9 @@ class Notice_inbox extends Memcached_DataObject
 
         return $ids;
     }
+
+    function &pkeyGet($kv)
+    {
+        return Memcached_DataObject::pkeyGet('Notice_inbox', $kv);
+    }
 }
index a61ce1b0d1622f2d63065d0ce118ca77d97ce3a6..9287b6d73332ee1cca765df095883703cf17575d 100755 (executable)
@@ -255,42 +255,11 @@ class TwitterStatusFetcher extends Daemon
         // check to see if we've already imported the status
         if (!$notice) {
 
-            $notice = new Notice();
-            $notice->profile_id = $id;
+            $created = strftime('%Y-%m-%d %H:%M:%S',
+                                strtotime($status->created_at));;
 
-            $notice->query('BEGIN');
-
-            // XXX: figure out reply_to
-            $notice->reply_to = null;
-
-            // XXX: Should this be common_sql_now() instead of status create date?
-
-            $notice->created = strftime('%Y-%m-%d %H:%M:%S',
-                strtotime($status->created_at));
-            $notice->content = $status->text;
-            $notice->rendered = common_render_content($status->text, $notice);
-            $notice->source = 'twitter';
-            $notice->is_local = 0;
-            $notice->uri = $uri;
-
-            $notice_id = $notice->insert();
-
-            if (!$notice_id) {
-                common_log_db_error($notice, 'INSERT', __FILE__);
-                if (defined('SCRIPT_DEBUG')) {
-                    common_debug('Could not save notice!');
-                }
-            }
-
-            // XXX: Figure out a better way to link Twitter replies?
-            $notice->saveReplies();
-
-            // XXX: Do we want to pollute our tag cloud with
-            // hashtags from Twitter?
-            $notice->saveTags();
-            $notice->saveGroups();
-
-            $notice->query('COMMIT');
+            $notice = Notice::saveNew($id, $status->text, 'twitter',
+                                      -2, null, $uri, $created);
 
             if (defined('SCRIPT_DEBUG')) {
                 common_debug("Saved status $status->id" .
@@ -298,13 +267,13 @@ class TwitterStatusFetcher extends Daemon
             }
         }
 
-        if (!Notice_inbox::staticGet('notice_id', $notice->id)) {
-
+        if (!Notice_inbox::pkeyGet(array('notice_id' => $notice->id,
+                                         'user_id' => $flink->user_id))) {
             // Add to inbox
             $inbox = new Notice_inbox();
             $inbox->user_id = $flink->user_id;
             $inbox->notice_id = $notice->id;
-            $inbox->created = common_sql_now();
+            $inbox->created = $notice->created;
 
             $inbox->insert();
         }