|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SG\Maintenance; |
|
4
|
|
|
|
|
5
|
|
|
use SG\Maintenance\GlossaryCacheRebuilder; |
|
6
|
|
|
use SG\Cache\GlossaryCache; |
|
7
|
|
|
|
|
8
|
|
|
use SMW\StoreFactory; |
|
9
|
|
|
|
|
10
|
|
|
$basePath = getenv( 'MW_INSTALL_PATH' ) !== false ? getenv( 'MW_INSTALL_PATH' ) : __DIR__ . '/../../..'; |
|
11
|
|
|
|
|
12
|
|
|
require_once $basePath . '/maintenance/Maintenance.php'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Rebuild glossary cache and update pages that contain a glossary term annotation |
|
16
|
|
|
* |
|
17
|
|
|
* Usage: |
|
18
|
|
|
* php rebuildGlossaryCache.php [options...] |
|
19
|
|
|
* |
|
20
|
|
|
* @ingroup SG |
|
21
|
|
|
* @ingroup SemanticGlossary |
|
22
|
|
|
* @ingroup Maintenance |
|
23
|
|
|
* |
|
24
|
|
|
* @license GNU GPL v2+ |
|
25
|
|
|
* @since 1.1 |
|
26
|
|
|
* |
|
27
|
|
|
* @author mwjames |
|
28
|
|
|
*/ |
|
29
|
|
|
class RebuildGlossaryCache extends \Maintenance { |
|
30
|
|
|
|
|
31
|
|
|
public function __construct() { |
|
32
|
|
|
parent::__construct(); |
|
33
|
|
|
|
|
34
|
|
|
$this->addDescription( "Rebuild glossary cache and update pages with glossary annotations." ); |
|
35
|
|
|
$this->addDefaultParams(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @see Maintenance::addDefaultParams |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function addDefaultParams() { |
|
42
|
|
|
parent::addDefaultParams(); |
|
43
|
|
|
$this->addOption( 'verbose', 'Be verbose about the progress', false, false, 'v' ); |
|
44
|
|
|
$this->addOption( 'quiet', 'Do not give any output', false ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @see Maintenance::execute |
|
49
|
|
|
*/ |
|
50
|
|
|
public function execute() { |
|
51
|
|
|
|
|
52
|
|
|
if ( !defined( 'SMW_VERSION' ) ) { |
|
53
|
|
|
$this->reportMessage( "You need to have SMW enabled in order to run the maintenance script!\n\n" ); |
|
54
|
|
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$glossaryCacheRebuilder = new GlossaryCacheRebuilder( |
|
58
|
|
|
StoreFactory::getStore(), |
|
59
|
|
|
new GlossaryCache(), |
|
60
|
|
|
array( $this, 'reportMessage' ) |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$glossaryCacheRebuilder->setParameters( $this->mOptions ); |
|
64
|
|
|
|
|
65
|
|
|
if ( $glossaryCacheRebuilder->rebuild() ) { |
|
66
|
|
|
return true; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$this->reportMessage( $this->mDescription . "\n\n" . 'Use option --help for details.' . "\n" ); |
|
70
|
|
|
return false; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @since 1.1 |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $message |
|
77
|
|
|
*/ |
|
78
|
|
|
public function reportMessage( $message ) { |
|
79
|
|
|
$this->output( $message ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$maintClass = 'SG\Maintenance\RebuildGlossaryCache'; |
|
85
|
|
|
require_once( RUN_MAINTENANCE_IF_MAIN ); |
|
86
|
|
|
|