use stream_resolve_include_path
[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         if (stream_resolve_include_path($file)) {
13             require $file;
14         }
15     }
16 );
17 require_once __DIR__ . '/../data/config.default.php';
18 if (file_exists(__DIR__ . '/../data/config.php')) {
19     require_once __DIR__ . '/../data/config.php';
20 }
21 if ($GLOBALS['phorkie']['cfg']['setupcheck']) {
22     SetupCheck::run();
23 }
24
25
26 $db = new Database();
27 $idx = $db->getIndexer();
28
29 //create mapping
30 echo "Index reset\n";
31 $db->getSetup()->reset();
32
33
34 $rs = new Repositories();
35 list($repos, $count) = $rs->getList(0, 10000);
36 foreach ($repos as $repo) {
37     echo 'Indexing ' . $repo->id . "\n";
38     $commits = $repo->getHistory();
39     $first = count($commits)-1;
40     $idx->addRepo($repo, $commits[$first]->committerTime, $commits[0]->committerTime);
41 }
42 ?>