public function testRebuildPropertyInfo()
 {
     $table = new PropertyInfoTable(false);
     $this->resetPropertyInfoTable($table);
     $properties = $this->initProperties();
     $propertyIds = array_keys($properties);
     // NOTE: We use the EntityStore from WikibaseRepo in initProperties,
     //       so we should also use the EntityLookup from WikibaseRepo.
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $entityLookup = $wikibaseRepo->getEntityLookup('uncached');
     $propertyInfoBuilder = new PropertyInfoBuilder(new PropertyId('P1630'));
     $builder = new PropertyInfoTableBuilder($table, $entityLookup, $propertyInfoBuilder);
     $builder->setBatchSize(3);
     // rebuild all ----
     $builder->setFromId(0);
     $builder->setRebuildAll(true);
     $builder->rebuildPropertyInfo();
     $this->assertTableHasProperties($properties, $table);
     // make table incomplete ----
     $propId1 = new PropertyId($propertyIds[0]);
     $table->removePropertyInfo($propId1);
     // rebuild from offset, with no effect ----
     $builder->setFromId($propId1->getNumericId() + 1);
     $builder->setRebuildAll(false);
     $builder->rebuildPropertyInfo();
     $info = $table->getPropertyInfo($propId1);
     $this->assertNull($info, "rebuild missing from offset should have skipped this");
     // rebuild all from offset, with no effect ----
     $builder->setFromId($propId1->getNumericId() + 1);
     $builder->setRebuildAll(false);
     $builder->rebuildPropertyInfo();
     $info = $table->getPropertyInfo($propId1);
     $this->assertNull($info, "rebuild all from offset should have skipped this");
     // rebuild missing  ----
     $builder->setFromId(0);
     $builder->setRebuildAll(false);
     $builder->rebuildPropertyInfo();
     $this->assertTableHasProperties($properties, $table);
     // rebuild again ----
     $builder->setFromId(0);
     $builder->setRebuildAll(false);
     $c = $builder->rebuildPropertyInfo();
     $this->assertEquals(0, $c, "There should be nothing left to rebuild");
 }
 /**
  * @see LoggedUpdateMaintenance::doDBUpdates
  *
  * @return bool
  */
 public function doDBUpdates()
 {
     if (!defined('WB_VERSION')) {
         $this->output("You need to have Wikibase enabled in order to use this maintenance script!\n\n");
         exit;
     }
     $reporter = new ObservableMessageReporter();
     $reporter->registerReporterCallback(array($this, 'report'));
     $table = new PropertyInfoTable(false);
     $wikibaseRepo = WikibaseRepo::getDefaultInstance();
     $entityLookup = $wikibaseRepo->getEntityLookup();
     $propertyInfoBuilder = $wikibaseRepo->newPropertyInfoBuilder();
     $builder = new PropertyInfoTableBuilder($table, $entityLookup, $propertyInfoBuilder);
     $builder->setReporter($reporter);
     $builder->setBatchSize((int) $this->getOption('batch-size', 100));
     $builder->setRebuildAll($this->getOption('rebuild-all', false));
     $builder->setFromId((int) $this->getOption('start-row', 1));
     $n = $builder->rebuildPropertyInfo();
     $this->output("Done. Updated {$n} property info entries.\n");
     return true;
 }