doMaintenance.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * We want to make this whole thing as seamless as possible to the
  4. * end-user. Unfortunately, we can't do _all_ of the work in the class
  5. * because A) included files are not in global scope, but in the scope
  6. * of their caller, and B) MediaWiki has way too many globals. So instead
  7. * we'll kinda fake it, and do the requires() inline. <3 PHP
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. * http://www.gnu.org/copyleft/gpl.html
  23. *
  24. * @author Chad Horohoe <chad@anyonecanedit.org>
  25. * @file
  26. * @ingroup Maintenance
  27. */
  28. use MediaWiki\MediaWikiServices;
  29. if ( !defined( 'RUN_MAINTENANCE_IF_MAIN' ) ) {
  30. echo "This file must be included after Maintenance.php\n";
  31. exit( 1 );
  32. }
  33. // Wasn't included from the file scope, halt execution (probably wanted the class)
  34. // If a class is using commandLine.inc (old school maintenance), they definitely
  35. // cannot be included and will proceed with execution
  36. if ( !Maintenance::shouldExecute() && $maintClass != 'CommandLineInc' ) {
  37. return;
  38. }
  39. if ( !$maintClass || !class_exists( $maintClass ) ) {
  40. echo "\$maintClass is not set or is set to a non-existent class.\n";
  41. exit( 1 );
  42. }
  43. // Get an object to start us off
  44. /** @var Maintenance $maintenance */
  45. $maintenance = new $maintClass();
  46. // Basic sanity checks and such
  47. $maintenance->setup();
  48. // We used to call this variable $self, but it was moved
  49. // to $maintenance->mSelf. Keep that here for b/c
  50. $self = $maintenance->getName();
  51. # Start the autoloader, so that extensions can derive classes from core files
  52. require_once "$IP/includes/AutoLoader.php";
  53. # Grab profiling functions
  54. require_once "$IP/includes/profiler/ProfilerFunctions.php";
  55. # Start the profiler
  56. $wgProfiler = [];
  57. if ( file_exists( "$IP/StartProfiler.php" ) ) {
  58. require "$IP/StartProfiler.php";
  59. }
  60. // Some other requires
  61. require_once "$IP/includes/Defines.php";
  62. require_once "$IP/includes/DefaultSettings.php";
  63. require_once "$IP/includes/GlobalFunctions.php";
  64. # Load composer's autoloader if present
  65. if ( is_readable( "$IP/vendor/autoload.php" ) ) {
  66. require_once "$IP/vendor/autoload.php";
  67. }
  68. if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
  69. # Use a callback function to configure MediaWiki
  70. call_user_func( MW_CONFIG_CALLBACK );
  71. } else {
  72. // Require the configuration (probably LocalSettings.php)
  73. require $maintenance->loadSettings();
  74. }
  75. if ( $maintenance->getDbType() === Maintenance::DB_NONE ) {
  76. if ( $wgLocalisationCacheConf['storeClass'] === false
  77. && ( $wgLocalisationCacheConf['store'] == 'db'
  78. || ( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) )
  79. ) {
  80. $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull';
  81. }
  82. }
  83. $maintenance->finalSetup();
  84. // Some last includes
  85. require_once "$IP/includes/Setup.php";
  86. // Initialize main config instance
  87. $maintenance->setConfig( ConfigFactory::getDefaultInstance()->makeConfig( 'main' ) );
  88. // Sanity-check required extensions are installed
  89. $maintenance->checkRequiredExtensions();
  90. // A good time when no DBs have writes pending is around lag checks.
  91. // This avoids having long running scripts just OOM and lose all the updates.
  92. $maintenance->setAgentAndTriggers();
  93. // Do the work
  94. $maintenance->execute();
  95. // Potentially debug globals
  96. $maintenance->globals();
  97. // Perform deferred updates.
  98. $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
  99. $lbFactory->commitMasterChanges( $maintClass );
  100. DeferredUpdates::doUpdates();
  101. // log profiling info
  102. wfLogProfilingData();
  103. // Commit and close up!
  104. $lbFactory->commitMasterChanges( 'doMaintenance' );
  105. $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT );