rebuildSitesCache.php 1.8 KB

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