*/ class rebuildPropertyStatistics extends Maintenance { public function __construct() { parent::__construct(); $this->mDescription = 'Rebuild the property usage statistics (only works with SQLStore3 for now)'; $this->addOption( 'with-maintenance-log', 'Add log entry to `Special:Log` about the maintenance run.', false ); } /** * @see Maintenance::execute */ public function execute() { if ( $this->canExecute() !== true ) { exit; } $applicationFactory = ApplicationFactory::getInstance(); $maintenanceFactory = $applicationFactory->newMaintenanceFactory(); $maintenanceHelper = $maintenanceFactory->newMaintenanceHelper(); $maintenanceHelper->initRuntimeValues(); $statisticsRebuilder = $maintenanceFactory->newPropertyStatisticsRebuilder( $applicationFactory->getStore( 'SMW\SQLStore\SQLStore' ), [ $this, 'reportMessage' ] ); $statisticsRebuilder->rebuild(); if ( $this->hasOption( 'with-maintenance-log' ) ) { $maintenanceLogger = $maintenanceFactory->newMaintenanceLogger( 'RebuildPropertyStatisticsLogger' ); $runtimeValues = $maintenanceHelper->getRuntimeValues(); $log = [ 'Memory used' => $runtimeValues['memory-used'], 'Time used' => $runtimeValues['humanreadable-time'] ]; $maintenanceLogger->logFromArray( $log ); } } /** * @see Maintenance::reportMessage * * @since 1.9 * * @param string $message */ public function reportMessage( $message ) { $this->output( $message ); } private function canExecute() { if ( !Setup::isEnabled() ) { return $this->reportMessage( "\nYou need to have SMW enabled in order to run the maintenance script!\n" ); } if ( !Setup::isValid( true ) ) { return $this->reportMessage( "\nYou need to run `update.php` or `setupStore.php` first before continuing\n" . "with this maintenance task!\n" ); } return true; } } // @codeCoverageIgnoreStart $maintClass = rebuildPropertyStatistics::class; require_once RUN_MAINTENANCE_IF_MAIN; // @codeCoverageIgnoreEnd