5da912e2aa9750faceaa004c20841cb5847feceb
[phorkie.git] / scripts / index.php
1 <?php
2 //index repositories in elasticsearch
3
4 namespace phorkie;
5 set_include_path(
6     __DIR__ . '/../src/'
7     . PATH_SEPARATOR . get_include_path()
8 );
9 spl_autoload_register(
10     function ($class) {
11         $file = str_replace(array('\\', '_'), '/', $class) . '.php';
12         $hdl = @fopen($file, 'r', true);
13         if ($hdl !== false) {
14             fclose($hdl);
15             require $file;
16         }
17     }
18 );
19 require_once __DIR__ . '/../data/config.default.php';
20 if (file_exists(__DIR__ . '/../data/config.php')) {
21     require_once __DIR__ . '/../data/config.php';
22 }
23 if ($GLOBALS['phorkie']['cfg']['setupcheck']) {
24     SetupCheck::run();
25 }
26
27
28 $db = new Database();
29 $idx = $db->getIndexer();
30
31 //create mapping
32 echo "Index reset\n";
33 $db->getSetup()->reset();
34
35
36 $rs = new Repositories();
37 list($repos, $count) = $rs->getList(0, 10000);
38 foreach ($repos as $repo) {
39     echo 'Indexing ' . $repo->id . "\n";
40     $commits = $repo->getHistory();
41     $first = count($commits)-1;
42     $idx->addRepo($repo, $commits[$first]->committerTime, $commits[0]->committerTime);
43 }
44 ?>