コード例 #1
0
ファイル: updatedb.php プロジェクト: hyb148/core
 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');
 }
コード例 #2
0
ファイル: updatedbtest.php プロジェクト: evanjt/core
 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]);
 }
コード例 #3
0
 /**
  * @param string $mimeType
  * @return string
  */
 protected function getPreviewPathFromMimeType($mimeType)
 {
     $mimeTypeIcon = $this->mimeTypeDetector->mimeTypeIcon($mimeType);
     if (substr($mimeTypeIcon, -4) === '.png') {
         $mimeTypeIcon = substr($mimeTypeIcon, 0, -4) . '.svg';
     }
     return $mimeTypeIcon;
 }
コード例 #4
0
 /**
  * @param string $messageId
  * @param $accountId
  * @param $folderId
  * @return callable
  */
 private function enrichDownloadUrl($accountId, $folderId, $messageId, $attachment)
 {
     $downloadUrl = \OCP\Util::linkToRoute('mail.messages.downloadAttachment', ['accountId' => $accountId, 'folderId' => $folderId, 'messageId' => $messageId, 'attachmentId' => $attachment['id']]);
     $downloadUrl = \OC::$server->getURLGenerator()->getAbsoluteURL($downloadUrl);
     $attachment['downloadUrl'] = $downloadUrl;
     $attachment['mimeUrl'] = $this->mimeTypeDetector->mimeTypeIcon($attachment['mime']);
     if ($this->attachmentIsImage($attachment)) {
         $attachment['isImage'] = true;
     }
     return $attachment;
 }
コード例 #5
0
ファイル: updatejs.php プロジェクト: evanjt/core
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // Fetch all the aliases
        $aliases = $this->mimetypeDetector->getAllAliases();
        // Remove comments
        $keys = array_filter(array_keys($aliases), function ($k) {
            return $k[0] === '_';
        });
        foreach ($keys as $key) {
            unset($aliases[$key]);
        }
        // Fetch all files
        $dir = new \DirectoryIterator(\OC::$SERVERROOT . '/core/img/filetypes');
        $files = [];
        foreach ($dir as $fileInfo) {
            if ($fileInfo->isFile()) {
                $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
                $files[] = $file;
            }
        }
        //Remove duplicates
        $files = array_values(array_unique($files));
        // Fetch all themes!
        $themes = [];
        $dirs = new \DirectoryIterator(\OC::$SERVERROOT . '/themes/');
        foreach ($dirs as $dir) {
            //Valid theme dir
            if ($dir->isFile() || $dir->isDot()) {
                continue;
            }
            $theme = $dir->getFilename();
            $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/';
            // Check if this theme has its own filetype icons
            if (!file_exists($themeDir)) {
                continue;
            }
            $themes[$theme] = [];
            // Fetch all the theme icons!
            $themeIt = new \DirectoryIterator($themeDir);
            foreach ($themeIt as $fileInfo) {
                if ($fileInfo->isFile()) {
                    $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
                    $themes[$theme][] = $file;
                }
            }
            //Remove Duplicates
            $themes[$theme] = array_values(array_unique($themes[$theme]));
        }
        //Generate the JS
        $js = '/**
* This file is automatically generated
* DO NOT EDIT MANUALLY!
*
* You can update the list of MimeType Aliases in config/mimetypealiases.json
* The list of files is fetched from core/img/filetypes
* To regenerate this file run ./occ maintenance:mimetypesjs
*/
OC.MimeTypeList={
	aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ',
	files: ' . json_encode($files, JSON_PRETTY_PRINT) . ',
	themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . '
};
';
        //Output the JS
        file_put_contents(\OC::$SERVERROOT . '/core/js/mimetypelist.js', $js);
        $output->writeln('<info>mimetypelist.js is updated');
    }
コード例 #6
0
ファイル: ocsendpointtest.php プロジェクト: ynott/activity
 /**
  * @dataProvider dataGetPreviewPathFromMimeType
  * @param string $mimeType
  * @param string $icon
  * @param string $expected
  */
 public function testGetPreviewPathFromMimeType($mimeType, $icon, $expected)
 {
     $this->mimeTypeDetector->expects($this->once())->method('mimeTypeIcon')->with($mimeType)->willReturn($icon);
     $this->assertSame($expected, $this->invokePrivate($this->controller, 'getPreviewPathFromMimeType', [$mimeType]));
 }