From aeb9aeb648cdaf28e2872c88687933bb3add821c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 27 Sep 2012 23:18:21 +0200 Subject: Fix bug #22: Edited pastes not in "recently created" --- .../Database/Adapter/Elasticsearch/Indexer.php | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src') diff --git a/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php b/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php index 41aa7d7..dbe769e 100644 --- a/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php +++ b/src/phorkie/Database/Adapter/Elasticsearch/Indexer.php @@ -29,9 +29,13 @@ class Database_Adapter_Elasticsearch_Indexer implements Database_IIndexer 'description' => $repo->getDescription(), 'tstamp' => gmdate('c', time()), ); + if ($crdate == null) { + $crdate = $this->getCrDate($repo); + } if ($crdate !== null) { $repoData['crdate'] = gmdate('c', $crdate); } + $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( -- cgit v1.2.3