Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize full Symfony layout in Back Office #32235

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
9a2126e
Add feature flag for Symfony layout
jolelievre Apr 20, 2023
a9d1507
Create based twig layout, most of the layout variables are initialize…
jolelievre Apr 21, 2023
bb427ee
Make LayoutExtension more resilient in CLI environment
jolelievre Apr 25, 2023
5c170c4
introduce LegacyController that allows rendering a smarty template vi…
jolelievre Apr 26, 2023
5e8ec2f
Add dedicated SymfonyLayoutFeature to check if symfony layout is enabled
jolelievre Apr 26, 2023
83558cc
LegacyContext no longer creates a legacy controller when symfony layo…
jolelievre Apr 26, 2023
963e696
Include all missing components in default layout
jolelievre Apr 26, 2023
5383b33
Hande page header toolbar
jolelievre Apr 26, 2023
5ad9fdd
Define interface for symfony layout feature which allows disabling it…
jolelievre Apr 28, 2023
79d5459
Fix js files integration, configurators must be executed in the appro…
jolelievre Apr 28, 2023
0bc5470
Fix setMedia to matcgh recent changes
jolelievre Apr 28, 2023
3dfe642
Fix feature flag controller redirection
jolelievre Apr 28, 2023
9f23933
Fix notifications API access
jolelievre May 1, 2023
d6ed479
Handle lite layout and correctly hide header when needed
jolelievre May 1, 2023
2656949
Add sanity tests run with symfony layout enabled only when Symfony la…
jolelievre May 1, 2023
6c343e8
Trigger worflow even without label to test
jolelievre May 1, 2023
ae24cee
Handle controller_type in bridge controller
jolelievre May 2, 2023
b7acb9e
Preset global variables use by global layout
jolelievre May 2, 2023
d6b8ba2
Handle correctly layoutTitle and toolbar class
jolelievre May 4, 2023
3d5810c
Handle symfony layout via environment variable, set it for sanity tests
jolelievre May 5, 2023
5429ec4
Load .env to allow setting env variables for UI tests
jolelievre May 5, 2023
c70592b
Prevent double assignation of PHP constant
jolelievre May 5, 2023
8664f4f
Symfony layout can be disabled via query parameter
jolelievre May 5, 2023
65e4b7c
Run product page V2 with symfony layout as well
jolelievre May 5, 2023
2398c32
Handle custom metaTitle and special title of Order correctly
jolelievre May 5, 2023
35a07a4
Handle proper fallback for meta title
jolelievre May 5, 2023
5d855b5
Use configuration as the default table value just like in AminControl…
jolelievre May 5, 2023
7011f1d
Fix product pagination on v1, and hide header feature in default layout
jolelievre May 10, 2023
a631847
Make sure the symfony toolbar is correctly closed
jolelievre May 10, 2023
b175f8e
Force closing toolbar before creating a product
jolelievre May 10, 2023
d07a5cc
Remove legacy const and classes from services
jolelievre May 12, 2023
f664454
Clean PHPStan errors a bit more
jolelievre May 15, 2023
9037833
Update PHPStan baseline
jolelievre May 15, 2023
c4a9bf6
Sanity for symfonylayout only on PHP 8.1
jolelievre May 15, 2023
55185da
Enable symfony layout via feature flag command
jolelievre May 16, 2023
889c887
Run sanity tests without installation part
jolelievre May 16, 2023
2ffd1dc
Auto install
jolelievre May 16, 2023
c9723cb
Do not run product sanity tests
jolelievre May 16, 2023
d047953
Run product v1 tests
jolelievre May 17, 2023
ea54584
Run v1 and v2
jolelievre May 17, 2023
42135dc
One at a time
jolelievre May 17, 2023
c893307
Display dev logs
jolelievre May 17, 2023
09d7fb8
plop
jolelievre May 17, 2023
280752e
Improve artifact upload and warmup cache
jolelievre May 17, 2023
9a2b1a9
Disable dev mode
jolelievre May 17, 2023
04b5cd8
Adapt FrameworkBundleAdminControllerTest
jolelievre Jun 7, 2023
5134d10
Update DotEnv initialization
jolelievre Jun 7, 2023
d586638
Replace smart controller component with Twig function
jolelievre Jun 20, 2023
eb02e45
Use str_starts_with
jolelievre Jun 20, 2023
7f04c4c
Change name of Sanity with symfony layout so it's not matching the re…
jolelievre Jun 20, 2023
4b085e8
Rector fix
jolelievre Jun 20, 2023
3a70d97
Setup USE_SYMFONY_LAYOUT in docker-compose.yml
jolelievre Jun 20, 2023
cd403a6
Use .env file to enable symfony layout
jolelievre Jun 20, 2023
27c4977
Make SymfonyLayoutExtension more resilient to the absence of request
jolelievre Jun 20, 2023
55d15f3
Improve sanity symfony tests
jolelievre Jun 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/actions/setup-prestashop-env/action.yml
Expand Up @@ -31,6 +31,10 @@ inputs:
required: false
description: GITHUB_TOKEN to be used by composer
default: ""
backoffice-layout:
description: Backoffice layout
required: false
default: 'legacy'

