Skip to content

Commit 078f0c8

Browse files
authored
Merge pull request #288 from os2display/feature/upgrade-guide
Added command to migrate config.json files to .env variables
2 parents ee02522 + 49a3891 commit 078f0c8

File tree

7 files changed

+160
-39
lines changed

7 files changed

+160
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
2121
* Removed admin/access-config.json fetch
2222
* Aligned with v. 2.5.2.
2323
* Removed themes.
24+
* Added command to migrate config.json files.
2425

2526
### NB! Prior to 3.x the project was split into separate repositories
2627

README.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
## Table of Contents
44

5-
1. [Description](#description)
6-
2. [ADR - Architectural Decision Records](#adr---architectural-decision-records)
7-
3. [Technologies](#technologies)
8-
4. [Versioning](#versioning)
9-
5. [Taskfile](#taskfile)
10-
6. [Development setup](#development-setup)
11-
7. [Production setup](#production-setup)
12-
8. [Coding standards](#coding-standards)
13-
9. [Stateless](#stateless)
14-
10. [OIDC providers](#oidc-providers)
15-
11. [JWT Auth](#jwt-auth)
16-
12. [Test](#test)
17-
13. [API specification and generated code](#api-specification-and-generated-code)
18-
14. [Configuration](#configuration)
19-
15. [Rest API & Relationships](#rest-api--relationships)
20-
16. [Error codes in the Client](#error-codes-in-the-client)
21-
17. [Preview mode in the Client](#preview-mode-in-the-client)
22-
18. [Feeds](#feeds)
23-
19. [Custom Templates](#custom-templates)
24-
20. [Upgrade Guide](#upgrade-guide)
5+
- [Description](#description)
6+
- [ADR - Architectural Decision Records](#adr---architectural-decision-records)
7+
- [Technologies](#technologies)
8+
- [Versioning](#versioning)
9+
- [Taskfile](#taskfile)
10+
- [Development setup](#development-setup)
11+
- [Production setup](#production-setup)
12+
- [Coding standards](#coding-standards)
13+
- [Stateless](#stateless)
14+
- [OIDC providers](#oidc-providers)
15+
- [JWT Auth](#jwt-auth)
16+
- [Test](#test)
17+
- [API specification and generated code](#api-specification-and-generated-code)
18+
- [Configuration](#configuration)
19+
- [Rest API & Relationships](#rest-api--relationships)
20+
- [Error codes in the Client](#error-codes-in-the-client)
21+
- [Preview mode in the Client](#preview-mode-in-the-client)
22+
- [Feeds](#feeds)
23+
- [Custom Templates](#custom-templates)
24+
- [Upgrade Guide](#upgrade-guide)
2525

2626
## Description
2727

@@ -586,7 +586,9 @@ custom themes.
586586

587587
## Custom Templates
588588

589-
It is possible to include your own templates in your installation.
589+
OS2Display ships with some standard templates. These are located in `assets/shared/templates`.
590+
591+
It is possible to include custom templates in your installation.
590592

591593
### Location
592594

@@ -620,6 +622,9 @@ The `.jsx` should expose the following functions:
620622

621623
For an example of a custom template see `assets/shared/custom-templates-example/`.
622624

625+
In production, these custom templates need to be built together with the normal templates with the `npm run build`
626+
command.
627+
623628
### Contributing template
624629

625630
If you think the template could be used by other, consider contributing the template to the project as a pull request.

UPGRADE.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Upgrade Guide
22

3-
## 2.x -> 3.0.0
3+
## Table of contents
44

5-
The upgrade from 2.x to 3.0.0 of OS2Display introduces a major change to the project.
5+
- ### [2.x -> 3.0](#2x---30)
6+
7+
## 2.x -> 3.0
8+
9+
The upgrade from 2.x to 3.0 of OS2Display introduces a major change to the project.
610
The Admin and Client apps and the Templates that previously existed in separate repositories from the API,
711
have been included in the API repository.
812
The API repository has been renamed from <https://github.com/os2display/display-api-service> to
@@ -13,6 +17,17 @@ Because of these changes, it will be necessary to adjust the server setup to mat
1317

1418
### Upgrade steps
1519

20+
#### 0 - Convert external templates to custom templates
21+
22+
Instead of loading javascript for templates from possibly external urls we have made the change to only include
23+
templates that are a part of the code. Standard templates are now located in `assets/shared/templates/`.
24+
Custom templates are located in `assets/shared/custom-templates`.
25+
26+
Because of this change, external templates in 2.x will have to be converted to custom templates.
27+
Custom templates are documented in the [README.md#custom-templates](README.md#custom-templates).
28+
29+
The important thing is that the `id` of the template should remain the same when converted to a custom template.
30+
1631
#### 1 - Upgrade the API to the latest version of 2.x
1732

1833
#### 2 - Configure the following environment variables in `.env.local`
@@ -40,6 +55,13 @@ CLIENT_DEBUG=false
4055
These values were previously added to Admin and Client: `/public/config.json`.
4156
See [README.md](./README.md) for a description of the configuration options.
4257

58+
You can convert your previous config.json files to .env config with the following commands:
59+
60+
```shell
61+
docker compose exec phpfpm bin/console app:utils:convert-config-json-to-env --type=admin path/to/admin/config.json
62+
docker compose exec phpfpm bin/console app:utils:convert-config-json-to-env --type=client path/to/client/config.json
63+
```
64+
4365
#### 3 - Run doctrine migrate
4466

4567
```shell

composer.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,6 @@
131131
"fixtures-load": [
132132
"bin/console hautelook:fixtures:load --no-interaction"
133133
],
134-
"prepare-code": [
135-
"bin/console doctrine:schema:validate",
136-
"@coding-standards-apply",
137-
"vendor/bin/rector",
138-
"vendor/bin/psalm --no-cache",
139-
"@test-setup",
140-
"@test"
141-
],
142134
"test": [
143135
"vendor/bin/phpunit --stop-on-failure"
144136
],

src/Command/UpdateCommand.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
)]
2020
class UpdateCommand extends Command
2121
{
22-
private TemplateService $templateService;
23-
24-
public function __construct(TemplateService $templateService, ?string $name = null)
25-
{
22+
public function __construct(
23+
private readonly TemplateService $templateService,
24+
?string $name = null,
25+
) {
2626
parent::__construct($name);
27-
$this->templateService = $templateService;
2827
}
2928

3029
final protected function execute(InputInterface $input, OutputInterface $output): int
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Command\Utils;
6+
7+
use Symfony\Component\Console\Attribute\AsCommand;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputArgument;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
use Symfony\Component\Console\Style\SymfonyStyle;
14+
15+
#[AsCommand(
16+
name: 'app:utils:convert-config-json-to-env',
17+
description: 'Converts a config json file (admin/client) from 2.x to .env variables used in 3.x',
18+
)]
19+
class ConvertConfigJsonToEnvCommand extends Command
20+
{
21+
protected function configure(): void
22+
{
23+
$this->addArgument('filepath', InputArgument::REQUIRED, 'Path to the file or URL to convert');
24+
$this->addOption('type', 't', InputOption::VALUE_REQUIRED, 'Type of the config (admin or client).', null, ['admin', 'client']);
25+
}
26+
27+
final protected function execute(InputInterface $input, OutputInterface $output): int
28+
{
29+
$io = new SymfonyStyle($input, $output);
30+
31+
$type = $input->getOption('type');
32+
33+
if (!in_array($type, ['admin', 'client'])) {
34+
$io->error('Invalid type');
35+
36+
return Command::INVALID;
37+
}
38+
39+
try {
40+
$content = file_get_contents($input->getArgument('filepath'));
41+
42+
if (false === $content) {
43+
throw new \Exception('Error reading file');
44+
}
45+
46+
$config = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
47+
} catch (\Exception|\JsonException $e) {
48+
$io->error($e->getMessage());
49+
50+
return Command::INVALID;
51+
}
52+
53+
if ('admin' === $type) {
54+
$io->success('Insert the following lines in .env.local');
55+
56+
$rejseplanenApiKey = $config['rejseplanenApiKey'] ?? null;
57+
$showScreenStatus = $config['showScreenStatus'] ?? null;
58+
$touchButtonRegions = $config['touchButtonRegions'] ?? null;
59+
$loginMethods = $config['loginMethods'] ?? null;
60+
61+
if (null !== $loginMethods) {
62+
// Remove enabled field since this is unused in v3.
63+
foreach ($loginMethods as &$method) {
64+
unset($method['enabled']);
65+
}
66+
}
67+
68+
$io->writeln('###> Admin configuration ###');
69+
null !== $rejseplanenApiKey && $io->writeln('ADMIN_REJSEPLANEN_APIKEY="'.$rejseplanenApiKey.'"');
70+
null !== $showScreenStatus && $io->writeln('ADMIN_SHOW_SCREEN_STATUS='.var_export($showScreenStatus, true));
71+
null !== $touchButtonRegions && $io->writeln('ADMIN_TOUCH_BUTTON_REGIONS='.var_export($touchButtonRegions, true));
72+
null !== $loginMethods && $io->writeln("ADMIN_LOGIN_METHODS='".json_encode($loginMethods)."'");
73+
// This is a conversion from an url to boolean value. If the url is not empty, it is interpreted as true.
74+
!empty($config['previewClient']) && $io->writeln('ADMIN_ENHANCED_PREVIEW=true');
75+
$io->writeln('###< Admin configuration ###');
76+
} elseif ('client' === $type) {
77+
$io->success('Insert the following lines in .env.local');
78+
79+
$loginCheckTimeout = $config['loginCheckTimeout'] ?? null;
80+
$refreshTokenTimeout = $config['refreshTokenTimeout'] ?? null;
81+
$releaseTimestampIntervalTimeout = $config['releaseTimestampIntervalTimeout'] ?? null;
82+
$schedulingInterval = $config['schedulingInterval'] ?? null;
83+
$pullStrategyInterval = $config['dataStrategy']['config']['interval'] ?? null;
84+
$debug = $config['debug'] ?? null;
85+
86+
$colorScheme = $config['colorScheme'] ?? null;
87+
$colorSchemeValue = null !== $colorScheme ? "'".json_encode($colorScheme)."'" : null;
88+
89+
$io->writeln('###> Client configuration ###');
90+
null !== $loginCheckTimeout && $io->writeln('CLIENT_LOGIN_CHECK_TIMEOUT='.$loginCheckTimeout);
91+
null !== $refreshTokenTimeout && $io->writeln('CLIENT_REFRESH_TOKEN_TIMEOUT='.$refreshTokenTimeout);
92+
null !== $releaseTimestampIntervalTimeout && $io->writeln('CLIENT_RELEASE_TIMESTAMP_INTERVAL_TIMEOUT='.$releaseTimestampIntervalTimeout);
93+
null !== $schedulingInterval && $io->writeln('CLIENT_SCHEDULING_INTERVAL='.$schedulingInterval);
94+
null !== $pullStrategyInterval && $io->writeln('CLIENT_PULL_STRATEGY_INTERVAL='.$pullStrategyInterval);
95+
null !== $colorSchemeValue && $io->writeln('CLIENT_COLOR_SCHEME='.$colorSchemeValue);
96+
null !== $debug && $io->writeln('CLIENT_DEBUG=true');
97+
$io->writeln('###< Client configuration ###');
98+
}
99+
100+
return Command::SUCCESS;
101+
}
102+
}

src/Command/GenerateUlid.php renamed to src/Command/Utils/GenerateUlid.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Command;
5+
namespace App\Command\Utils;
66

77
use Symfony\Component\Console\Attribute\AsCommand;
88
use Symfony\Component\Console\Command\Command;
@@ -12,8 +12,8 @@
1212
use Symfony\Component\Uid\Ulid;
1313

1414
#[AsCommand(
15-
name: 'app:ulid:generate',
16-
description: 'Generate a new ULID',
15+
name: 'app:utils:generate-ulid',
16+
description: 'Generate a new ULID.',
1717
)]
1818
class GenerateUlid extends Command
1919
{

0 commit comments

Comments
 (0)