'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();
}
}
+ /**
+ * 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(