]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/YammerImport/lib/yammerrunner.php
Made YammerImport more robust against errors; can now pause/resume/reset the import...
[quix0rs-gnu-social.git] / plugins / YammerImport / lib / yammerrunner.php
index e0aec0d1666080e07a4285305d2ffc264aa90137..3e53f3361beb547b5c645ad427ffffb4073fb21a 100644 (file)
@@ -298,7 +298,10 @@ class YammerRunner
             $this->state->state = 'save-messages';
         } else {
             foreach ($messages as $item) {
-                Yammer_notice_stub::record($item['id'], $item);
+                $stub = Yammer_notice_stub::staticGet($item['id']);
+                if (!$stub) {
+                    Yammer_notice_stub::record($item['id'], $item);
+                }
                 $oldest = $item['id'];
             }
             $this->state->messages_oldest = $oldest;
@@ -395,4 +398,41 @@ class YammerRunner
         $qm->enqueue('YammerImport', 'yammer');
     }
 
+    /**
+     * Record an error condition from a background run, which we should
+     * display in progress state for the admin.
+     * 
+     * @param string $msg 
+     */
+    public function recordError($msg)
+    {
+        // HACK HACK HACK
+        try {
+            $temp = new Yammer_state();
+            $temp->query('ROLLBACK');
+        } catch (Exception $e) {
+            common_log(LOG_ERR, 'Exception while confirming rollback while recording error: ' . $e->getMessage());
+        }
+        $old = clone($this->state);
+        $this->state->last_error = $msg;
+        $this->state->update($old);
+    }
+
+    /**
+     * Clear the error state.
+     */
+    public function clearError()
+    {
+        $this->recordError('');
+    }
+
+    /**
+     * Get the last recorded background error message, if any.
+     * 
+     * @return string
+     */
+    public function lastError()
+    {
+        return $this->state->last_error;
+    }
 }