protected function execute(InputInterface $input, OutputInterface $output) { $mappings = $this->mimetypeDetector->getAllMappings(); $totalFilecacheUpdates = 0; $totalNewMimetypes = 0; foreach ($mappings as $ext => $mimetypes) { 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'); }
/** * search for files by mimetype * * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') * where it will search for all mimetypes in the group ('image/*') * @return array an array of cache entries where the mimetype matches the search */ public function searchByMime($mimetype) { if (strpos($mimetype, '/')) { $where = '`mimetype` = ?'; } else { $where = '`mimepart` = ?'; } $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `etag`, `permissions` FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?'; $mimetype = $this->mimetypeLoader->getId($mimetype); $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId())); $files = array(); while ($row = $result->fetch()) { $row['mimetype'] = $this->mimetypeLoader->getMimetypeById($row['mimetype']); $row['mimepart'] = $this->mimetypeLoader->getMimetypeById($row['mimepart']); $files[] = $row; } return $files; }