11#!/usr/bin/env php
22<?php
33
4+ use dokuwiki \Logger ;
45use splitbrain \phpcli \CLI ;
56use 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