diff --git a/appinfo/info.xml b/appinfo/info.xml index 20feb659e0..6686ed11d4 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -31,10 +31,16 @@ You can also edit your documents off-line with the Collabora Office app from the OCA\Richdocuments\Backgroundjobs\ObtainCapabilities OCA\Richdocuments\Backgroundjobs\Cleanup + + + OCA\Richdocuments\Migration\InstallDefaultFonts + + OCA\Richdocuments\Command\ActivateConfig OCA\Richdocuments\Command\ConvertToBigInt OCA\Richdocuments\Command\UpdateEmptyTemplates + OCA\Richdocuments\Command\InstallDefaultFonts OCA\Richdocuments\Settings\Admin diff --git a/assets/fonts/AmaticSC-Regular.ttf b/assets/fonts/AmaticSC-Regular.ttf new file mode 100644 index 0000000000..b860368bec Binary files /dev/null and b/assets/fonts/AmaticSC-Regular.ttf differ diff --git a/composer/composer/autoload_classmap.php b/composer/composer/autoload_classmap.php index b8bd7aa4bc..0e047b71eb 100644 --- a/composer/composer/autoload_classmap.php +++ b/composer/composer/autoload_classmap.php @@ -14,6 +14,7 @@ 'OCA\\Richdocuments\\Capabilities' => $baseDir . '/../lib/Capabilities.php', 'OCA\\Richdocuments\\Command\\ActivateConfig' => $baseDir . '/../lib/Command/ActivateConfig.php', 'OCA\\Richdocuments\\Command\\ConvertToBigInt' => $baseDir . '/../lib/Command/ConvertToBigInt.php', + 'OCA\\Richdocuments\\Command\\InstallDefaultFonts' => $baseDir . '/../lib/Command/InstallDefaultFonts.php', 'OCA\\Richdocuments\\Command\\UpdateEmptyTemplates' => $baseDir . '/../lib/Command/UpdateEmptyTemplates.php', 'OCA\\Richdocuments\\Controller\\AssetsController' => $baseDir . '/../lib/Controller/AssetsController.php', 'OCA\\Richdocuments\\Controller\\DirectViewController' => $baseDir . '/../lib/Controller/DirectViewController.php', @@ -45,6 +46,7 @@ 'OCA\\Richdocuments\\Listener\\ReferenceListener' => $baseDir . '/../lib/Listener/ReferenceListener.php', 'OCA\\Richdocuments\\Listener\\ShareLinkListener' => $baseDir . '/../lib/Listener/ShareLinkListener.php', 'OCA\\Richdocuments\\Middleware\\WOPIMiddleware' => $baseDir . '/../lib/Middleware/WOPIMiddleware.php', + 'OCA\\Richdocuments\\Migration\\InstallDefaultFonts' => $baseDir . '/../lib/Migration/InstallDefaultFonts.php', 'OCA\\Richdocuments\\Migration\\Version2060Date20200302131958' => $baseDir . '/../lib/Migration/Version2060Date20200302131958.php', 'OCA\\Richdocuments\\Migration\\Version2060Date20200302132145' => $baseDir . '/../lib/Migration/Version2060Date20200302132145.php', 'OCA\\Richdocuments\\Migration\\Version30704Date20200626072306' => $baseDir . '/../lib/Migration/Version30704Date20200626072306.php', diff --git a/composer/composer/autoload_static.php b/composer/composer/autoload_static.php index aea309c791..311c882df0 100644 --- a/composer/composer/autoload_static.php +++ b/composer/composer/autoload_static.php @@ -29,6 +29,7 @@ class ComposerStaticInitRichdocuments 'OCA\\Richdocuments\\Capabilities' => __DIR__ . '/..' . '/../lib/Capabilities.php', 'OCA\\Richdocuments\\Command\\ActivateConfig' => __DIR__ . '/..' . '/../lib/Command/ActivateConfig.php', 'OCA\\Richdocuments\\Command\\ConvertToBigInt' => __DIR__ . '/..' . '/../lib/Command/ConvertToBigInt.php', + 'OCA\\Richdocuments\\Command\\InstallDefaultFonts' => __DIR__ . '/..' . '/../lib/Command/InstallDefaultFonts.php', 'OCA\\Richdocuments\\Command\\UpdateEmptyTemplates' => __DIR__ . '/..' . '/../lib/Command/UpdateEmptyTemplates.php', 'OCA\\Richdocuments\\Controller\\AssetsController' => __DIR__ . '/..' . '/../lib/Controller/AssetsController.php', 'OCA\\Richdocuments\\Controller\\DirectViewController' => __DIR__ . '/..' . '/../lib/Controller/DirectViewController.php', @@ -60,6 +61,7 @@ class ComposerStaticInitRichdocuments 'OCA\\Richdocuments\\Listener\\ReferenceListener' => __DIR__ . '/..' . '/../lib/Listener/ReferenceListener.php', 'OCA\\Richdocuments\\Listener\\ShareLinkListener' => __DIR__ . '/..' . '/../lib/Listener/ShareLinkListener.php', 'OCA\\Richdocuments\\Middleware\\WOPIMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/WOPIMiddleware.php', + 'OCA\\Richdocuments\\Migration\\InstallDefaultFonts' => __DIR__ . '/..' . '/../lib/Migration/InstallDefaultFonts.php', 'OCA\\Richdocuments\\Migration\\Version2060Date20200302131958' => __DIR__ . '/..' . '/../lib/Migration/Version2060Date20200302131958.php', 'OCA\\Richdocuments\\Migration\\Version2060Date20200302132145' => __DIR__ . '/..' . '/../lib/Migration/Version2060Date20200302132145.php', 'OCA\\Richdocuments\\Migration\\Version30704Date20200626072306' => __DIR__ . '/..' . '/../lib/Migration/Version30704Date20200626072306.php', diff --git a/cypress/e2e/settings.spec.js b/cypress/e2e/settings.spec.js index 3adefbb183..6771523cb5 100644 --- a/cypress/e2e/settings.spec.js +++ b/cypress/e2e/settings.spec.js @@ -21,6 +21,7 @@ import { User } from '@nextcloud/cypress' const usesHttps = Cypress.env('baseUrl').substr(0, 5) === 'https' const collaboraUrl = Cypress.env('collaboraUrl') +const defaultFonts = ['AmaticSC-Regular.ttf'] describe('Office admin settings', function() { @@ -77,6 +78,13 @@ describe('Office admin settings', function() { .scrollIntoView() .should('be.visible') + cy.get('#font-settings') + .scrollIntoView() + .should('be.visible') + defaultFonts.forEach(font => { + cy.get('.settings-entry.font-list-settings').contains(font) + }) + // FIXME: Template settings only get visible after reload cy.reload() cy.get('#richdocuments-templates') diff --git a/lib/Command/InstallDefaultFonts.php b/lib/Command/InstallDefaultFonts.php new file mode 100644 index 0000000000..2a1416ed91 --- /dev/null +++ b/lib/Command/InstallDefaultFonts.php @@ -0,0 +1,32 @@ +setName('richdocuments:install-fonts') + ->setDescription('Install default fonts'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + try { + $this->fontService->installDefaultFonts(); + return 0; + } catch (\Exception $e) { + $output->writeln('Failed to install default fonts'); + $output->writeln($e->getMessage()); + $output->writeln($e->getTraceAsString()); + return 1; + } + } +} diff --git a/lib/Migration/InstallDefaultFonts.php b/lib/Migration/InstallDefaultFonts.php new file mode 100644 index 0000000000..573051d8d8 --- /dev/null +++ b/lib/Migration/InstallDefaultFonts.php @@ -0,0 +1,27 @@ +config->getAppValue('richdocuments', 'installed_version'); + + if (!empty($appVersion) && version_compare($appVersion, '8.2.2') < 1) { + return; + } + + $this->fontService->installDefaultFonts(); + } +} diff --git a/lib/Service/FontService.php b/lib/Service/FontService.php index 67c168bd91..e41d97721b 100644 --- a/lib/Service/FontService.php +++ b/lib/Service/FontService.php @@ -23,6 +23,7 @@ namespace OCA\Richdocuments\Service; +use Exception; use OCA\Richdocuments\AppInfo\Application; use OCP\Files\IAppData; use OCP\Files\NotFoundException; @@ -242,4 +243,41 @@ private function generateFontOverview(ISimpleFile $fontFile): void { // in the UI and display a fallback message } } + + /** + * @throws Exception + */ + public function installDefaultFonts(): void { + $dirPath = __DIR__ . '/../../assets/fonts'; + + if (!is_dir($dirPath)) { + throw new Exception("Directory \"$dirPath\" does not exist!"); + } + + $handle = opendir($dirPath); + + if (!$handle) { + throw new Exception("Failed opening directory \"$dirPath\"!"); + } + + while (false !== ($fileName = readdir($handle))) { + if ($fileName === '.' || $fileName === '..') { + continue; + } + + $filePath = $dirPath . '/' . $fileName; + + if (!is_file($filePath)) { + continue; + } + + $fileHandle = fopen($filePath, 'r'); + + if (!$fileHandle) { + continue; + } + + $this->uploadFontFile($fileName, $fileHandle); + } + } } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index c55752e530..6297e9bbba 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -33,6 +33,11 @@ Command + + + Command + + getId()]]>