Skip to content

Commit

Permalink
feat: add repair step to install default fonts on installation
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Trovic <[email protected]>
  • Loading branch information
luka-nextcloud committed Dec 7, 2023
1 parent 9eea957 commit 406e16b
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 0 deletions.
6 changes: 6 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ You can also edit your documents off-line with the Collabora Office app from the
<job>OCA\Richdocuments\Backgroundjobs\ObtainCapabilities</job>
<job>OCA\Richdocuments\Backgroundjobs\Cleanup</job>
</background-jobs>
<repair-steps>
<install>
<step>OCA\Richdocuments\Migration\InstallDefaultFonts</step>
</install>
</repair-steps>
<commands>
<command>OCA\Richdocuments\Command\ActivateConfig</command>
<command>OCA\Richdocuments\Command\ConvertToBigInt</command>
<command>OCA\Richdocuments\Command\UpdateEmptyTemplates</command>
<command>OCA\Richdocuments\Command\InstallDefaultFonts</command>
</commands>
<settings>
<admin>OCA\Richdocuments\Settings\Admin</admin>
Expand Down
Binary file added assets/fonts/AmaticSC-Regular.ttf
Binary file not shown.
2 changes: 2 additions & 0 deletions composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions cypress/e2e/settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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')
Expand Down
32 changes: 32 additions & 0 deletions lib/Command/InstallDefaultFonts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace OCA\Richdocuments\Command;

use OCA\Richdocuments\Service\FontService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class InstallDefaultFonts extends Command {
public function __construct(private FontService $fontService) {
parent::__construct();
}

protected function configure() {
$this
->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('<error>Failed to install default fonts</error>');
$output->writeln($e->getMessage());
$output->writeln($e->getTraceAsString());
return 1;
}
}
}
27 changes: 27 additions & 0 deletions lib/Migration/InstallDefaultFonts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace OCA\Richdocuments\Migration;

use OCA\Richdocuments\Service\FontService;
use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class InstallDefaultFonts implements IRepairStep {
public function __construct(private IConfig $config, private FontService $fontService) {
}

public function getName(): string {
return 'Install default fonts';
}

public function run(IOutput $output): void {
$appVersion = $this->config->getAppValue('richdocuments', 'installed_version');

if (!empty($appVersion) && version_compare($appVersion, '8.2.2') < 1) {
return;
}

$this->fontService->installDefaultFonts();
}
}
38 changes: 38 additions & 0 deletions lib/Service/FontService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Richdocuments\Service;

use Exception;
use OCA\Richdocuments\AppInfo\Application;
use OCP\Files\IAppData;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -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);
}
}
}
5 changes: 5 additions & 0 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<code>Command</code>
</UndefinedClass>
</file>
<file src="lib/Command/InstallDefaultFonts.php">
<UndefinedClass>
<code>Command</code>
</UndefinedClass>
</file>
<file src="lib/Controller/DirectViewController.php">
<InvalidScalarArgument>
<code><![CDATA[$item->getId()]]></code>
Expand Down

0 comments on commit 406e16b

Please sign in to comment.