Skip to content

Commit

Permalink
NEXT-24090 - Add welcome page
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Feb 22, 2023
1 parent eac31d8 commit 10a21d8
Show file tree
Hide file tree
Showing 30 changed files with 770 additions and 140 deletions.
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"twig/intl-extra": "^3.4",
"twig/string-extra": "^3.4",
"twig/twig": "~3.4.3",
"zircote/swagger-php": "~4.5.1"
"zircote/swagger-php": "~4.5.1 || ~3"
},
"require-dev": {
"ext-tokenizer": "*",
Expand Down Expand Up @@ -343,14 +343,17 @@
"@init:e2e",
"@e2e:prepare"
],
"e2e:recovery:open": [
"Composer\\Config::disableProcessTimeout",
"e2e:recovery:start": [
"@putenv SW_RECOVERY_NEXT_VERSION=6.5.99.9",
"@putenv CYPRESS_SKIP_INIT=1",
"symfony local:server:stop --dir=shop",
"symfony local:server:stop --dir=tests/e2e/update-api-mock",
"APP_URL=${INSTALL_URL-${CYPRESS_baseUrl-http://localhost:8000}} symfony local:server:start --dir=shop --port=8050 -d",
"symfony local:server:start --dir=tests/e2e/update-api-mock --port=8060 -d",
"symfony local:server:start --dir=tests/e2e/update-api-mock --port=8060 -d"
],
"e2e:recovery:open": [
"Composer\\Config::disableProcessTimeout",
"@e2e:recovery:start",
"export CYPRESS_baseUrl=${INSTALL_URL-${CYPRESS_baseUrl-http://localhost:8000}}; export APP_ENV=e2e; export CYPRESS_localUsage=1; export CYPRESS_shopwareRoot=\"$PWD\"; cd tests/e2e; export PATH=\"$PWD/node_modules/.bin/:$PATH\"; \"$CYPRESS_shopwareRoot\"/bin/exec-with-env cypress open"
],
"e2e:recovery:setup": [
Expand Down
9 changes: 8 additions & 1 deletion devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,17 @@
# General cypress
env.CYPRESS_baseUrl = lib.mkDefault "http://localhost:8000";

# Installer testing
# Installer/Updater testing
env.INSTALL_URL = lib.mkDefault "http://localhost:8050";
env.CYPRESS_dbHost = lib.mkDefault "localhost";
env.CYPRESS_dbUser = lib.mkDefault "shopware";
env.CYPRESS_dbPassword = lib.mkDefault "shopware";
env.CYPRESS_dbName = lib.mkDefault "shopware";

scripts.build-updater.exec = ''
${pkgs.phpPackages.box}/bin/box compile -d src/WebRecovery
mv src/WebRecovery/shopware-recovery.phar.php shop/public/shopware-recovery.phar.php
'';

scripts.watch-updater.exec = "${pkgs.watchexec}/bin/watchexec -i src/WebRecovery/shopware-recovery.phar.php -eyaml,php,js build-updater";
}
7 changes: 6 additions & 1 deletion src/WebRecovery/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"symfony/console": "6.2.*",
"symfony/dotenv": "6.2.*",
"symfony/framework-bundle": "6.2.*",
"symfony/http-client": "^6.2",
"symfony/process": "^6.2",
"symfony/translation": "^6.2",
"symfony/twig-bundle": "^6.2",
"symfony/http-client": "^6.2",
"symfony/yaml": "6.2.*",
"twig/twig": "^3.4"
},
Expand Down Expand Up @@ -61,6 +62,10 @@
"wget -q https://github.com/box-project/box/releases/download/4.2.0/box.phar -O box.phar",
"@php -d phar.readonly=0 box.phar compile",
"rm box.phar"
],
"build-phar-move": [
"@build-phar",
"mv shopware-web-recovery.phar shopware-web-recovery"
]
},
"extra": {
Expand Down
100 changes: 99 additions & 1 deletion src/WebRecovery/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions src/WebRecovery/src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,15 @@

namespace App\Controller;

use App\Services\RecoveryManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class IndexController extends AbstractController
{
public function __construct(private readonly RecoveryManager $recoveryManager)
{
}

#[Route('/', name: 'index')]
#[Route('/', name: 'index', defaults: ['step' => 0])]
public function index(): Response
{
try {
$this->recoveryManager->getShopwareLocation();

return $this->redirectToRoute('update');
} catch (\RuntimeException $e) {
return $this->redirectToRoute('install');
}
return $this->render('index.html.twig');
}
}
10 changes: 6 additions & 4 deletions src/WebRecovery/src/Controller/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
) {
}

