@@ -34,145 +34,145 @@ |
||
| 34 | 34 | use OCP\Migration\IRepairStep; |
| 35 | 35 | |
| 36 | 36 | class RepairMimeTypes implements IRepairStep { |
| 37 | - /** |
|
| 38 | - * @var \OCP\IConfig |
|
| 39 | - */ |
|
| 40 | - protected $config; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - protected $folderMimeTypeId; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param \OCP\IConfig $config |
|
| 49 | - */ |
|
| 50 | - public function __construct($config) { |
|
| 51 | - $this->config = $config; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function getName() { |
|
| 55 | - return 'Repair mime types'; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - private static function existsStmt() { |
|
| 59 | - return \OC_DB::prepare(' |
|
| 37 | + /** |
|
| 38 | + * @var \OCP\IConfig |
|
| 39 | + */ |
|
| 40 | + protected $config; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + protected $folderMimeTypeId; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param \OCP\IConfig $config |
|
| 49 | + */ |
|
| 50 | + public function __construct($config) { |
|
| 51 | + $this->config = $config; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function getName() { |
|
| 55 | + return 'Repair mime types'; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + private static function existsStmt() { |
|
| 59 | + return \OC_DB::prepare(' |
|
| 60 | 60 | SELECT count(`mimetype`) |
| 61 | 61 | FROM `*PREFIX*mimetypes` |
| 62 | 62 | WHERE `mimetype` = ? |
| 63 | 63 | '); |
| 64 | - } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - private static function getIdStmt() { |
|
| 67 | - return \OC_DB::prepare(' |
|
| 66 | + private static function getIdStmt() { |
|
| 67 | + return \OC_DB::prepare(' |
|
| 68 | 68 | SELECT `id` |
| 69 | 69 | FROM `*PREFIX*mimetypes` |
| 70 | 70 | WHERE `mimetype` = ? |
| 71 | 71 | '); |
| 72 | - } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - private static function insertStmt() { |
|
| 75 | - return \OC_DB::prepare(' |
|
| 74 | + private static function insertStmt() { |
|
| 75 | + return \OC_DB::prepare(' |
|
| 76 | 76 | INSERT INTO `*PREFIX*mimetypes` ( `mimetype` ) |
| 77 | 77 | VALUES ( ? ) |
| 78 | 78 | '); |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - private static function updateByNameStmt() { |
|
| 82 | - return \OC_DB::prepare(' |
|
| 81 | + private static function updateByNameStmt() { |
|
| 82 | + return \OC_DB::prepare(' |
|
| 83 | 83 | UPDATE `*PREFIX*filecache` |
| 84 | 84 | SET `mimetype` = ? |
| 85 | 85 | WHERE `mimetype` <> ? AND `mimetype` <> ? AND `name` ILIKE ? |
| 86 | 86 | '); |
| 87 | - } |
|
| 88 | - |
|
| 89 | - private function updateMimetypes($updatedMimetypes) { |
|
| 90 | - if (empty($this->folderMimeTypeId)) { |
|
| 91 | - $result = \OC_DB::executeAudited(self::getIdStmt(), array('httpd/unix-directory')); |
|
| 92 | - $this->folderMimeTypeId = (int)$result->fetchOne(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - foreach ($updatedMimetypes as $extension => $mimetype) { |
|
| 96 | - $result = \OC_DB::executeAudited(self::existsStmt(), array($mimetype)); |
|
| 97 | - $exists = $result->fetchOne(); |
|
| 98 | - |
|
| 99 | - if (!$exists) { |
|
| 100 | - // insert mimetype |
|
| 101 | - \OC_DB::executeAudited(self::insertStmt(), array($mimetype)); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // get target mimetype id |
|
| 105 | - $result = \OC_DB::executeAudited(self::getIdStmt(), array($mimetype)); |
|
| 106 | - $mimetypeId = $result->fetchOne(); |
|
| 107 | - |
|
| 108 | - // change mimetype for files with x extension |
|
| 109 | - \OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $this->folderMimeTypeId, $mimetypeId, '%.' . $extension)); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - private function introduceImageTypes() { |
|
| 114 | - $updatedMimetypes = array( |
|
| 115 | - 'jp2' => 'image/jp2', |
|
| 116 | - 'webp' => 'image/webp', |
|
| 117 | - ); |
|
| 118 | - |
|
| 119 | - $this->updateMimetypes($updatedMimetypes); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - private function introduceWindowsProgramTypes() { |
|
| 123 | - $updatedMimetypes = array( |
|
| 124 | - 'htaccess' => 'text/plain', |
|
| 125 | - 'bat' => 'application/x-msdos-program', |
|
| 126 | - 'cmd' => 'application/cmd', |
|
| 127 | - ); |
|
| 128 | - |
|
| 129 | - $this->updateMimetypes($updatedMimetypes); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - private function introduceLocationTypes() { |
|
| 133 | - $updatedMimetypes = [ |
|
| 134 | - 'gpx' => 'application/gpx+xml', |
|
| 135 | - 'kml' => 'application/vnd.google-earth.kml+xml', |
|
| 136 | - 'kmz' => 'application/vnd.google-earth.kmz', |
|
| 137 | - 'tcx' => 'application/vnd.garmin.tcx+xml', |
|
| 138 | - ]; |
|
| 139 | - |
|
| 140 | - $this->updateMimetypes($updatedMimetypes); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - private function introduceInternetShortcutTypes() { |
|
| 144 | - $updatedMimetypes = [ |
|
| 145 | - 'url' => 'application/internet-shortcut', |
|
| 146 | - 'webloc' => 'application/internet-shortcut' |
|
| 147 | - ]; |
|
| 148 | - |
|
| 149 | - $this->updateMimetypes($updatedMimetypes); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Fix mime types |
|
| 154 | - */ |
|
| 155 | - public function run(IOutput $out) { |
|
| 156 | - |
|
| 157 | - $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 158 | - |
|
| 159 | - // NOTE TO DEVELOPERS: when adding new mime types, please make sure to |
|
| 160 | - // add a version comparison to avoid doing it every time |
|
| 161 | - |
|
| 162 | - if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.14', '<') && $this->introduceImageTypes()) { |
|
| 163 | - $out->info('Fixed image mime types'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) { |
|
| 167 | - $out->info('Fixed windows program mime types'); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.0', '<') && $this->introduceLocationTypes()) { |
|
| 171 | - $out->info('Fixed geospatial mime types'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) { |
|
| 175 | - $out->info('Fixed internet-shortcut mime types'); |
|
| 176 | - } |
|
| 177 | - } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + private function updateMimetypes($updatedMimetypes) { |
|
| 90 | + if (empty($this->folderMimeTypeId)) { |
|
| 91 | + $result = \OC_DB::executeAudited(self::getIdStmt(), array('httpd/unix-directory')); |
|
| 92 | + $this->folderMimeTypeId = (int)$result->fetchOne(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + foreach ($updatedMimetypes as $extension => $mimetype) { |
|
| 96 | + $result = \OC_DB::executeAudited(self::existsStmt(), array($mimetype)); |
|
| 97 | + $exists = $result->fetchOne(); |
|
| 98 | + |
|
| 99 | + if (!$exists) { |
|
| 100 | + // insert mimetype |
|
| 101 | + \OC_DB::executeAudited(self::insertStmt(), array($mimetype)); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // get target mimetype id |
|
| 105 | + $result = \OC_DB::executeAudited(self::getIdStmt(), array($mimetype)); |
|
| 106 | + $mimetypeId = $result->fetchOne(); |
|
| 107 | + |
|
| 108 | + // change mimetype for files with x extension |
|
| 109 | + \OC_DB::executeAudited(self::updateByNameStmt(), array($mimetypeId, $this->folderMimeTypeId, $mimetypeId, '%.' . $extension)); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + private function introduceImageTypes() { |
|
| 114 | + $updatedMimetypes = array( |
|
| 115 | + 'jp2' => 'image/jp2', |
|
| 116 | + 'webp' => 'image/webp', |
|
| 117 | + ); |
|
| 118 | + |
|
| 119 | + $this->updateMimetypes($updatedMimetypes); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + private function introduceWindowsProgramTypes() { |
|
| 123 | + $updatedMimetypes = array( |
|
| 124 | + 'htaccess' => 'text/plain', |
|
| 125 | + 'bat' => 'application/x-msdos-program', |
|
| 126 | + 'cmd' => 'application/cmd', |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + $this->updateMimetypes($updatedMimetypes); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + private function introduceLocationTypes() { |
|
| 133 | + $updatedMimetypes = [ |
|
| 134 | + 'gpx' => 'application/gpx+xml', |
|
| 135 | + 'kml' => 'application/vnd.google-earth.kml+xml', |
|
| 136 | + 'kmz' => 'application/vnd.google-earth.kmz', |
|
| 137 | + 'tcx' => 'application/vnd.garmin.tcx+xml', |
|
| 138 | + ]; |
|
| 139 | + |
|
| 140 | + $this->updateMimetypes($updatedMimetypes); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + private function introduceInternetShortcutTypes() { |
|
| 144 | + $updatedMimetypes = [ |
|
| 145 | + 'url' => 'application/internet-shortcut', |
|
| 146 | + 'webloc' => 'application/internet-shortcut' |
|
| 147 | + ]; |
|
| 148 | + |
|
| 149 | + $this->updateMimetypes($updatedMimetypes); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Fix mime types |
|
| 154 | + */ |
|
| 155 | + public function run(IOutput $out) { |
|
| 156 | + |
|
| 157 | + $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
| 158 | + |
|
| 159 | + // NOTE TO DEVELOPERS: when adding new mime types, please make sure to |
|
| 160 | + // add a version comparison to avoid doing it every time |
|
| 161 | + |
|
| 162 | + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.14', '<') && $this->introduceImageTypes()) { |
|
| 163 | + $out->info('Fixed image mime types'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) { |
|
| 167 | + $out->info('Fixed windows program mime types'); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.0', '<') && $this->introduceLocationTypes()) { |
|
| 171 | + $out->info('Fixed geospatial mime types'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) { |
|
| 175 | + $out->info('Fixed internet-shortcut mime types'); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | 178 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $keys = array_filter(array_keys($aliases), function($k) { |
| 57 | 57 | return $k[0] === '_'; |
| 58 | 58 | }); |
| 59 | - foreach($keys as $key) { |
|
| 59 | + foreach ($keys as $key) { |
|
| 60 | 60 | unset($aliases[$key]); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes'); |
| 65 | 65 | |
| 66 | 66 | $files = []; |
| 67 | - foreach($dir as $fileInfo) { |
|
| 67 | + foreach ($dir as $fileInfo) { |
|
| 68 | 68 | if ($fileInfo->isFile()) { |
| 69 | 69 | $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
| 70 | 70 | $files[] = $file; |
@@ -78,14 +78,14 @@ discard block |
||
| 78 | 78 | // Fetch all themes! |
| 79 | 79 | $themes = []; |
| 80 | 80 | $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/'); |
| 81 | - foreach($dirs as $dir) { |
|
| 81 | + foreach ($dirs as $dir) { |
|
| 82 | 82 | //Valid theme dir |
| 83 | 83 | if ($dir->isFile() || $dir->isDot()) { |
| 84 | 84 | continue; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $theme = $dir->getFilename(); |
| 88 | - $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/'; |
|
| 88 | + $themeDir = $dir->getPath().'/'.$theme.'/core/img/filetypes/'; |
|
| 89 | 89 | // Check if this theme has its own filetype icons |
| 90 | 90 | if (!file_exists($themeDir)) { |
| 91 | 91 | continue; |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * To regenerate this file run ./occ maintenance:mimetype:update-js |
| 117 | 117 | */ |
| 118 | 118 | OC.MimeTypeList={ |
| 119 | - aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ', |
|
| 120 | - files: ' . json_encode($files, JSON_PRETTY_PRINT) . ', |
|
| 121 | - themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . ' |
|
| 119 | + aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).', |
|
| 120 | + files: ' . json_encode($files, JSON_PRETTY_PRINT).', |
|
| 121 | + themes: ' . json_encode($themes, JSON_PRETTY_PRINT).' |
|
| 122 | 122 | }; |
| 123 | 123 | '; |
| 124 | 124 | |