Fix bug #22: Edited pastes not in "recently created"
authorChristian Weiske <cweiske@cweiske.de>
Thu, 27 Sep 2012 21:18:21 +0000 (23:18 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 27 Sep 2012 21:18:21 +0000 (23:18 +0200)
ChangeLog
NEWS.rst
src/phorkie/Database/Adapter/Elasticsearch/Indexer.php

index 022968537b3b7ee8227ccab5f130fd474c29a2b3..84cf40df850aa6a733eb0e5841cbc62779de43e4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2012-09-27  Christian Weiske  <cweiske@bogo>
+
+       * Fix bug #22: Edited pastes not in "recently created"
+
 2012-09-27  Christian Weiske  <cweiske@cweiske.de>
 
        * Release of version 0.3.0
 2012-09-27  Christian Weiske  <cweiske@cweiske.de>
 
        * Release of version 0.3.0
index 02acbfb0eea9c37485c028548f4714ce79c1fb99..be2672ebfd105ab600ce9eca8837027b76533327 100644 (file)
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -3,6 +3,7 @@ Version 0.3.0 - 2012-09-27
 
 * Fix bug #10: error when nothing submitted [cweiske]
 * Fix bug #11: do not index edit, delete and tool pages [cweiske]
 
 * Fix bug #10: error when nothing submitted [cweiske]
 * Fix bug #11: do not index edit, delete and tool pages [cweiske]
+* Fix bug #22: Edited pastes not in "recently created" [cweiske]
 * Implement request #5: Add OpenID authentication [jnovack]
 * Implement request #9: autodetect file type [cweiske]
 * Implement request #12: DOAP and rel="vcs-git" support [cweiske]
 * Implement request #5: Add OpenID authentication [jnovack]
 * Implement request #9: autodetect file type [cweiske]
 * Implement request #12: DOAP and rel="vcs-git" support [cweiske]
index 41aa7d71bda77abad0fba12c6de61ab3f5ed487a..dbe769e56a647e21fef33ebd0ce3d707649bc536 100644 (file)
@@ -29,9 +29,13 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer
             'description' => $repo->getDescription(),
             'tstamp'      => gmdate('c', time()),
         );
             'description' => $repo->getDescription(),
             'tstamp'      => gmdate('c', time()),
         );
+        if ($crdate == null) {
+            $crdate = $this->getCrDate($repo);
+        }
         if ($crdate !== null) {
             $repoData['crdate'] = gmdate('c', $crdate);
         }
         if ($crdate !== null) {
             $repoData['crdate'] = gmdate('c', $crdate);
         }
+
         $r->setBody(json_encode((object)$repoData));
         $r->send();
 
         $r->setBody(json_encode((object)$repoData));
         $r->send();
 
@@ -57,6 +61,28 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer
         }
     }
 
         }
     }
 
+    /**
+     * When updating the repository, we don't have a creation date.
+     * We need to keep it, but elasticsearch does not have a simple way
+     * to update some fields only (without using a custom script).
+     *
+     * @return integer Unix timestamp
+     */
+    protected function getCrDate(Repository $repo)
+    {
+        $r = new Database_Adapter_Elasticsearch_HTTPRequest(
+            $this->searchInstance . 'repo/' . $repo->id,
+            \HTTP_Request2::METHOD_GET
+        );
+        $json = json_decode($r->send()->getBody());
+
+        if (!isset($json->_source->crdate)) {
+            return null;
+        }
+
+        return strtotime($json->_source->crdate);
+    }
+
     public function deleteAllRepos()
     {
         $r = new Database_Adapter_Elasticsearch_HTTPRequest(
     public function deleteAllRepos()
     {
         $r = new Database_Adapter_Elasticsearch_HTTPRequest(