implement request #3: show recent pastes in "New paste" screen sidebar
[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 //cleanup
32 echo "Deleting all index data\n";
33 $idx->deleteAllRepos();
34
35 //create mapping
36 echo "Index setup\n";
37 $db->getSetup()->setup();
38
39
40 $rs = new Repositories();
41 list($repos, $count) = $rs->getList(0, 10000);
42 foreach ($repos as $repo) {
43     echo 'Indexing ' . $repo->id . "\n";
44     $idx->addRepo($repo, filectime($repo->gitDir));
45 }
46 ?>