diff options
-rw-r--r-- | appinfo/info.xml | 5 | ||||
-rw-r--r-- | assets/presentation.otp | bin | 13690 -> 15207 bytes | |||
-rw-r--r-- | lib/Migration/UpdateEmptyTemplates.php | 60 | ||||
-rw-r--r-- | lib/TemplateManager.php | 35 |
4 files changed, 92 insertions, 8 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml index ee501d35..dfe86799 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -30,6 +30,11 @@ <background-jobs> <job>OCA\Richdocuments\Backgroundjobs\ObtainCapabilities</job> </background-jobs> + <repair-steps> + <post-migration> + <step>OCA\Richdocuments\Migration\UpdateEmptyTemplates</step> + </post-migration> + </repair-steps> <settings> <admin>OCA\Richdocuments\Settings\Admin</admin> <admin-section>OCA\Richdocuments\Settings\Section</admin-section> diff --git a/assets/presentation.otp b/assets/presentation.otp Binary files differindex 600baf0b..8ca7e1a7 100644 --- a/assets/presentation.otp +++ b/assets/presentation.otp diff --git a/lib/Migration/UpdateEmptyTemplates.php b/lib/Migration/UpdateEmptyTemplates.php new file mode 100644 index 00000000..84f182f8 --- /dev/null +++ b/lib/Migration/UpdateEmptyTemplates.php @@ -0,0 +1,60 @@ +<?php +/** + * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +namespace OCA\RichDocuments\Migration; + +use OCA\Richdocuments\TemplateManager; +use OCP\Migration\IRepairStep; +use OCP\Migration\IOutput; + +class UpdateEmptyTemplates implements IRepairStep { + + + /** @var TemplateManager */ + private $templateManager; + + public function __construct(TemplateManager $templateManager) { + $this->templateManager = $templateManager; + } + + /* + * @inheritdoc + */ + public function getName() { + return 'Update empty template files'; + } + + /** + * @inheritdoc + */ + public function run(IOutput $output) { + try { + $this->templateManager->updateEmptyTemplates(); + } catch (\Exception $e) { + $output->warning('Failed to update templates'); + $output->warning($e->getMessage()); + $output->warning($e->getTraceAsString()); + } + } +} diff --git a/lib/TemplateManager.php b/lib/TemplateManager.php index ecdb88a5..d7bc0d1b 100644 --- a/lib/TemplateManager.php +++ b/lib/TemplateManager.php @@ -26,6 +26,7 @@ namespace OCA\Richdocuments; use OCP\Files\File; use OCP\Files\Folder; +use OCP\Files\IAppData; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; @@ -112,7 +113,7 @@ class TemplateManager { public function __construct($appName, $userId, IConfig $config, - Factory $appDataFactory, + IAppData $appData, IURLGenerator $urlGenerator, IRootFolder $rootFolder, IL10N $l) { @@ -122,24 +123,29 @@ class TemplateManager { $this->rootFolder = $rootFolder; $this->urlGenerator = $urlGenerator; + + $this->appData = $appData; + $this->createAppDataFolders(); + + $this->l = $l; + } + + private function createAppDataFolders() { /* * Init the appdata folder * We need an actual folder for the fileid and previews. * TODO: Fix this at some point */ - $appData = $appDataFactory->get($appName); try { - $appData->getFolder('templates'); + $this->appData->getFolder('templates'); } catch (NotFoundException $e) { - $appData->newFolder('templates'); + $this->appData->newFolder('templates'); } try { - $appData->getFolder('empty_templates'); + $this->appData->getFolder('empty_templates'); } catch (NotFoundException $e) { - $appData->newFolder('empty_templates'); + $this->appData->newFolder('empty_templates'); } - - $this->l = $l; } public function setUserId($userId) { @@ -225,6 +231,19 @@ class TemplateManager { } /** + * Remove empty_templates in appdata and recreate it from the apps templates + */ + public function updateEmptyTemplates() { + try { + $folder = $this->getEmptyTemplateDir(); + $folder->delete(); + } catch (NotFoundException $e) { + } + $this->appData->newFolder('empty_templates'); + $this->getEmpty(); + } + + /** * Get all global templates * * @return File[] |