/** * @see Maintenance::execute */ public function execute() { $start = microtime(true); $memoryBefore = memory_get_peak_usage(false); if (!defined('SMW_VERSION')) { $this->reportMessage("You need to have SMW enabled in order to run the maintenance script!\n\n"); return false; } $reporter = new ObservableMessageReporter(); $reporter->registerReporterCallback(array($this, 'reportMessage')); $store = StoreFactory::getStore($this->hasOption('b') ? $this->getOption('b') : null); $store->setUpdateJobsEnabledState(false); $dataRebuilder = new DataRebuilder($store); $dataRebuilder->setMessageReporter($reporter); $dataRebuilder->setParameters($this->mOptions); if ($dataRebuilder->rebuild()) { $this->doReportRuntimeEnvironment($memoryBefore, memory_get_peak_usage(false), microtime(true) - $start); return true; } $this->reportMessage($this->mDescription . "\n\n" . 'Use option --help for usage details.' . "\n"); return false; }
public function testRebuildSelectedPagesWithPageOption() { $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $titleCreator = $this->getMockBuilder('\\SMW\\MediaWiki\\TitleCreator')->disableOriginalConstructor()->getMock(); $titleCreator->expects($this->at(0))->method('createFromText')->with($this->equalTo('Main page'))->will($this->returnValue(Title::newFromText('Main page'))); $titleCreator->expects($this->at(1))->method('createFromText')->with($this->equalTo('Some other page'))->will($this->returnValue(Title::newFromText('Some other page'))); $titleCreator->expects($this->at(2))->method('createFromText')->with($this->equalTo('Help:Main page'))->will($this->returnValue(Title::newFromText('Main page', NS_HELP))); $titleCreator->expects($this->at(3))->method('createFromText')->with($this->equalTo('Main page'))->will($this->returnValue(Title::newFromText('Main page'))); $instance = new DataRebuilder($store, $titleCreator); $instance->setParameters(array('page' => 'Main page|Some other page|Help:Main page|Main page')); $this->assertTrue($instance->rebuild()); $this->assertEquals(3, $instance->getRebuildCount()); }
public function testRebuildSelectedPagesWithPropertyNamespaceFilter() { $row = new \stdClass(); $row->page_namespace = SMW_NS_PROPERTY; $row->page_title = 'Bar'; $database = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock(); $database->expects($this->any())->method('select')->with($this->anything(), $this->anything(), $this->equalTo(array('page_namespace' => SMW_NS_PROPERTY)), $this->anything(), $this->anything())->will($this->returnValue(array($row))); $store = $this->getMockBuilder('\\SMWSQLStore3')->disableOriginalConstructor()->getMock(); $store->expects($this->once())->method('getConnection')->will($this->returnValue($database)); $instance = new DataRebuilder($store, null); $instance->setParameters(array('p' => true)); $this->assertTrue($instance->rebuild()); }