setName('maintenance:mimetype:update-db') ->setDescription('Update database mimetypes and update filecache') ->addOption( 'repair-filecache', null, InputOption::VALUE_NONE, 'Repair filecache for all mimetypes, not just new ones' ) ; } protected function execute(InputInterface $input, OutputInterface $output): int { $mappings = $this->mimetypeDetector->getAllMappings(); $totalFilecacheUpdates = 0; $totalNewMimetypes = 0; foreach ($mappings as $ext => $mimetypes) { // Single digit extensions will be treated as integers // Let's make sure they are strings // https://github.com/nextcloud/server/issues/42902 $ext = (string)$ext; if ($ext[0] === '_') { // comment continue; } $mimetype = $mimetypes[0]; $existing = $this->mimetypeLoader->exists($mimetype); // this will add the mimetype if it didn't exist $mimetypeId = $this->mimetypeLoader->getId($mimetype); if (!$existing) { $output->writeln('Added mimetype "' . $mimetype . '" to database'); $totalNewMimetypes++; } if (!$existing || $input->getOption('repair-filecache')) { $touchedFilecacheRows = $this->mimetypeLoader->updateFilecache($ext, $mimetypeId); if ($touchedFilecacheRows > 0) { $output->writeln('Updated ' . $touchedFilecacheRows . ' filecache rows for mimetype "' . $mimetype . '"'); } $totalFilecacheUpdates += $touchedFilecacheRows; } } $output->writeln('Added ' . $totalNewMimetypes . ' new mimetypes'); $output->writeln('Updated ' . $totalFilecacheUpdates . ' filecache rows'); return 0; } }