protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->initServices();
     if (is_string($input->getOption('tmpDir'))) {
         $this->tmpDir = $input->getOption('tmpDir');
     } else {
         $this->tmpDir = sys_get_temp_dir();
     }
     if (!is_writable($this->tmpDir)) {
         throw new RuntimeException('Temp dir: ' . $this->tmpDir . ' is not writable');
     }
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelper('formatter');
     $output->writeln($formatter->formatBlock(array('Wikidata Referencer', 'This script is in development, If something goes wrong while you use it it is your fault!', 'Temp file: ' . $this->getProcessedListPath()), 'info'));
     // Get options
     $user = $input->getOption('user');
     $userDetails = $this->appConfig->offsetGet('users.' . $user);
     if ($userDetails === null) {
         throw new RuntimeException('User not found in config');
     }
     $sparqlQueryParts = $input->getOption('sparql');
     $item = $input->getOption('item');
     $force = false;
     // Get a list of ItemIds
     if ($item !== null) {
         $output->writeln($formatter->formatSection('Init', 'Using item passed in item parameter'));
         $itemIds = array(new ItemId($item));
         // Force if explicitly passed an ItemId
         $force = true;
     } elseif (!empty($sparqlQueryParts)) {
         $output->writeln($formatter->formatSection('Init', 'Using items from SPARQL QUERY (running)'));
         $itemIds = $this->sparqlQueryRunner->getItemIdsForSimpleQueryParts($sparqlQueryParts);
     } else {
         throw new RuntimeException('You must pass an instance id or an item');
     }
     shuffle($itemIds);
     $output->writeln($formatter->formatSection('Init', 'Got ' . count($itemIds) . ' items to investigate'));
     // Log in to Wikidata
     $loggedIn = $this->wikibaseApi->login(new ApiUser($userDetails['username'], $userDetails['password']));
     if (!$loggedIn) {
         throw new RuntimeException('Failed to log in to wikibase wiki');
     }
     $this->executeForItemIds($output, $itemIds, $force);
     return 0;
 }