translation update
[dokuwiki.git] / bin / indexer.php
blob4d19a9515c57651c8f6a7e005364880ad8720ce7
1 #!/usr/bin/php
2 <?php
4 use splitbrain\phpcli\CLI;
5 use splitbrain\phpcli\Options;
7 if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
8 define('NOSESSION', 1);
9 require_once(DOKU_INC . 'inc/init.php');
11 /**
12 * Update the Search Index from command line
14 class IndexerCLI extends CLI {
16 private $quiet = false;
17 private $clear = false;
19 /**
20 * Register options and arguments on the given $options object
22 * @param Options $options
23 * @return void
25 protected function setup(Options $options) {
26 $options->setHelp(
27 'Updates the searchindex by indexing all new or changed pages. When the -c option is ' .
28 'given the index is cleared first.'
31 $options->registerOption(
32 'clear',
33 'clear the index before updating',
34 'c'
36 $options->registerOption(
37 'quiet',
38 'don\'t produce any output',
39 'q'
43 /**
44 * Your main program
46 * Arguments and options have been parsed when this is run
48 * @param Options $options
49 * @return void
51 protected function main(Options $options) {
52 $this->clear = $options->getOpt('clear');
53 $this->quiet = $options->getOpt('quiet');
55 if($this->clear) $this->clearindex();
57 $this->update();
60 /**
61 * Update the index
63 function update() {
64 global $conf;
65 $data = array();
66 $this->quietecho("Searching pages... ");
67 search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
68 $this->quietecho(count($data) . " pages found.\n");
70 foreach($data as $val) {
71 $this->index($val['id']);
75 /**
76 * Index the given page
78 * @param string $id
80 function index($id) {
81 $this->quietecho("$id... ");
82 idx_addPage($id, !$this->quiet, $this->clear);
83 $this->quietecho("done.\n");
86 /**
87 * Clear all index files
89 function clearindex() {
90 $this->quietecho("Clearing index... ");
91 idx_get_indexer()->clear();
92 $this->quietecho("done.\n");
95 /**
96 * Print message if not supressed
98 * @param string $msg
100 function quietecho($msg) {
101 if(!$this->quiet) echo $msg;
105 // Main
106 $cli = new IndexerCLI();
107 $cli->run();