runs:
using: "composite"
Expand Down Expand Up @@ -112,6 +116,12 @@ runs:
echo "Disabling DEV mode ...";
sed -ie "s/define('_PS_MODE_DEV_', true);/define('_PS_MODE_DEV_',\ false);/g" config/defines.inc.php

- name: Adapt Back Office layout
if: inputs.backoffice-layout == 'symfony'
shell: bash
run: |
sudo runuser -g www-data -u www-data -- echo USE_SYMFONY_LAYOUT=1 >> .env

- name: Install PrestaShop
if: inputs.ps-auto-install == 'true'
shell: bash
Expand All @@ -123,3 +133,17 @@ runs:
--password="$ADMIN_PASSWD" --email="demo@prestashop.com" \
--language="en" --country="fr" \
--ssl=1

- name: Clear and warmup cache for dev mode
if: inputs.ps-dev-mode == 'true'
shell: bash
run: |
sudo runuser -g www-data -u www-data -- php -d memory_limit=-1 ./bin/console cache:clear --env=dev
sudo runuser -g www-data -u www-data -- php -d memory_limit=-1 ./bin/console cache:warmup --env=dev

- name: Clear and warmup cache for prod mode
if: inputs.ps-dev-mode == 'false'
shell: bash
run: |
sudo runuser -g www-data -u www-data -- php -d memory_limit=-1 ./bin/console cache:clear --env=prod
sudo runuser -g www-data -u www-data -- php -d memory_limit=-1 ./bin/console cache:warmup --env=prod
56 changes: 56 additions & 0 deletions .github/workflows/sanity-symfony-layout.yml
@@ -0,0 +1,56 @@
name: UI tests (Symfony layout)
on: [ push, pull_request ]
permissions:
contents: read # to fetch code (actions/checkout)
concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
sanity:
permissions:
contents: read # to fetch code (actions/checkout)
runs-on: ubuntu-latest
name: Sanity Symfony Layout
strategy:
matrix:
php: [ '8.1' ]
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Setup environment
uses: ./.github/actions/setup-prestashop-env
with:
php-version: ${{ matrix.php }}
mysql-version: '5.7'
mysql-database: 'prestashop'
mysql-root-password: 'password'
node-version: '16'
npm-version: '7'
github-token: ${{ secrets.GITHUB_TOKEN }}
backoffice-layout: symfony

- name: Cache Playwright browsers
uses: actions/cache@v3
with:
path: ~/.cache/ms-playwright/
key: ${{ runner.os }}-browsers

- name: Use .env.ci
run: mv .env.ci .env
working-directory: ./tests/UI

- name: Run tests even with install since the symfony layout is enabled via .env
run: npm ci && npm run test:sanity:fast-fail && npm run test:sanity:productV2:fast-fail
working-directory: ./tests/UI
env:
ENABLE_SSL: true

- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: artifacts-${{ matrix.php }}
path: |
./tests/UI/screenshots/
var/logs/
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -214,3 +214,5 @@ tools/build/releases/*
# Docker configuration
install.lock
docker-compose.override.yml

.env
12 changes: 12 additions & 0 deletions admin-dev/index.php
Expand Up @@ -24,6 +24,7 @@
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
use PrestaShopBundle\Api\Api;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
Expand Down Expand Up @@ -70,6 +71,17 @@
if (_PS_MODE_DEV_) {
Debug::enable();
}

// Loads .env file from the root of project if present
$dotEnvFile = dirname(__FILE__, 2) . '/.env';
if (file_exists($dotEnvFile)) {
(new Dotenv())
// DO NOT use putEnv
->usePutenv(false)
->loadEnv($dotEnvFile)
;
}

Comment on lines +76 to +84
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about .env.local, .env.*.local ... ?

require_once __DIR__ . '/../app/AppKernel.php';

$kernel = new AppKernel(_PS_ENV_, _PS_MODE_DEV_);
Expand Down
4 changes: 2 additions & 2 deletions admin-dev/themes/default/template/header.tpl
Expand Up @@ -76,8 +76,8 @@
var employee_token = '{getAdminToken tab='AdminEmployees'}';
var choose_language_translate = '{l|escape s='Choose language:' js=1 d='Admin.Actions'}';
var default_language = '{$default_language|intval}';
var admin_notification_get_link = adminNotificationGetLink = '{$link->getAdminLink("AdminCommon")|addslashes}';
var admin_notification_push_link = adminNotificationPushLink ='{$link->getAdminLink("AdminCommon", true, ['route' => 'admin_common_notifications_ack'])|addslashes}';
var admin_notification_get_link = adminNotificationGetLink = '{$link->getAdminLink('AdminCommon', true, ['route' => 'admin_common_notifications'])|addslashes}';
var admin_notification_push_link = adminNotificationPushLink ='{$link->getAdminLink('AdminCommon', true, ['route' => 'admin_common_notifications_ack'])|addslashes}';
var update_success_msg = '{l|escape s='Successful update' js=1 d='Admin.Notifications.Success'}';
var search_product_msg = '{l|escape s='Search for a product' js=1 d='Admin.Orderscustomers.Feature'}';
</script>
Expand Down
14 changes: 14 additions & 0 deletions admin-dev/themes/new-theme/.webpack/common.js
Expand Up @@ -417,6 +417,7 @@ module.exports = {
},
},
}),
// Smarty preload
new HtmlWebpackPlugin({
filename: 'preload.tpl',
templateContent: '{{{preloadLinks}}}',
Expand All @@ -433,6 +434,19 @@ module.exports = {
// eslint-disable-next-line
replaceCallback: ({indexSource, linksAsString}) => indexSource.replace('{{{preloadLinks}}}', linksAsString.replace(/href="/g, 'href="{$admin_dir}')),
}),
// Twig preload
new HtmlWebpackPlugin({
filename: 'preload.html.twig',
templateContent: '{{{preloadLinks}}}',
inject: false,
}),
new FontPreloadPlugin({
index: 'preload.html.twig',
extensions: ['woff2'],
filter: /preload/,
// eslint-disable-next-line
replaceCallback: ({indexSource, linksAsString}) => indexSource.replace('{{{preloadLinks}}}', linksAsString.replace(/href="([^"]+)"/g, 'href="{{ asset(\'themes/new-theme/public/$1\') }}"')),
}),
new CssoWebpackPlugin({
forceMediaMerge: true,
}),
Expand Down
6 changes: 3 additions & 3 deletions admin-dev/themes/new-theme/template/header.tpl
Expand Up @@ -66,9 +66,9 @@
var employee_token = '{getAdminToken tab='AdminEmployees'}';
var choose_language_translate = '{l s='Choose language:' js=1 d='Admin.Actions'}';
var default_language = '{$default_language|intval}';
var admin_modules_link = '{$link->getAdminLink("AdminModulesSf", true, ['route' => "admin_module_manage"])|addslashes}';
var admin_notification_get_link = '{$link->getAdminLink("AdminCommon")|addslashes}';
var admin_notification_push_link = adminNotificationPushLink = '{$link->getAdminLink("AdminCommon", true, ['route' => 'admin_common_notifications_ack'])|addslashes}';
var admin_modules_link = '{$link->getAdminLink('AdminModulesSf', true, ['route' => 'admin_module_manage'])|addslashes}';
var admin_notification_get_link = '{$link->getAdminLink('AdminCommon', true, ['route' => 'admin_common_notifications'])|addslashes}';
var admin_notification_push_link = adminNotificationPushLink = '{$link->getAdminLink('AdminCommon', true, ['route' => 'admin_common_notifications_ack'])|addslashes}';
var update_success_msg = '{l s='Update successful' js=1 d='Admin.Notifications.Success'}';
var search_product_msg = '{l s='Search for a product' js=1 d='Admin.Orderscustomers.Feature'}';
</script>
Expand Down
4 changes: 4 additions & 0 deletions app/config/config.yml
Expand Up @@ -12,13 +12,16 @@ parameters:
translator.class: PrestaShopBundle\Translation\Translator
translator.data_collector: PrestaShopBundle\Translation\DataCollectorTranslator
prestashop_views: "%kernel.project_dir%/src/PrestaShopBundle/Resources/views"
# This is hard-coded for now but it should be dynamic wince admin folder name changes in prod environments
admin_themes_folder: "%kernel.project_dir%/admin-dev/themes"
admin_page: "%prestashop_views%/Admin"
env(PS_LOG_OUTPUT): "%kernel.logs_dir%/%kernel.environment%.log"
env(PS_LOG_MAX_FILES): '30'
mail_themes_uri: "/mails/themes"
mail_themes_dir: "%kernel.project_dir%%mail_themes_uri%"
modules_translation_paths: [ ]
api_base_path: !php/const PrestaShopBundle\Api\Api::API_BASE_PATH
env(USE_SYMFONY_LAYOUT): 'false'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put this in the .env no?


# Autowires Core controllers
services:
Expand Down Expand Up @@ -85,6 +88,7 @@ twig:
'%kernel.project_dir%/modules': Modules
'%mail_themes_dir%': MailThemes
'%prestashop_views%': PrestaShopCore
'%admin_themes_folder%': AdminThemes
globals:
webpack_server: false
multistore_field_prefix: !php/const PrestaShopBundle\Service\Form\MultistoreCheckboxEnabler::MULTISTORE_FIELD_PREFIX
Expand Down
3 changes: 3 additions & 0 deletions classes/lang/KeysReference/FeatureFlagLang.php
Expand Up @@ -94,3 +94,6 @@

trans('Features', 'Admin.Advparameters.Feature');
trans('Enable or disable the migrated features page.', 'Admin.Advparameters.Help');

trans('Symfony layout', 'Admin.Advparameters.Feature');
trans('Enable / Disable symfony layout (in opposition to legacy layout).', 'Admin.Advparameters.Help');
3 changes: 3 additions & 0 deletions config/services/front/services_prod.yml
Expand Up @@ -57,3 +57,6 @@ services:
class: PrestaShopBundle\Translation\TranslatorLanguageLoader
arguments:
- '@prestashop.adapter.module.repository.module_repository'

PrestaShopBundle\Bridge\SymfonyLayoutFeatureInterface:
class: PrestaShopBundle\Bridge\DisabledSymfonyLayoutFeature
4 changes: 4 additions & 0 deletions config/services/webservice/services_prod.yml
@@ -1,2 +1,6 @@
imports:
- { resource: ../common.yml }

services:
PrestaShopBundle\Bridge\SymfonyLayoutFeatureInterface:
class: PrestaShopBundle\Bridge\DisabledSymfonyLayoutFeature
1 change: 1 addition & 0 deletions docker-compose.yml
Expand Up @@ -56,6 +56,7 @@ services:
PS_ERASE_DB: ${PS_ERASE_DB:-0}
ADMIN_MAIL: ${ADMIN_MAIL:-demo@prestashop.com}
ADMIN_PASSWD: ${ADMIN_PASSWD:-Correct Horse Battery Staple}
USE_SYMFONY_LAYOUT: ${USE_SYMFONY_LAYOUT:-0}
command: ["/tmp/wait-for-it.sh", "--timeout=60", "--strict", "mysql:3306", "--", "/tmp/docker_run_git.sh"]
ports:
- "8001:80"
Expand Down
4 changes: 3 additions & 1 deletion install-dev/controllers/http/smarty_compile.php
Expand Up @@ -23,7 +23,9 @@
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
define('_PS_DO_NOT_LOAD_CONFIGURATION_', true);
if (!defined('_PS_DO_NOT_LOAD_CONFIGURATION_')) {
define('_PS_DO_NOT_LOAD_CONFIGURATION_', true);
}
if (Tools::getValue('bo')) {
if (!is_dir(_PS_ROOT_DIR_ . '/admin/')) {
exit;
Expand Down
1 change: 1 addition & 0 deletions install-dev/data/xml/feature_flag.xml
Expand Up @@ -25,5 +25,6 @@
<feature_flag id="customer_threads" name="customer_threads" label_wording="Customer threads" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the migrated customer threads page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="order_state" name="order_state" label_wording="Order states" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the migrated order states page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="feature" name="feature" label_wording="Features" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the migrated features page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="symfony_layout" name="symfony_layout" label_wording="Symfony layout" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable symfony layout (in opposition to legacy layout)." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
</entities>
</entity_feature_flag>