/** * @see Maintenance::execute */ public function execute() { if (!defined('SMW_VERSION')) { $this->output("You need to have SMW enabled in order to use this maintenance script!\n\n"); exit; } $store = StoreFactory::getStore(); $statsTable = new PropertyStatisticsTable($store->getConnection('mw.db'), \SMWSQLStore3::PROPERTY_STATISTICS_TABLE); // Need to instantiate an extra object here since we cannot make this class itself // into a MessageReporter since the maintenance script does not load the interface in time. $reporter = new ObservableMessageReporter(); $reporter->registerReporterCallback(array($this, 'reportMessage')); $statisticsRebuilder = new SimplePropertyStatisticsRebuilder($store, $reporter); $statisticsRebuilder->rebuild($statsTable); }
public function testRebuildWithValidPropertyStatisticsStoreInsertUsageCount() { $arbitraryPropertyTableName = 'allornothing'; $propertySelectRow = new \stdClass(); $propertySelectRow->count = 1111; $selectResult = array('smw_title' => 'Foo', 'smw_id' => 9999); $selectResultWrapper = new FakeResultWrapper(array((object) $selectResult)); $database = $this->getMockBuilder('\\SMW\\MediaWiki\\Database')->disableOriginalConstructor()->getMock(); $database->expects($this->atLeastOnce())->method('select')->will($this->returnValue($selectResultWrapper)); $database->expects($this->once())->method('selectRow')->with($this->stringContains($arbitraryPropertyTableName), $this->anything(), $this->equalTo(array('p_id' => 9999)), $this->anything())->will($this->returnValue($propertySelectRow)); $store = $this->getMockBuilder('\\SMWSQLStore3')->disableOriginalConstructor()->getMock(); $store->expects($this->atLeastOnce())->method('getConnection')->will($this->returnValue($database)); $store->expects($this->atLeastOnce())->method('getPropertyTables')->will($this->returnValue(array($this->getNonFixedPropertyTable($arbitraryPropertyTableName)))); $instance = new SimplePropertyStatisticsRebuilder($store, null); $propertyStatisticsStore = $this->getMockBuilder('\\SMW\\Store\\PropertyStatisticsStore')->disableOriginalConstructor()->getMock(); $propertyStatisticsStore->expects($this->atLeastOnce())->method('insertUsageCount'); $instance->rebuild($propertyStatisticsStore); }