diff --git a/keeweb/lib/Migration/MimeTypeMigration.php b/keeweb/lib/Migration/MimeTypeMigration.php new file mode 100644 index 0000000..c0d5d44 --- /dev/null +++ b/keeweb/lib/Migration/MimeTypeMigration.php @@ -0,0 +1,19 @@ +mimeTypeLoader = $mimeTypeLoader; + } +} diff --git a/keeweb/lib/Migration/RegisterMimeType.php b/keeweb/lib/Migration/RegisterMimeType.php index fbbdb36..b0f739c 100644 --- a/keeweb/lib/Migration/RegisterMimeType.php +++ b/keeweb/lib/Migration/RegisterMimeType.php @@ -6,15 +6,8 @@ use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; -class RegisterMimeType implements IRepairStep +class RegisterMimeType extends MimeTypeMigration { - private $mimeTypeLoader; - - public function __construct(IMimeTypeLoader $mimeTypeLoader) - { - $this->mimeTypeLoader = $mimeTypeLoader; - } - public function getName() { return 'Register MIME type for "application/x-kdbx"'; @@ -22,14 +15,14 @@ public function getName() private function registerForExistingFiles() { - $mimetypeId = $this->mimeTypeLoader->getId('application/x-kdbx'); - $this->mimeTypeLoader->updateFilecache('kdbx', $mimetypeId); + $mimeTypeId = $this->mimeTypeLoader->getId('application/x-kdbx'); + $this->mimeTypeLoader->updateFilecache('kdbx', $mimeTypeId); } private function registerForNewFiles() { $mapping = ['kdbx' => ['application/x-kdbx']]; - $mappingFile = \OC::$configDir . 'mimetypemapping.json'; + $mappingFile = \OC::$configDir . self::CUSTOM_MIMETYPEMAPPING; if (file_exists($mappingFile)) { $existingMapping = json_decode(file_get_contents($mappingFile), true); @@ -43,7 +36,7 @@ private function registerForNewFiles() public function run(IOutput $output) { - $this->logger->info('Registering the mimetype...'); + $output->info('Registering the mimetype...'); // Register the mime type for existing files $this->registerForExistingFiles(); @@ -51,6 +44,6 @@ public function run(IOutput $output) // Register the mime type for new files $this->registerForNewFiles(); - $this->logger->info('The mimetype was successfully registered.'); + $output->info('The mimetype was successfully registered.'); } } diff --git a/keeweb/lib/Migration/UnregisterMimeType.php b/keeweb/lib/Migration/UnregisterMimeType.php index a544a1f..bfd7ea1 100644 --- a/keeweb/lib/Migration/UnregisterMimeType.php +++ b/keeweb/lib/Migration/UnregisterMimeType.php @@ -6,29 +6,22 @@ use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; -class UnregisterMimeType implements IRepairStep +class UnregisterMimeType extends MimeTypeMigration { - private $mimeTypeLoader; - - public function __construct(IMimeTypeLoader $mimeTypeLoader) - { - $this->mimeTypeLoader = $mimeTypeLoader; - } - public function getName() { return 'Unregister MIME type for "application/x-kdbx"'; } - private function registerForExistingFiles() + private function unregisterForExistingFiles() { - $mimetypeId = $this->mimeTypeLoader->getId('application/octet-stream'); - $this->mimeTypeLoader->updateFilecache('kdbx', $mimetypeId); + $mimeTypeId = $this->mimeTypeLoader->getId('application/octet-stream'); + $this->mimeTypeLoader->updateFilecache('kdbx', $mimeTypeId); } - private function registerForNewFiles() + private function unregisterForNewFiles() { - $mappingFile = \OC::$configDir . 'mimetypemapping.json'; + $mappingFile = \OC::$configDir . self::CUSTOM_MIMETYPEMAPPING; if (file_exists($mappingFile)) { $mapping = json_decode(file_get_contents($mappingFile), true); @@ -43,14 +36,14 @@ private function registerForNewFiles() public function run(IOutput $output) { - $this->logger->info('Unregistering the mimetype...'); + $output->info('Unregistering the mimetype...'); // Register the mime type for existing files - $this->registerForExistingFiles(); + $this->unregisterForExistingFiles(); // Register the mime type for new files - $this->registerForNewFiles(); + $this->unregisterForNewFiles(); - $this->logger->info('The mimetype was successfully unregistered.'); + $output->info('The mimetype was successfully unregistered.'); } }