protected function execute(InputInterface $input, OutputInterface $output) { $user = $input->getOption('user'); $userDetails = $this->appConfig->offsetGet('users.' . $user); if ($userDetails === null) { throw new RuntimeException('User not found in config'); } $wiki = $input->getOption('wiki'); $wikiDetails = $this->appConfig->offsetGet('wikis.' . $wiki); if ($wikiDetails === null) { throw new RuntimeException('Wiki not found in config'); } $sparql = $input->getOption('sparql'); if ($sparql === null || empty($sparql)) { throw new RuntimeException('SPARQL endpoint must be passed'); } $this->setServices($wikiDetails['url'], $sparql); $propertyString = $input->getOption('property'); $property = new PropertyId($propertyString); if ($propertyString === null || $propertyString === '' || $property === null) { throw new RuntimeException('No property given'); } $output->writeln('Running SPARQL query to find items to check'); $queryBuilder = new QueryBuilder(array('wdt' => 'http://www.wikidata.org/prop/direct/')); $itemIds = $this->sparqlQueryRunner->getItemIdsFromQuery($queryBuilder->select('?item')->where('?item', 'wdt:' . $propertyString, '?value')->limit(10000)->__toString()); $loggedIn = $this->wikibaseApi->login(new ApiUser($userDetails['username'], $userDetails['password'])); if (!$loggedIn) { $output->writeln('Failed to log in to wikibase wiki'); return -1; } $itemLookup = $this->wikibaseFactory->newItemLookup(); $statementRemover = $this->wikibaseFactory->newStatementRemover(); foreach ($itemIds as $itemId) { $item = $itemLookup->getItemForId($itemId); foreach ($item->getStatements()->getIterator() as $statement) { if ($statement->getPropertyId()->equals($property)) { $statementRemover->remove($statement, new EditInfo('Removing Statement')); } } } return 0; }