Yet another attempt to fix the populateIpChanges script
[lhc/web/wiklou.git] / maintenance / rebuildSitesCache.php
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 * @ingroup Maintenance
21 */
22
23 require_once __DIR__ . '/Maintenance.php';
24
25 /**
26 * Maintenance script to dump a SiteStore as a static json file.
27 *
28 * @ingroup Maintenance
29 */
30 class RebuildSitesCache extends Maintenance {
31
32 public function __construct() {
33 parent::__construct();
34
35 $this->addDescription( 'Cache sites as json for file-based lookup.' );
36 $this->addOption( 'file', 'File to output the json to', false, true );
37 }
38
39 public function execute() {
40 $sitesCacheFileBuilder = new SitesCacheFileBuilder(
41 \MediaWiki\MediaWikiServices::getInstance()->getSiteLookup(),
42 $this->getCacheFile()
43 );
44
45 $sitesCacheFileBuilder->build();
46 }
47
48 /**
49 * @return string
50 */
51 private function getCacheFile() {
52 if ( $this->hasOption( 'file' ) ) {
53 $jsonFile = $this->getOption( 'file' );
54 } else {
55 $jsonFile = $this->getConfig()->get( 'SitesCacheFile' );
56
57 if ( $jsonFile === false ) {
58 $this->error( 'Error: No file set in configuration for SitesCacheFile.', 1 );
59 }
60 }
61
62 return $jsonFile;
63 }
64
65 }
66
67 $maintClass = "RebuildSitesCache";
68 require_once RUN_MAINTENANCE_IF_MAIN;