Example #1
0
 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');
 }
Example #2
0
 public function testRepairFilecache()
 {
     $this->consoleInput->method('getOption')->with('repair-filecache')->willReturn(true);
     $this->detector->expects($this->once())->method('getAllMappings')->willReturn(['ext' => ['testing/existingmimetype']]);
     $this->loader->expects($this->exactly(1))->method('exists')->will($this->returnValueMap([['testing/existingmimetype', true]]));
     $this->loader->expects($this->exactly(1))->method('getId')->will($this->returnValueMap([['testing/existingmimetype', 1]]));
     $this->loader->expects($this->once())->method('updateFilecache')->with('ext', 1)->willReturn(3);
     $this->consoleOutput->expects($this->at(0))->method('writeln')->with('Updated 3 filecache rows for mimetype "testing/existingmimetype"');
     $this->consoleOutput->expects($this->at(1))->method('writeln')->with('Added 0 new mimetypes');
     $this->consoleOutput->expects($this->at(2))->method('writeln')->with('Updated 3 filecache rows');
     self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
 }
 private function renameMimeTypes($currentMimeTypes, $fixedMimeTypes)
 {
     $this->addEntries($currentMimeTypes);
     /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
     $outputMock = $this->getMockBuilder('\\OCP\\Migration\\IOutput')->disableOriginalConstructor()->getMock();
     $this->repair->run($outputMock);
     // force mimetype reload
     $this->mimetypeLoader->reset();
     $this->checkEntries($fixedMimeTypes);
 }
Example #4
0
    /**
     * 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;
    }