Skip to content

Commit 36855f4

Browse files
authored
Merge pull request dokuwiki#4543 from dokuwiki/indexer
Make bin/indexer.php more robust
2 parents 26e9686 + 141d9fe commit 36855f4

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

bin/indexer.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env php
22
<?php
33

4+
use dokuwiki\Logger;
45
use splitbrain\phpcli\CLI;
56
use splitbrain\phpcli\Options;
67

@@ -36,7 +37,7 @@ protected function setup(Options $options)
3637
);
3738
$options->registerOption(
3839
'quiet',
39-
'don\'t produce any output',
40+
'DEPRECATED',
4041
'q'
4142
);
4243
}
@@ -54,6 +55,11 @@ protected function main(Options $options)
5455
$this->clear = $options->getOpt('clear');
5556
$this->quiet = $options->getOpt('quiet');
5657

58+
if ($this->quiet) {
59+
Logger::deprecated('Calling bin/indexer.php with -q/--quiet is deprecated. Use --loglevel instead.');
60+
$this->setLogLevel('emergency');
61+
}
62+
5763
if ($this->clear) $this->clearindex();
5864

5965
$this->update();
@@ -66,9 +72,9 @@ protected function update()
6672
{
6773
global $conf;
6874
$data = [];
69-
$this->quietecho("Searching pages... ");
75+
$this->notice('Searching pages...');
7076
search($data, $conf['datadir'], 'search_allpages', ['skipacl' => true]);
71-
$this->quietecho(count($data) . " pages found.\n");
77+
$this->info(count($data) . ' pages found.');
7278

7379
foreach ($data as $val) {
7480
$this->index($val['id']);
@@ -82,29 +88,28 @@ protected function update()
8288
*/
8389
protected function index($id)
8490
{
85-
$this->quietecho("$id... ");
86-
idx_addPage($id, !$this->quiet, $this->clear);
87-
$this->quietecho("done.\n");
91+
$this->notice("$id indexing...");
92+
try {
93+
if (idx_addPage($id, isset($this->loglevel['info']), $this->clear)) {
94+
$this->success("$id indexed.");
95+
} else {
96+
$this->info("$id index not updated.");
97+
}
98+
} catch (Throwable $e) {
99+
$this->error("$id indexing error: " . $e->getMessage());
100+
$this->debug($e->getTraceAsString());
101+
return;
102+
}
88103
}
89104

90105
/**
91106
* Clear all index files
92107
*/
93108
protected function clearindex()
94109
{
95-
$this->quietecho("Clearing index... ");
110+
$this->notice('Clearing index...');
96111
idx_get_indexer()->clear();
97-
$this->quietecho("done.\n");
98-
}
99-
100-
/**
101-
* Print message if not supressed
102-
*
103-
* @param string $msg
104-
*/
105-
protected function quietecho($msg)
106-
{
107-
if (!$this->quiet) echo $msg;
112+
$this->success('Index cleared.');
108113
}
109114
}
110115

0 commit comments

Comments
 (0)