Comment migrer une application en Anakeen Platform 4 2021 ?

Prérequis

Afin de pouvoir suivre ce guide, il faut préalablement avoir initialisé une application.

On souhaite porter notre application Restauratec en version AP4 2021.

Recommandations

Ce How-To vous montrera comment migrer une application en version 2021. En fonction des fonctionnalités utilisées dans votre projet, veuillez vous référer au journal des modifications de la version 2021.

Comment procéder ?

Créer un nouveau projet Anakeen Platform 4 2021

Pour commencer la migration, créons un nouveau projet Anakeen Platform 4, comme décrit dans ce How-To :

Créer un nouveau dossier

mkdir restauratec_2021
cd restauratec_2021

Initialiser un package.json

npm init

package.json :

{
  "name": "restauratec_2021",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Installer anakeen-platform, l’outil d’installation de paquets d’Anakeen Platform 4

Lancer la commande :

npm add @anakeen/anakeen-platform

Installer les modules AP4 nécessaires au projet

La liste des paquets utilisés par Restauratec est disponible dans le fichier devtools/anakeen-compose/repo.xml :











 
 
 
 
 
 
 
 
 
 



<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<compose xmlns="https://platform.anakeen.com/4/schemas/compose/1.0">
  <config>
    <localRepo path="../Docker/Volumes/_private/php/var/www/html/anakeen/repo"/>
    <localSrc path="src"/>
  </config>
  <registries>
    <registry name="anakeen-platform-4" url="https://a4ppm.ap4.anakeen.com/stable"/>
  </registries>
  <dependencies>
    <module name="admin-center" version="^2.1.2-RC.2020.1.38" registry="anakeen-platform-4"/>
    <module name="anakeen-control" version="^3.0.0-RC.2020.1.38" registry="anakeen-platform-4"/>
    <module name="anakeen-hub" version="^1.0.4-RC.2020.1.38" registry="anakeen-platform-4"/>
    <module name="anakeen-hub-business-app" version="^1.0.4-RC.2020.1.38" registry="anakeen-platform-4"/>
    <module name="development-center" version="^2.2.2-RC.2020.1.38" registry="anakeen-platform-4"/>
    <module name="security" version="^2.0.3-RC.2020.1.38" registry="anakeen-platform-4"/>
    <module name="smart-data-engine" version="^2.1.2-RC.2020.1.38" registry="anakeen-platform-4"/>
    <module name="transformation" version="^2.0.3-RC.2020.1.38" registry="anakeen-platform-4"/>
    <module name="user-interfaces" version="^3.0.2-RC.2020.1.38" registry="anakeen-platform-4"/>
    <module name="workflow" version="^2.0.2-RC.2020.1.38" registry="anakeen-platform-4"/>
  </dependencies>
</compose>

Lancer la commande interactive suivante :

npx @anakeen/anakeen-platform install

Choisir l’option custom et cocher les paquets suivants :

@anakeen/admin-center
@anakeen/anakeen-about
@anakeen/business-app
@anakeen/development-center
@anakeen/transformation
@anakeen/user-interfaces
❯ npx @anakeen/anakeen-platform install
? Modules flavour to install : [Mandatory] custom
? Working directory to use :  .
[06/09/2021] [15:14:45] › ▶  install   Initialized timer...
? What module do you want to install ? @anakeen/admin-center, @anakeen/business-app, @anakeen/development-center, @anakeen/transformation, @anakeen/user-interfaces
[06/09/2021] [15:18:04] › ◼  install   Timer run for: 199.70s
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/admin-center v3.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/anakeen-cli v2.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/anakeen-control v4.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/anakeen-module-validation v3.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/business-app v3.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/development-center v3.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/hub-components v3.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/security v3.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/smart-data-engine v6.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/transformation v3.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/user-interfaces v4.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ℹ  info      @anakeen/workflow v3.0.0-rc.2021.1.1.3 added
[06/09/2021] [15:18:04] › ✔  success   install done
[06/09/2021] [15:18:04] › ●  note      run 'npm i' in the working directory

Lancer enfin la commande d’installation des paquets :

npm install

Initialiser le projet vierge

Lancer la commande :

npx @anakeen/anakeen-cli create --sourcePath . --vendorName Cogip --moduleName Restauratec

Récupérer les données du projet Restauratec

Supprimer le contenu de /src :

rm -rf src

Importer le contenu du projet Restauratec dans le projet Restauratec_2021 :

cp -R ~/restauratec/src ~/restauratec_2021
cp ~/restauratec/info.xml ~/restauratec_2021/

Installer la version 2021

Lancer La commande suivante pour démarrer l’environnement Docker :

make env-start

Puis lancer la commande d’initialisation du contexte de l’application :

make context-install

Une erreur apparait :

❯ make context-install
[D][/home/leopold/restauratec_2021/dist/Restauratec-1.0.0.app]Make app
npx @anakeen/anakeen-cli build --sourcePath /home/leopold/restauratec_2021 -t /home/leopold/restauratec_2021/dist
[06/09/2021] [15:45:51] › ▶  build     Initialized timer...
[06/09/2021] [15:45:52] › ◼  build     Timer run for: 341ms
[06/09/2021] [15:45:52] › ✖  error
/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/200-HUBEXT_1161_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': [facet 'enumeration'] The value '' is not an element of the set {'or', 'and'}.
/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/200-HUBEXT_1161_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': '' is not a valid value of the atomic type '{https://platform.anakeen.com/4/schemas/search/1.0}olType'.

/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/201-HUBEXT_1165_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': [facet 'enumeration'] The value '' is not an element of the set {'or', 'and'}.
/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/201-HUBEXT_1165_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': '' is not a valid value of the atomic type '{https://platform.anakeen.com/4/schemas/search/1.0}olType'.

/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/202-HUBEXT_1163_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': [facet 'enumeration'] The value '' is not an element of the set {'or', 'and'}.
/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/202-HUBEXT_1163_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': '' is not a valid value of the atomic type '{https://platform.anakeen.com/4/schemas/search/1.0}olType'.

/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/203-HUBEXT_1162_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': [facet 'enumeration'] The value '' is not an element of the set {'or', 'and'}.
/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/203-HUBEXT_1162_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': '' is not a valid value of the atomic type '{https://platform.anakeen.com/4/schemas/search/1.0}olType'.

/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/204-HUBEXT_1164_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': [facet 'enumeration'] The value '' is not an element of the set {'or', 'and'}.
/home/leopold/restauratec_2021/src/vendor/Cogip/Restauratec/hub_export/extra/204-HUBEXT_1164_DSEARCH.xml line :10 : Error: Element '{https://platform.anakeen.com/4/schemas/search/1.0}query-filters', attribute 'logical-operator': '' is not a valid value of the atomic type '{https://platform.anakeen.com/4/schemas/search/1.0}olType'.

make: *** [Makefile:151 : /home/leopold/restauratec_2021/dist/Restauratec-1.0.0.app] Erreur 1

Cette erreur nous montre que notre fichier de définition de hub 20X-HUBEXT_XXX_DSEARCH.xml ne sont plus définis correctement au regard des nouvelles commandes de anakeen-cli.

Corrigeons les fichiers en supprimant les occurrences de logcal-operator="" avec la commande :

sed -i 's/\ logical-operator=\"\"//' src/vendor/Cogip/Restauratec/hub_export/extra/*

Relancer l’initialisation du contexte :

make context-install

Une nouvelle erreur apparaît :

[I]anakeen-platform-4 already registered
[I]Install
COMPOSE_UID=$(id -u) COMPOSE_GID=$(id -g) PROJECT_HTTP_PORT=8080 PROJECT_PSQL_PORT=54320 PROJECT_MAIL_PORT=8081 PROJECT_PHP_VERSION=8.0-latest PROJECT_POSTGRES_VERSION=13.1-latest docker-compose -p Restauratec -f /home/leopold/restauratec_2021/devtools/Docker/docker-compose.yml  exec  web /var/www/html/anakeen/control/anakeen-control install --no-interaction --no-ansi
Searching modules on repositories...
Will (i)nstall, (u)pgrade, (d)elete, or (r)eplace the following modules:
- (i) smart-data-engine 6.0.0-rc.2021.1.1.3
- (i) user-interfaces 4.0.0-rc.2021.1.1.3
- (i) security 3.0.0-rc.2021.1.1.3
- (i) workflow 3.0.0-rc.2021.1.1.3
- (i) anakeen-about 2.0.0-rc.2021.1.1.3
- (i) Restauratec 1.0.0
- (i) hub-components 3.0.0-rc.2021.1.1.3
- (i) admin-center 3.0.0-rc.2021.1.1.3
- (i) business-app 3.0.0-rc.2021.1.1.3
- (i) transformation 3.0.0-rc.2021.1.1.3
Installing modules...
.............................................................

In ModuleJob.php line 218:

  Error :Error importing "./vendor/Cogip/Restauratec/Accounts/110-RestauratecGroups.xml":
  Account reference "hub-user-role" not exists for account "group_restaurant_member"

On constate que notre projet Restauratec est installé avant le paquet hub-components. Il faut spécifier dans notre fichier info.xml nos dépendances aux paquets Anakeen :



 
 
 
 























<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<module xmlns="https://platform.anakeen.com/4/schemas/app/1.0" name="Restauratec" vendor="Cogip" version="1.0.0">
  <requires>
    <module name="smart-data-engine" version="^6.0.0-rc.2021.1.1.2"/>
    <module name="business-app" version="^3.0.0-rc.2021.1.1.2"/>
  </requires>
  <post-install>
    <process command="./ank.php --script=registerConfigDir --path=./vendor/Cogip/Restauratec/Config"/>
    <process command="./ank.php --script=importConfiguration --glob=./vendor/Cogip/Restauratec/Accounts/**/*.xml"/>
    <process command="./ank.php --script=importConfiguration --glob=./vendor/Cogip/Restauratec/Enumerates/**/*.xml"/>
    <process command="./ank.php --script=importConfiguration --glob=./vendor/Cogip/Restauratec/SmartStructures/Consommable/**/*.xml"/>
    <process command="./ank.php --script=importConfiguration --glob=./vendor/Cogip/Restauratec/SmartStructures/Menu/**/*.xml"/>
    <process command="./ank.php --script=importConfiguration --glob=./vendor/Cogip/Restauratec/SmartStructures/Boisson/**/*.xml"/>
    <process command="./ank.php --script=importConfiguration --glob=./vendor/Cogip/Restauratec/SmartStructures/Plat/**/*.xml"/>

    <process command="./ank.php --script=importConfiguration --file=./vendor/Cogip/Restauratec/250-MailTemplateMailMonPremierModele.xml"/>
    <process command="./ank.php --script=importConfiguration --file=./vendor/Cogip/Restauratec/SmartStructures/DataEntree.xml"/>
    <process command="./ank.php --script=importConfiguration --file=./vendor/Cogip/Restauratec/SmartStructures/DataPlat.xml"/>
    <process command="./ank.php --script=importConfiguration --file=./vendor/Cogip/Restauratec/SmartStructures/DataDessert.xml"/>
    <process command="./ank.php --script=importConfiguration --file=./vendor/Cogip/Restauratec/SmartStructures/DataBoisson.xml"/>

    <process command="./ank.php --script=importConfiguration --glob=./vendor/Cogip/Restauratec/hub_export/**/*.xml" />
  </post-install>
  <post-upgrade>
    <process command="./ank.php --script=importConfiguration --glob=./vendor/Cogip/Restauratec/Accounts/**/*.xml"/>
    <process command="./ank.php --script=importConfiguration --glob=./vendor/Cogip/Restauratec/Enumerates/**/*.xml"/>
  </post-upgrade>
</module>

Relançons l’initialisation du contexte :

make context-install

Une nouvelle erreur apparaît :

Error :Error importing "./vendor/Cogip/Restauratec/SmartStructures/Plat/PlatSettings/250-MailTemplateMailInfoE1ToE2.xml":
In the mail template "MAIL_INFO_E1_TO_E2" : the value "consommable_creator" of xml tag "element-field-value" need to be a name of a SmartField of type text.

La version 2021 a permis de détecter une erreur dans un de nos modèles de mail. Corrigeons le fichier src/vendor/Cogip/Restauratec/SmartStructures/Plat/PlatSettings/250-MailTemplateMailInfoE1ToE2.xml :









 

















<?xml version="1.0" encoding="UTF-8"?>
<smart:config xmlns:smart="https://platform.anakeen.com/4/schemas/smart/1.0" xmlns:mail="https://platform.anakeen.com/4/schemas/mailtemplate/1.0">
    <mail:mailtemplate name="MAIL_INFO_E1_TO_E2" label="Plat `En test` =>  `À la carte`" structure="PLAT" workflow-model="WFAM_PLAT">
        <mail:from>
            <mail:address>admin@foxriver.com</mail:address>
        </mail:from>
        <mail:recipients>
            <mail:recipient dest="to">
                <mail:element-account-field>consommable_creator</mail:element-account-field>
                <mail:workflow-account-field>wfl_dest_validation_group</mail:workflow-account-field>
            </mail:recipient>
        </mail:recipients>
        <mail:subject>Validation du plat [V_CONSOMMABLE_TITLE]</mail:subject>
        <mail:body content-type="html">
            <![CDATA[
            <p style="margin:0pt;">&nbsp;</p>
            <div>
                Le plat "<strong>[V_CONSOMMABLE_TITLE]</strong>" n’est plus `En test` mais
                désormais disponible `À la carte`
            </div>
            <p style="margin:0pt;">&nbsp;</p>
            ]]>
        </mail:body>
    </mail:mailtemplate>
</smart:config>

Supprimons l’ancien installeur afin d’avoir la dernière version des fichiers modifiés dans l’installation :

rm -rf dist

Relancer l’initialisation du contexte :

make context-install
Install complete.

Tester l’application

Pour tester, rendez-vous à l’url suivante :

http://localhost:8080/