@@ -72,181 +72,181 @@ |
||
72 | 72 | |
73 | 73 | class Repair implements IOutput { |
74 | 74 | |
75 | - /** @var IRepairStep[] */ |
|
76 | - private $repairSteps; |
|
77 | - |
|
78 | - /** @var EventDispatcherInterface */ |
|
79 | - private $dispatcher; |
|
80 | - |
|
81 | - /** @var string */ |
|
82 | - private $currentStep; |
|
83 | - |
|
84 | - /** |
|
85 | - * Creates a new repair step runner |
|
86 | - * |
|
87 | - * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
88 | - * @param EventDispatcherInterface $dispatcher |
|
89 | - */ |
|
90 | - public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) { |
|
91 | - $this->repairSteps = $repairSteps; |
|
92 | - $this->dispatcher = $dispatcher; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Run a series of repair steps for common problems |
|
97 | - */ |
|
98 | - public function run() { |
|
99 | - if (count($this->repairSteps) === 0) { |
|
100 | - $this->emit('\OC\Repair', 'info', ['No repair steps available']); |
|
101 | - |
|
102 | - return; |
|
103 | - } |
|
104 | - // run each repair step |
|
105 | - foreach ($this->repairSteps as $step) { |
|
106 | - $this->currentStep = $step->getName(); |
|
107 | - $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
108 | - $step->run($this); |
|
109 | - } |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Add repair step |
|
114 | - * |
|
115 | - * @param IRepairStep|string $repairStep repair step |
|
116 | - * @throws \Exception |
|
117 | - */ |
|
118 | - public function addStep($repairStep) { |
|
119 | - if (is_string($repairStep)) { |
|
120 | - try { |
|
121 | - $s = \OC::$server->query($repairStep); |
|
122 | - } catch (QueryException $e) { |
|
123 | - if (class_exists($repairStep)) { |
|
124 | - $s = new $repairStep(); |
|
125 | - } else { |
|
126 | - throw new \Exception("Repair step '$repairStep' is unknown"); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - if ($s instanceof IRepairStep) { |
|
131 | - $this->repairSteps[] = $s; |
|
132 | - } else { |
|
133 | - throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
134 | - } |
|
135 | - } else { |
|
136 | - $this->repairSteps[] = $repairStep; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Returns the default repair steps to be run on the |
|
142 | - * command line or after an upgrade. |
|
143 | - * |
|
144 | - * @return IRepairStep[] |
|
145 | - */ |
|
146 | - public static function getRepairSteps() { |
|
147 | - return [ |
|
148 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
149 | - new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
150 | - new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
151 | - new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
152 | - new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
153 | - new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
154 | - new AddLogRotateJob(\OC::$server->getJobList()), |
|
155 | - new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
156 | - new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
157 | - new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
158 | - new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
159 | - new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
160 | - new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
161 | - new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), |
|
162 | - new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)), |
|
163 | - \OC::$server->query(ResetGeneratedAvatarFlag::class), |
|
164 | - \OC::$server->query(EncryptionLegacyCipher::class), |
|
165 | - \OC::$server->query(EncryptionMigration::class), |
|
166 | - \OC::$server->get(ShippedDashboardEnable::class), |
|
167 | - \OC::$server->get(AddBruteForceCleanupJob::class), |
|
168 | - \OC::$server->get(AddCheckForUserCertificatesJob::class), |
|
169 | - ]; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Returns expensive repair steps to be run on the |
|
174 | - * command line with a special option. |
|
175 | - * |
|
176 | - * @return IRepairStep[] |
|
177 | - */ |
|
178 | - public static function getExpensiveRepairSteps() { |
|
179 | - return [ |
|
180 | - new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()) |
|
181 | - ]; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Returns the repair steps to be run before an |
|
186 | - * upgrade. |
|
187 | - * |
|
188 | - * @return IRepairStep[] |
|
189 | - */ |
|
190 | - public static function getBeforeUpgradeRepairSteps() { |
|
191 | - $connection = \OC::$server->getDatabaseConnection(); |
|
192 | - $config = \OC::$server->getConfig(); |
|
193 | - $steps = [ |
|
194 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
195 | - new SqliteAutoincrement($connection), |
|
196 | - new SaveAccountsTableData($connection, $config), |
|
197 | - new DropAccountTermsTable($connection) |
|
198 | - ]; |
|
199 | - |
|
200 | - return $steps; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @param string $scope |
|
205 | - * @param string $method |
|
206 | - * @param array $arguments |
|
207 | - */ |
|
208 | - public function emit($scope, $method, array $arguments = []) { |
|
209 | - if (!is_null($this->dispatcher)) { |
|
210 | - $this->dispatcher->dispatch("$scope::$method", |
|
211 | - new GenericEvent("$scope::$method", $arguments)); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - public function info($string) { |
|
216 | - // for now just emit as we did in the past |
|
217 | - $this->emit('\OC\Repair', 'info', [$string]); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string $message |
|
222 | - */ |
|
223 | - public function warning($message) { |
|
224 | - // for now just emit as we did in the past |
|
225 | - $this->emit('\OC\Repair', 'warning', [$message]); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @param int $max |
|
230 | - */ |
|
231 | - public function startProgress($max = 0) { |
|
232 | - // for now just emit as we did in the past |
|
233 | - $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * @param int $step |
|
238 | - * @param string $description |
|
239 | - */ |
|
240 | - public function advance($step = 1, $description = '') { |
|
241 | - // for now just emit as we did in the past |
|
242 | - $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * @param int $max |
|
247 | - */ |
|
248 | - public function finishProgress() { |
|
249 | - // for now just emit as we did in the past |
|
250 | - $this->emit('\OC\Repair', 'finishProgress', []); |
|
251 | - } |
|
75 | + /** @var IRepairStep[] */ |
|
76 | + private $repairSteps; |
|
77 | + |
|
78 | + /** @var EventDispatcherInterface */ |
|
79 | + private $dispatcher; |
|
80 | + |
|
81 | + /** @var string */ |
|
82 | + private $currentStep; |
|
83 | + |
|
84 | + /** |
|
85 | + * Creates a new repair step runner |
|
86 | + * |
|
87 | + * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
88 | + * @param EventDispatcherInterface $dispatcher |
|
89 | + */ |
|
90 | + public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) { |
|
91 | + $this->repairSteps = $repairSteps; |
|
92 | + $this->dispatcher = $dispatcher; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Run a series of repair steps for common problems |
|
97 | + */ |
|
98 | + public function run() { |
|
99 | + if (count($this->repairSteps) === 0) { |
|
100 | + $this->emit('\OC\Repair', 'info', ['No repair steps available']); |
|
101 | + |
|
102 | + return; |
|
103 | + } |
|
104 | + // run each repair step |
|
105 | + foreach ($this->repairSteps as $step) { |
|
106 | + $this->currentStep = $step->getName(); |
|
107 | + $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
108 | + $step->run($this); |
|
109 | + } |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Add repair step |
|
114 | + * |
|
115 | + * @param IRepairStep|string $repairStep repair step |
|
116 | + * @throws \Exception |
|
117 | + */ |
|
118 | + public function addStep($repairStep) { |
|
119 | + if (is_string($repairStep)) { |
|
120 | + try { |
|
121 | + $s = \OC::$server->query($repairStep); |
|
122 | + } catch (QueryException $e) { |
|
123 | + if (class_exists($repairStep)) { |
|
124 | + $s = new $repairStep(); |
|
125 | + } else { |
|
126 | + throw new \Exception("Repair step '$repairStep' is unknown"); |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + if ($s instanceof IRepairStep) { |
|
131 | + $this->repairSteps[] = $s; |
|
132 | + } else { |
|
133 | + throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
134 | + } |
|
135 | + } else { |
|
136 | + $this->repairSteps[] = $repairStep; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Returns the default repair steps to be run on the |
|
142 | + * command line or after an upgrade. |
|
143 | + * |
|
144 | + * @return IRepairStep[] |
|
145 | + */ |
|
146 | + public static function getRepairSteps() { |
|
147 | + return [ |
|
148 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
149 | + new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
150 | + new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
151 | + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
152 | + new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
153 | + new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
154 | + new AddLogRotateJob(\OC::$server->getJobList()), |
|
155 | + new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
156 | + new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
157 | + new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
158 | + new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
159 | + new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
160 | + new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
161 | + new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), |
|
162 | + new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)), |
|
163 | + \OC::$server->query(ResetGeneratedAvatarFlag::class), |
|
164 | + \OC::$server->query(EncryptionLegacyCipher::class), |
|
165 | + \OC::$server->query(EncryptionMigration::class), |
|
166 | + \OC::$server->get(ShippedDashboardEnable::class), |
|
167 | + \OC::$server->get(AddBruteForceCleanupJob::class), |
|
168 | + \OC::$server->get(AddCheckForUserCertificatesJob::class), |
|
169 | + ]; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Returns expensive repair steps to be run on the |
|
174 | + * command line with a special option. |
|
175 | + * |
|
176 | + * @return IRepairStep[] |
|
177 | + */ |
|
178 | + public static function getExpensiveRepairSteps() { |
|
179 | + return [ |
|
180 | + new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()) |
|
181 | + ]; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Returns the repair steps to be run before an |
|
186 | + * upgrade. |
|
187 | + * |
|
188 | + * @return IRepairStep[] |
|
189 | + */ |
|
190 | + public static function getBeforeUpgradeRepairSteps() { |
|
191 | + $connection = \OC::$server->getDatabaseConnection(); |
|
192 | + $config = \OC::$server->getConfig(); |
|
193 | + $steps = [ |
|
194 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
195 | + new SqliteAutoincrement($connection), |
|
196 | + new SaveAccountsTableData($connection, $config), |
|
197 | + new DropAccountTermsTable($connection) |
|
198 | + ]; |
|
199 | + |
|
200 | + return $steps; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @param string $scope |
|
205 | + * @param string $method |
|
206 | + * @param array $arguments |
|
207 | + */ |
|
208 | + public function emit($scope, $method, array $arguments = []) { |
|
209 | + if (!is_null($this->dispatcher)) { |
|
210 | + $this->dispatcher->dispatch("$scope::$method", |
|
211 | + new GenericEvent("$scope::$method", $arguments)); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + public function info($string) { |
|
216 | + // for now just emit as we did in the past |
|
217 | + $this->emit('\OC\Repair', 'info', [$string]); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $message |
|
222 | + */ |
|
223 | + public function warning($message) { |
|
224 | + // for now just emit as we did in the past |
|
225 | + $this->emit('\OC\Repair', 'warning', [$message]); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @param int $max |
|
230 | + */ |
|
231 | + public function startProgress($max = 0) { |
|
232 | + // for now just emit as we did in the past |
|
233 | + $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * @param int $step |
|
238 | + * @param string $description |
|
239 | + */ |
|
240 | + public function advance($step = 1, $description = '') { |
|
241 | + // for now just emit as we did in the past |
|
242 | + $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * @param int $max |
|
247 | + */ |
|
248 | + public function finishProgress() { |
|
249 | + // for now just emit as we did in the past |
|
250 | + $this->emit('\OC\Repair', 'finishProgress', []); |
|
251 | + } |
|
252 | 252 | } |
@@ -40,197 +40,197 @@ |
||
40 | 40 | use OCP\Migration\IRepairStep; |
41 | 41 | |
42 | 42 | class RepairMimeTypes implements IRepairStep { |
43 | - /** @var IConfig */ |
|
44 | - protected $config; |
|
45 | - /** @var IDBConnection */ |
|
46 | - protected $connection; |
|
47 | - |
|
48 | - /** @var int */ |
|
49 | - protected $folderMimeTypeId; |
|
50 | - |
|
51 | - public function __construct(IConfig $config, |
|
52 | - IDBConnection $connection) { |
|
53 | - $this->config = $config; |
|
54 | - $this->connection = $connection; |
|
55 | - } |
|
56 | - |
|
57 | - public function getName() { |
|
58 | - return 'Repair mime types'; |
|
59 | - } |
|
60 | - |
|
61 | - private function updateMimetypes($updatedMimetypes) { |
|
62 | - $query = $this->connection->getQueryBuilder(); |
|
63 | - $query->select('id') |
|
64 | - ->from('mimetypes') |
|
65 | - ->where($query->expr()->eq('mimetype', $query->createParameter('mimetype'), IQueryBuilder::PARAM_INT)); |
|
66 | - $insert = $this->connection->getQueryBuilder(); |
|
67 | - $insert->insert('mimetypes') |
|
68 | - ->setValue('mimetype', $insert->createParameter('mimetype')); |
|
69 | - |
|
70 | - if (empty($this->folderMimeTypeId)) { |
|
71 | - $query->setParameter('mimetype', 'httpd/unix-directory'); |
|
72 | - $result = $query->execute(); |
|
73 | - $this->folderMimeTypeId = (int)$result->fetchColumn(); |
|
74 | - $result->closeCursor(); |
|
75 | - } |
|
76 | - |
|
77 | - $update = $this->connection->getQueryBuilder(); |
|
78 | - $update->update('filecache') |
|
79 | - ->set('mimetype', $update->createParameter('mimetype')) |
|
80 | - ->where($update->expr()->neq('mimetype', $update->createParameter('mimetype'), IQueryBuilder::PARAM_INT)) |
|
81 | - ->andWhere($update->expr()->neq('mimetype', $update->createParameter('folder'), IQueryBuilder::PARAM_INT)) |
|
82 | - ->andWhere($update->expr()->iLike('name', $update->createParameter('name'))) |
|
83 | - ->setParameter('folder', $this->folderMimeTypeId); |
|
84 | - |
|
85 | - $count = 0; |
|
86 | - foreach ($updatedMimetypes as $extension => $mimetype) { |
|
87 | - // get target mimetype id |
|
88 | - $query->setParameter('mimetype', $mimetype); |
|
89 | - $result = $query->execute(); |
|
90 | - $mimetypeId = (int)$result->fetchColumn(); |
|
91 | - $result->closeCursor(); |
|
92 | - |
|
93 | - if (!$mimetypeId) { |
|
94 | - // insert mimetype |
|
95 | - $insert->setParameter('mimetype', $mimetype); |
|
96 | - $insert->execute(); |
|
97 | - $mimetypeId = $insert->getLastInsertId(); |
|
98 | - } |
|
99 | - |
|
100 | - // change mimetype for files with x extension |
|
101 | - $update->setParameter('mimetype', $mimetypeId) |
|
102 | - ->setParameter('name', '%' . $this->connection->escapeLikeParameter('.' . $extension)); |
|
103 | - $count += $update->execute(); |
|
104 | - } |
|
105 | - |
|
106 | - return $count; |
|
107 | - } |
|
108 | - |
|
109 | - private function introduceImageTypes() { |
|
110 | - $updatedMimetypes = [ |
|
111 | - 'jp2' => 'image/jp2', |
|
112 | - 'webp' => 'image/webp', |
|
113 | - ]; |
|
114 | - |
|
115 | - return $this->updateMimetypes($updatedMimetypes); |
|
116 | - } |
|
117 | - |
|
118 | - private function introduceWindowsProgramTypes() { |
|
119 | - $updatedMimetypes = [ |
|
120 | - 'htaccess' => 'text/plain', |
|
121 | - 'bat' => 'application/x-msdos-program', |
|
122 | - 'cmd' => 'application/cmd', |
|
123 | - ]; |
|
124 | - |
|
125 | - return $this->updateMimetypes($updatedMimetypes); |
|
126 | - } |
|
127 | - |
|
128 | - private function introduceLocationTypes() { |
|
129 | - $updatedMimetypes = [ |
|
130 | - 'gpx' => 'application/gpx+xml', |
|
131 | - 'kml' => 'application/vnd.google-earth.kml+xml', |
|
132 | - 'kmz' => 'application/vnd.google-earth.kmz', |
|
133 | - 'tcx' => 'application/vnd.garmin.tcx+xml', |
|
134 | - ]; |
|
135 | - |
|
136 | - return $this->updateMimetypes($updatedMimetypes); |
|
137 | - } |
|
138 | - |
|
139 | - private function introduceInternetShortcutTypes() { |
|
140 | - $updatedMimetypes = [ |
|
141 | - 'url' => 'application/internet-shortcut', |
|
142 | - 'webloc' => 'application/internet-shortcut' |
|
143 | - ]; |
|
144 | - |
|
145 | - return $this->updateMimetypes($updatedMimetypes); |
|
146 | - } |
|
147 | - |
|
148 | - private function introduceStreamingTypes() { |
|
149 | - $updatedMimetypes = [ |
|
150 | - 'm3u' => 'audio/mpegurl', |
|
151 | - 'm3u8' => 'audio/mpegurl', |
|
152 | - 'pls' => 'audio/x-scpls' |
|
153 | - ]; |
|
154 | - |
|
155 | - return $this->updateMimetypes($updatedMimetypes); |
|
156 | - } |
|
157 | - |
|
158 | - private function introduceVisioTypes() { |
|
159 | - $updatedMimetypes = [ |
|
160 | - 'vsdm' => 'application/vnd.visio', |
|
161 | - 'vsdx' => 'application/vnd.visio', |
|
162 | - 'vssm' => 'application/vnd.visio', |
|
163 | - 'vssx' => 'application/vnd.visio', |
|
164 | - 'vstm' => 'application/vnd.visio', |
|
165 | - 'vstx' => 'application/vnd.visio', |
|
166 | - ]; |
|
167 | - |
|
168 | - return $this->updateMimetypes($updatedMimetypes); |
|
169 | - } |
|
170 | - |
|
171 | - private function introduceComicbookTypes() { |
|
172 | - $updatedMimetypes = [ |
|
173 | - 'cb7' => 'application/comicbook+7z', |
|
174 | - 'cba' => 'application/comicbook+ace', |
|
175 | - 'cbr' => 'application/comicbook+rar', |
|
176 | - 'cbt' => 'application/comicbook+tar', |
|
177 | - 'cbtc' => 'application/comicbook+truecrypt', |
|
178 | - 'cbz' => 'application/comicbook+zip', |
|
179 | - ]; |
|
180 | - |
|
181 | - return $this->updateMimetypes($updatedMimetypes); |
|
182 | - } |
|
183 | - |
|
184 | - private function introduceOpenDocumentTemplates() { |
|
185 | - $updatedMimetypes = [ |
|
186 | - 'ott' => 'application/vnd.oasis.opendocument.text-template', |
|
187 | - 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
|
188 | - 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
|
189 | - 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
|
190 | - ]; |
|
191 | - |
|
192 | - return $this->updateMimetypes($updatedMimetypes); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Fix mime types |
|
197 | - */ |
|
198 | - public function run(IOutput $out) { |
|
199 | - $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
200 | - |
|
201 | - // NOTE TO DEVELOPERS: when adding new mime types, please make sure to |
|
202 | - // add a version comparison to avoid doing it every time |
|
203 | - |
|
204 | - if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.14', '<') && $this->introduceImageTypes()) { |
|
205 | - $out->info('Fixed image mime types'); |
|
206 | - } |
|
207 | - |
|
208 | - if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) { |
|
209 | - $out->info('Fixed windows program mime types'); |
|
210 | - } |
|
211 | - |
|
212 | - if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.0', '<') && $this->introduceLocationTypes()) { |
|
213 | - $out->info('Fixed geospatial mime types'); |
|
214 | - } |
|
215 | - |
|
216 | - if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) { |
|
217 | - $out->info('Fixed internet-shortcut mime types'); |
|
218 | - } |
|
219 | - |
|
220 | - if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.6', '<') && $this->introduceStreamingTypes()) { |
|
221 | - $out->info('Fixed streaming mime types'); |
|
222 | - } |
|
223 | - |
|
224 | - if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.8', '<') && $this->introduceVisioTypes()) { |
|
225 | - $out->info('Fixed visio mime types'); |
|
226 | - } |
|
227 | - |
|
228 | - if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.10', '<') && $this->introduceComicbookTypes()) { |
|
229 | - $out->info('Fixed comicbook mime types'); |
|
230 | - } |
|
231 | - |
|
232 | - if (version_compare($ocVersionFromBeforeUpdate, '20.0.0.5', '<') && $this->introduceOpenDocumentTemplates()) { |
|
233 | - $out->info('Fixed OpenDocument template mime types'); |
|
234 | - } |
|
235 | - } |
|
43 | + /** @var IConfig */ |
|
44 | + protected $config; |
|
45 | + /** @var IDBConnection */ |
|
46 | + protected $connection; |
|
47 | + |
|
48 | + /** @var int */ |
|
49 | + protected $folderMimeTypeId; |
|
50 | + |
|
51 | + public function __construct(IConfig $config, |
|
52 | + IDBConnection $connection) { |
|
53 | + $this->config = $config; |
|
54 | + $this->connection = $connection; |
|
55 | + } |
|
56 | + |
|
57 | + public function getName() { |
|
58 | + return 'Repair mime types'; |
|
59 | + } |
|
60 | + |
|
61 | + private function updateMimetypes($updatedMimetypes) { |
|
62 | + $query = $this->connection->getQueryBuilder(); |
|
63 | + $query->select('id') |
|
64 | + ->from('mimetypes') |
|
65 | + ->where($query->expr()->eq('mimetype', $query->createParameter('mimetype'), IQueryBuilder::PARAM_INT)); |
|
66 | + $insert = $this->connection->getQueryBuilder(); |
|
67 | + $insert->insert('mimetypes') |
|
68 | + ->setValue('mimetype', $insert->createParameter('mimetype')); |
|
69 | + |
|
70 | + if (empty($this->folderMimeTypeId)) { |
|
71 | + $query->setParameter('mimetype', 'httpd/unix-directory'); |
|
72 | + $result = $query->execute(); |
|
73 | + $this->folderMimeTypeId = (int)$result->fetchColumn(); |
|
74 | + $result->closeCursor(); |
|
75 | + } |
|
76 | + |
|
77 | + $update = $this->connection->getQueryBuilder(); |
|
78 | + $update->update('filecache') |
|
79 | + ->set('mimetype', $update->createParameter('mimetype')) |
|
80 | + ->where($update->expr()->neq('mimetype', $update->createParameter('mimetype'), IQueryBuilder::PARAM_INT)) |
|
81 | + ->andWhere($update->expr()->neq('mimetype', $update->createParameter('folder'), IQueryBuilder::PARAM_INT)) |
|
82 | + ->andWhere($update->expr()->iLike('name', $update->createParameter('name'))) |
|
83 | + ->setParameter('folder', $this->folderMimeTypeId); |
|
84 | + |
|
85 | + $count = 0; |
|
86 | + foreach ($updatedMimetypes as $extension => $mimetype) { |
|
87 | + // get target mimetype id |
|
88 | + $query->setParameter('mimetype', $mimetype); |
|
89 | + $result = $query->execute(); |
|
90 | + $mimetypeId = (int)$result->fetchColumn(); |
|
91 | + $result->closeCursor(); |
|
92 | + |
|
93 | + if (!$mimetypeId) { |
|
94 | + // insert mimetype |
|
95 | + $insert->setParameter('mimetype', $mimetype); |
|
96 | + $insert->execute(); |
|
97 | + $mimetypeId = $insert->getLastInsertId(); |
|
98 | + } |
|
99 | + |
|
100 | + // change mimetype for files with x extension |
|
101 | + $update->setParameter('mimetype', $mimetypeId) |
|
102 | + ->setParameter('name', '%' . $this->connection->escapeLikeParameter('.' . $extension)); |
|
103 | + $count += $update->execute(); |
|
104 | + } |
|
105 | + |
|
106 | + return $count; |
|
107 | + } |
|
108 | + |
|
109 | + private function introduceImageTypes() { |
|
110 | + $updatedMimetypes = [ |
|
111 | + 'jp2' => 'image/jp2', |
|
112 | + 'webp' => 'image/webp', |
|
113 | + ]; |
|
114 | + |
|
115 | + return $this->updateMimetypes($updatedMimetypes); |
|
116 | + } |
|
117 | + |
|
118 | + private function introduceWindowsProgramTypes() { |
|
119 | + $updatedMimetypes = [ |
|
120 | + 'htaccess' => 'text/plain', |
|
121 | + 'bat' => 'application/x-msdos-program', |
|
122 | + 'cmd' => 'application/cmd', |
|
123 | + ]; |
|
124 | + |
|
125 | + return $this->updateMimetypes($updatedMimetypes); |
|
126 | + } |
|
127 | + |
|
128 | + private function introduceLocationTypes() { |
|
129 | + $updatedMimetypes = [ |
|
130 | + 'gpx' => 'application/gpx+xml', |
|
131 | + 'kml' => 'application/vnd.google-earth.kml+xml', |
|
132 | + 'kmz' => 'application/vnd.google-earth.kmz', |
|
133 | + 'tcx' => 'application/vnd.garmin.tcx+xml', |
|
134 | + ]; |
|
135 | + |
|
136 | + return $this->updateMimetypes($updatedMimetypes); |
|
137 | + } |
|
138 | + |
|
139 | + private function introduceInternetShortcutTypes() { |
|
140 | + $updatedMimetypes = [ |
|
141 | + 'url' => 'application/internet-shortcut', |
|
142 | + 'webloc' => 'application/internet-shortcut' |
|
143 | + ]; |
|
144 | + |
|
145 | + return $this->updateMimetypes($updatedMimetypes); |
|
146 | + } |
|
147 | + |
|
148 | + private function introduceStreamingTypes() { |
|
149 | + $updatedMimetypes = [ |
|
150 | + 'm3u' => 'audio/mpegurl', |
|
151 | + 'm3u8' => 'audio/mpegurl', |
|
152 | + 'pls' => 'audio/x-scpls' |
|
153 | + ]; |
|
154 | + |
|
155 | + return $this->updateMimetypes($updatedMimetypes); |
|
156 | + } |
|
157 | + |
|
158 | + private function introduceVisioTypes() { |
|
159 | + $updatedMimetypes = [ |
|
160 | + 'vsdm' => 'application/vnd.visio', |
|
161 | + 'vsdx' => 'application/vnd.visio', |
|
162 | + 'vssm' => 'application/vnd.visio', |
|
163 | + 'vssx' => 'application/vnd.visio', |
|
164 | + 'vstm' => 'application/vnd.visio', |
|
165 | + 'vstx' => 'application/vnd.visio', |
|
166 | + ]; |
|
167 | + |
|
168 | + return $this->updateMimetypes($updatedMimetypes); |
|
169 | + } |
|
170 | + |
|
171 | + private function introduceComicbookTypes() { |
|
172 | + $updatedMimetypes = [ |
|
173 | + 'cb7' => 'application/comicbook+7z', |
|
174 | + 'cba' => 'application/comicbook+ace', |
|
175 | + 'cbr' => 'application/comicbook+rar', |
|
176 | + 'cbt' => 'application/comicbook+tar', |
|
177 | + 'cbtc' => 'application/comicbook+truecrypt', |
|
178 | + 'cbz' => 'application/comicbook+zip', |
|
179 | + ]; |
|
180 | + |
|
181 | + return $this->updateMimetypes($updatedMimetypes); |
|
182 | + } |
|
183 | + |
|
184 | + private function introduceOpenDocumentTemplates() { |
|
185 | + $updatedMimetypes = [ |
|
186 | + 'ott' => 'application/vnd.oasis.opendocument.text-template', |
|
187 | + 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', |
|
188 | + 'otp' => 'application/vnd.oasis.opendocument.presentation-template', |
|
189 | + 'otg' => 'application/vnd.oasis.opendocument.graphics-template', |
|
190 | + ]; |
|
191 | + |
|
192 | + return $this->updateMimetypes($updatedMimetypes); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Fix mime types |
|
197 | + */ |
|
198 | + public function run(IOutput $out) { |
|
199 | + $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); |
|
200 | + |
|
201 | + // NOTE TO DEVELOPERS: when adding new mime types, please make sure to |
|
202 | + // add a version comparison to avoid doing it every time |
|
203 | + |
|
204 | + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.14', '<') && $this->introduceImageTypes()) { |
|
205 | + $out->info('Fixed image mime types'); |
|
206 | + } |
|
207 | + |
|
208 | + if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) { |
|
209 | + $out->info('Fixed windows program mime types'); |
|
210 | + } |
|
211 | + |
|
212 | + if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.0', '<') && $this->introduceLocationTypes()) { |
|
213 | + $out->info('Fixed geospatial mime types'); |
|
214 | + } |
|
215 | + |
|
216 | + if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.3', '<') && $this->introduceInternetShortcutTypes()) { |
|
217 | + $out->info('Fixed internet-shortcut mime types'); |
|
218 | + } |
|
219 | + |
|
220 | + if (version_compare($ocVersionFromBeforeUpdate, '13.0.0.6', '<') && $this->introduceStreamingTypes()) { |
|
221 | + $out->info('Fixed streaming mime types'); |
|
222 | + } |
|
223 | + |
|
224 | + if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.8', '<') && $this->introduceVisioTypes()) { |
|
225 | + $out->info('Fixed visio mime types'); |
|
226 | + } |
|
227 | + |
|
228 | + if (version_compare($ocVersionFromBeforeUpdate, '14.0.0.10', '<') && $this->introduceComicbookTypes()) { |
|
229 | + $out->info('Fixed comicbook mime types'); |
|
230 | + } |
|
231 | + |
|
232 | + if (version_compare($ocVersionFromBeforeUpdate, '20.0.0.5', '<') && $this->introduceOpenDocumentTemplates()) { |
|
233 | + $out->info('Fixed OpenDocument template mime types'); |
|
234 | + } |
|
235 | + } |
|
236 | 236 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | if (empty($this->folderMimeTypeId)) { |
71 | 71 | $query->setParameter('mimetype', 'httpd/unix-directory'); |
72 | 72 | $result = $query->execute(); |
73 | - $this->folderMimeTypeId = (int)$result->fetchColumn(); |
|
73 | + $this->folderMimeTypeId = (int) $result->fetchColumn(); |
|
74 | 74 | $result->closeCursor(); |
75 | 75 | } |
76 | 76 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | // get target mimetype id |
88 | 88 | $query->setParameter('mimetype', $mimetype); |
89 | 89 | $result = $query->execute(); |
90 | - $mimetypeId = (int)$result->fetchColumn(); |
|
90 | + $mimetypeId = (int) $result->fetchColumn(); |
|
91 | 91 | $result->closeCursor(); |
92 | 92 | |
93 | 93 | if (!$mimetypeId) { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | // change mimetype for files with x extension |
101 | 101 | $update->setParameter('mimetype', $mimetypeId) |
102 | - ->setParameter('name', '%' . $this->connection->escapeLikeParameter('.' . $extension)); |
|
102 | + ->setParameter('name', '%'.$this->connection->escapeLikeParameter('.'.$extension)); |
|
103 | 103 | $count += $update->execute(); |
104 | 104 | } |
105 | 105 |