diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 86f0f02..2518599 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -70,7 +70,7 @@ jobs: strategy: fail-fast: true matrix: - ps_version: ["1.6.1.24", "1.7.6.9", "1.7.7.8", "1.7.8.11", "8.1.4"] + ps_version: ["1.6.1.24", "1.7.6.9", "1.7.7.8", "1.7.8.11", "8.1.7"] steps: - name: Checkout repository uses: actions/checkout@v4 @@ -138,7 +138,7 @@ jobs: strategy: fail-fast: true matrix: - ps_version: ["1.6.1.24", "1.7.6.9", "1.7.7.8", "1.7.8.11", "8.1.4"] + ps_version: ["1.6.1.24", "1.7.6.9", "1.7.7.8", "1.7.8.11", "8.1.7"] steps: - name: Checkout repository uses: actions/checkout@v4 @@ -154,6 +154,11 @@ jobs: env: DOCKER_IMAGE: prestashop/prestashop-flashlight:${{ matrix.ps_version }}-debian + - name: The image has a PrestaShop console CLI + run: docker run --env PS_DOMAIN='localhost:80' --entrypoint /bin/ls $DOCKER_IMAGE bin/console + env: + DOCKER_IMAGE: prestashop/prestashop-flashlight:${{ matrix.ps_version }}-debian + docker_build_nightly: name: "Docker build: PS nightly" runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 00e0125..ad76784 100644 --- a/.gitignore +++ b/.gitignore @@ -11,8 +11,6 @@ sonar-project.properties PrestaShop/ prestashop/ vendor/ -.prestashop-tags -.prestashop-minor-tags # cloudflared credentials credentials.json diff --git a/README.md b/README.md index 94ee298..dcb6b8e 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ On error, PrestaShop Flashlight can quit with these exit codes: ## Does Flashlight support PrestaShop 1.6? -Partially yes. As there is no console within the sources, the modules cannot be automatically installed right now. Feel free to contribute! +Yes. A polyfill is provided for the PrestaShop console, officially introduced in 1.7. ## Developing a module with RW (known Linux issue) diff --git a/assets/alpine-base-install.sh b/assets/alpine-base-install.sh index c2a8ac5..245f856 100755 --- a/assets/alpine-base-install.sh +++ b/assets/alpine-base-install.sh @@ -3,7 +3,7 @@ set -eu # Install base tools, PHP requirements and dev-tools apk --no-cache add -U \ - bash less vim geoip git tzdata zip curl jq autoconf \ + bash less vim geoip git tzdata zip curl jq autoconf findutils \ nginx nginx-mod-http-headers-more nginx-mod-http-geoip \ nginx-mod-stream nginx-mod-stream-geoip ca-certificates \ php-common php-iconv php-gd mariadb-client sudo libjpeg libxml2 \ diff --git a/assets/patch.sh b/assets/patch.sh index 92ab405..d986726 100755 --- a/assets/patch.sh +++ b/assets/patch.sh @@ -4,10 +4,18 @@ set -eu PS_FOLDER=${PS_FOLDER:?missing PS_FOLDER} PS_VERSION=$(awk 'NR==1{print $2}' "$PS_FOLDER/VERSION") +add_polyfill_console () { + mkdir -p "$PS_FOLDER/bin" + touch "$PS_FOLDER/bin/console" + mv /tmp/ps-console-polyfill.php "$PS_FOLDER/bin/console" + chmod +x "$PS_FOLDER/bin/console" +} + patch_1_6 () { echo "✅ Add a robots file for PrestaShop 1.6" echo "User-agent: *" > "$PS_FOLDER/admin/robots.txt" echo "Disallow: /" >> "$PS_FOLDER/admin/robots.txt" + add_polyfill_console } patch_1_7_6 () { @@ -20,7 +28,7 @@ patch_1_7_6 () { } patch_other () { - cat /dev/null # Nothing to do + rm -f /tmp/ps-console-polyfill.php } if echo "$PS_VERSION" | grep "^1.6" > /dev/null; then diff --git a/assets/ps-console-polyfill.php b/assets/ps-console-polyfill.php new file mode 100644 index 0000000..74723ce --- /dev/null +++ b/assets/ps-console-polyfill.php @@ -0,0 +1,59 @@ +#!/usr/local/bin/php -d memory_limit=-1 +=')) { + global $kernel; + if(!$kernel){ + require_once _PS_ROOT_DIR_.'/app/AppKernel.php'; + $kernel = new \AppKernel('dev', true); + $kernel->boot(); + } + } + $module = Module::getInstanceByName($moduleName); + $module->install(); +} + +function clearCache() { + $cacheDirs = [ + _PS_CACHEFS_DIRECTORY_ . '/smarty/compile', + _PS_CACHEFS_DIRECTORY_ . '/smarty/cache', + _PS_IMG_DIR_ . '/tmp', + ]; + foreach ($cacheDirs as $dir) { + $files = glob($dir . '/*'); + foreach ($files as $file) { + if (is_file($file)) { + unlink($file); + } + } + } +} + +switch ($argv[1]) { + case 'prestashop:module': + installModule($argv); + break; + case 'cache:clear': + clearCache(); + break; + default: + throw new Exception('This command is not supported by prestashop-flashlight\'s polyfill'); +} + diff --git a/assets/run.sh b/assets/run.sh index b342152..6dfa45d 100755 --- a/assets/run.sh +++ b/assets/run.sh @@ -181,21 +181,17 @@ fi # Eventually install some modules if [ ! -f $MODULES_INSTALLED_LOCK ] || [ "$INSTALL_MODULES_ON_RESTART" = "true" ]; then if [ -d "$INSTALL_MODULES_DIR" ]; then - if [ -f "$PS_FOLDER/bin/console" ]; then - for file in "$INSTALL_MODULES_DIR"/*.zip; do - module=$(unzip -l "$file" | awk 'NR==4{print $4}' | sed 's/\/$//' | tr "-" "\n" | head -n 1) - echo "--> Unzipping and installing $module from $file..." - rm -rf "/var/www/html/modules/${module:-something-at-least}" - unzip -qq "$file" -d /var/www/html/modules - if [ "$ON_INSTALL_MODULES_FAILURE" = "continue" ]; then - (php -d memory_limit=-1 "$PS_FOLDER/bin/console" prestashop:module --no-interaction install "$module") || { echo "x module installation failed. Skipping."; } - else - (php -d memory_limit=-1 "$PS_FOLDER/bin/console" prestashop:module --no-interaction install "$module") || { echo "x module installation failed. Sleep and exit."; sleep 10; exit 6; } - fi - done; - else - echo "Auto-installing modules with PrestaShop v1.6 is not yet supported"; - fi + for file in "$INSTALL_MODULES_DIR"/*.zip; do + module=$(unzip -l "$file" | awk 'NR==4{print $4}' | sed 's/\/$//' | tr "-" "\n" | head -n 1) + echo "--> Unzipping and installing $module from $file..." + rm -rf "/var/www/html/modules/${module:-something-at-least}" + unzip -qq "$file" -d /var/www/html/modules + if [ "$ON_INSTALL_MODULES_FAILURE" = "continue" ]; then + (php -d memory_limit=-1 "$PS_FOLDER/bin/console" prestashop:module --no-interaction install "$module") || { echo "x module installation failed. Skipping."; } + else + (php -d memory_limit=-1 "$PS_FOLDER/bin/console" prestashop:module --no-interaction install "$module") || { echo "x module installation failed. Sleep and exit."; sleep 10; exit 6; } + fi + done; fi touch $MODULES_INSTALLED_LOCK else diff --git a/docker/alpine.Dockerfile b/docker/alpine.Dockerfile index 7ab5b5c..7dfda28 100644 --- a/docker/alpine.Dockerfile +++ b/docker/alpine.Dockerfile @@ -22,6 +22,7 @@ COPY ./assets/nginx.conf /etc/nginx/nginx.conf COPY ./php-flavours.json /tmp COPY ./assets/php-configuration.sh /tmp/ COPY ./assets/alpine-base-install.sh /tmp/ +COPY ./assets/ps-console-polyfill.php /tmp/ COPY ./assets/coding-standards /var/opt/prestashop/coding-standards RUN /tmp/alpine-base-install.sh \ diff --git a/docker/debian.Dockerfile b/docker/debian.Dockerfile index 76867aa..63f0227 100644 --- a/docker/debian.Dockerfile +++ b/docker/debian.Dockerfile @@ -22,6 +22,7 @@ COPY ./assets/nginx.conf /etc/nginx/nginx.conf COPY ./php-flavours.json /tmp COPY ./assets/php-configuration.sh /tmp/ COPY ./assets/debian-base-install.sh /tmp/ +COPY ./assets/ps-console-polyfill.php /tmp/ COPY ./assets/coding-standards /var/opt/prestashop/coding-standards RUN /tmp/debian-base-install.sh \ diff --git a/examples/auto-install-modules/init-scripts/install-mock.sh b/examples/auto-install-modules/init-scripts/install-mock.sh index 222596f..c1ece0c 100755 --- a/examples/auto-install-modules/init-scripts/install-mock.sh +++ b/examples/auto-install-modules/init-scripts/install-mock.sh @@ -8,18 +8,14 @@ # set -eu -run_user () { - sudo -g www-data -u www-data -- "$@" -} - ps_accounts_mock_install() { echo "* [ps_accounts_mock] downloading..." - wget -q -O /tmp/ps_accounts.zip "https://github.com/PrestaShopCorp/ps_accounts_mock/releases/download/v1.0.0/ps_accounts.zip" + wget -q -O /tmp/ps_accounts.zip "https://github.com/PrestaShopCorp/ps_accounts_mock/releases/download/v7.0.2/ps_accounts.zip" echo "* [ps_accounts_mock] unzipping..." - run_user unzip -qq /tmp/ps_accounts.zip -d /var/www/html/modules + unzip -qq /tmp/ps_accounts.zip -d /var/www/html/modules echo "* [ps_accounts_mock] installing the module..." cd "$PS_FOLDER" - run_user php -d memory_limit=-1 bin/console prestashop:module --no-interaction install "ps_accounts" + php -d memory_limit=-1 bin/console prestashop:module --no-interaction install "ps_accounts" } ps_accounts_mock_install diff --git a/examples/auto-install-modules/modules/psalsace-v1.0.0.zip b/examples/auto-install-modules/modules/psalsace-v1.0.0.zip index 61d1a0a..b4d8ac7 100644 Binary files a/examples/auto-install-modules/modules/psalsace-v1.0.0.zip and b/examples/auto-install-modules/modules/psalsace-v1.0.0.zip differ diff --git a/examples/develop-a-module/modules/testmodule/testmodule.php b/examples/develop-a-module/modules/testmodule/testmodule.php index 658553a..04823c7 100644 --- a/examples/develop-a-module/modules/testmodule/testmodule.php +++ b/examples/develop-a-module/modules/testmodule/testmodule.php @@ -23,9 +23,9 @@ public function __construct() $this->bootstrap = false; parent::__construct(); - $this->displayName = $this->trans('Test Module', [], 'Modules.Mymodule.Admin'); - $this->description = $this->trans('Test Module', [], 'Modules.Mymodule.Admin'); - $this->confirmUninstall = $this->trans('Are you sure you want to quit ModuleA?', [], 'Modules.Mymodule.Admin'); + $this->displayName = $this->l('Test Module', [], 'Modules.Mymodule.Admin'); + $this->description = $this->l('Test Module', [], 'Modules.Mymodule.Admin'); + $this->confirmUninstall = $this->l('Are you sure you want to quit ModuleA?', [], 'Modules.Mymodule.Admin'); require_once __DIR__ . '/vendor/autoload.php'; } diff --git a/examples/module-coding-standard/testmodule/testmodule.php b/examples/module-coding-standard/testmodule/testmodule.php index 658553a..04823c7 100644 --- a/examples/module-coding-standard/testmodule/testmodule.php +++ b/examples/module-coding-standard/testmodule/testmodule.php @@ -23,9 +23,9 @@ public function __construct() $this->bootstrap = false; parent::__construct(); - $this->displayName = $this->trans('Test Module', [], 'Modules.Mymodule.Admin'); - $this->description = $this->trans('Test Module', [], 'Modules.Mymodule.Admin'); - $this->confirmUninstall = $this->trans('Are you sure you want to quit ModuleA?', [], 'Modules.Mymodule.Admin'); + $this->displayName = $this->l('Test Module', [], 'Modules.Mymodule.Admin'); + $this->description = $this->l('Test Module', [], 'Modules.Mymodule.Admin'); + $this->confirmUninstall = $this->l('Are you sure you want to quit ModuleA?', [], 'Modules.Mymodule.Admin'); require_once __DIR__ . '/vendor/autoload.php'; } diff --git a/release.sh b/release.sh index b14931b..d1e5b61 100755 --- a/release.sh +++ b/release.sh @@ -1,36 +1,42 @@ #!/bin/sh set -eu -PRESTASHOP_TAGS=.prestashop-tags -PRESTASHOP_MINOR_TAGS=.prestashop-minor-tags - -get_prestashop_tags() { - git ls-remote --tags git@github.com:PrestaShop/PrestaShop.git \ - | cut -f2 \ - | grep -Ev '\/1.5|\/1.6.0|beta|rc|RC|\^' \ - | cut -d '/' -f3 \ - | sort -r -V > "$PRESTASHOP_TAGS" -} - -get_prestashop_minor_tags() { - printf "" > "$PRESTASHOP_MINOR_TAGS" - while IFS= read -r version; do - major_minor=$(echo "$version" | cut -d. -f1-2) - major_minor_patch=$(echo "$version" | cut -d. -f1-3) - criteria=$major_minor - # shellcheck disable=SC3010 - [[ "$major_minor" == 1* ]] && criteria=$major_minor_patch - if ! grep -q "^$criteria" "$PRESTASHOP_MINOR_TAGS"; then - echo "$version" >> "$PRESTASHOP_MINOR_TAGS" - fi - done < "$PRESTASHOP_TAGS" -} +EXCLUDED_TAGS='\/1.5|\/1.6.0|alpha|beta|rc|RC|\^' +PRESTASHOP_TAGS=$(git ls-remote --tags git@github.com:PrestaShop/PrestaShop.git | cut -f2 | grep -Ev $EXCLUDED_TAGS | cut -d '/' -f3 | sort -r -V) +# PRESTASHOP_MAJOR_TAGS=$( +# MAJOR_TAGS="" +# for VERSION in $PRESTASHOP_TAGS; do +# CRITERIA=$(echo "$VERSION" | cut -d. -f1) +# # shellcheck disable=SC3010 +# if [[ "$CRITERIA" == 1* ]]; then +# CRITERIA=$(echo "$VERSION" | cut -d. -f1-2) +# fi +# if ! echo "$MAJOR_TAGS" | grep -q "^$CRITERIA"; then +# MAJOR_TAGS="$MAJOR_TAGS\n$VERSION"; +# fi +# done +# echo "$MAJOR_TAGS" +# ) +# PRESTASHOP_MINOR_TAGS=$( +# MINOR_TAGS="" +# for VERSION in $PRESTASHOP_TAGS; do +# CRITERIA=$(echo "$VERSION" | cut -d. -f1-2) +# # shellcheck disable=SC3010 +# if [[ "$CRITERIA" == 1* ]]; then +# CRITERIA=$(echo "$VERSION" | cut -d. -f1-3) +# fi +# if ! echo "$MINOR_TAGS" | grep -q "^$CRITERIA"; then +# MINOR_TAGS="$MINOR_TAGS\n$VERSION"; +# fi +# done +# echo "$MINOR_TAGS" +# ) get_compatible_php_version() { - REGEXP_LIST=$(jq -r 'keys_unsorted | .[]'