#[Route('/install', name: 'install')]
#[Route('/install', name: 'install', defaults: ['step' => 2])]
public function index(): Response
{
return $this->render('install.html.twig');
Expand All @@ -29,10 +29,12 @@ public function index(): Response
#[Route('/install/_run', name: 'install_run', methods: ['POST'])]
public function run(Request $request): StreamedResponse
{
$finish = function (Process $process) use ($request): void {
$folder = $request->query->get('folder', 'shopware');

$finish = function (Process $process) use ($request, $folder): void {
echo json_encode([
'success' => $process->isSuccessful(),
'newLocation' => $request->getBasePath() . '/shopware/public/',
'newLocation' => $request->getBasePath() . '/' . $folder . '/public/',
]);
};

Expand All @@ -45,7 +47,7 @@ public function run(Request $request): StreamedResponse
'--no-interaction',
'--no-ansi',
'-v',
'shopware',
$folder,
], $finish);
}
}
16 changes: 13 additions & 3 deletions src/WebRecovery/src/Controller/PhpConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,38 @@
namespace App\Controller;

use App\Services\PhpBinaryFinder;
use App\Services\RecoveryManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class PhpConfigController extends AbstractController
{
public function __construct(private readonly PhpBinaryFinder $binaryFinder)
{
public function __construct(
private readonly PhpBinaryFinder $binaryFinder,
private readonly RecoveryManager $recoveryManager
) {
}

#[Route('/configure', name: 'configure', defaults: ['step' => 1])]
public function index(Request $request): Response
{
try {
$shopwareLocation = $this->recoveryManager->getShopwareLocation();
} catch (\RuntimeException $e) {
$shopwareLocation = null;
}

if ($phpBinary = $request->request->get('phpBinary')) {
$request->getSession()->set('phpBinary', $phpBinary);

return $this->redirectToRoute('index');
return $this->redirectToRoute($shopwareLocation === null ? 'install' : 'update');
}

return $this->render('php_config.html.twig', [
'phpBinary' => $request->getSession()->get('phpBinary', $this->binaryFinder->find()),
'shopwareLocation' => $shopwareLocation,
]);
}
}
65 changes: 65 additions & 0 deletions src/WebRecovery/src/Listener/InstallerLocaleListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php declare(strict_types=1);

namespace App\Listener;

use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\RequestEvent;

/**
* @package core
*
* @internal
*/
class InstallerLocaleListener
{
public const FALLBACK_LOCALE = 'en';

/**
* @var list<string>
*/
private array $installerLanguages = ['de', 'en'];

#[AsEventListener(RequestEvent::class, priority: 15)]
public function __invoke(RequestEvent $event): void
{
$request = $event->getRequest();

$locale = $this->detectLanguage($request);
$request->attributes->set('_locale', $locale);
$request->setLocale($locale);
}

private function detectLanguage(Request $request): string
{
$session = $request->getSession();

// language is changed
if ($request->query->has('language') && \in_array((string) $request->query->get('language'), $this->installerLanguages, true)) {
$session->set('language', (string) $request->query->get('language'));

return (string) $request->query->get('language');
}

// language was already set
if ($session->has('language') && \in_array((string) $session->get('language'), $this->installerLanguages, true)) {
return (string) $session->get('language');
}

// get initial language from browser header
if ($request->headers->has('HTTP_ACCEPT_LANGUAGE')) {
$browserLanguage = explode(',', $request->headers->get('HTTP_ACCEPT_LANGUAGE', ''));
$browserLanguage = mb_strtolower(mb_substr($browserLanguage[0], 0, 2));

if (\in_array($browserLanguage, $this->installerLanguages, true)) {
$session->set('language', $browserLanguage);

return $browserLanguage;
}
}

$session->set('language', self::FALLBACK_LOCALE);

return self::FALLBACK_LOCALE;
}
}
2 changes: 1 addition & 1 deletion src/WebRecovery/src/Listener/PhpConfigForcerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __invoke(RequestEvent $event): void
{
$request = $event->getRequest();

if ($request->attributes->get('_route') === 'configure' || $request->getSession()->has('phpBinary')) {
if (\in_array($request->attributes->get('_route'), ['configure', 'index'], true) || $request->getSession()->has('phpBinary')) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion src/WebRecovery/src/Resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ imports:
framework:
secret: ''
default_locale: en
translator:
fallbacks: [ 'en' ]
cache_dir: null
default_path: '%kernel.project_dir%/Resources/translations'
session:
name: 'shopware-recovery'
cookie_secure: auto
cookie_samesite: strict

twig:
cache: false
default_path: '%kernel.project_dir%/Resources/views'
default_path: '%kernel.project_dir%/Resources/views'
Loading

0 comments on commit 10a21d8

Please sign in to comment.