diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e1818d4..1ebf2ce 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,13 +1,20 @@ version: 2 updates: -- package-ecosystem: npm +- package-ecosystem: composer directory: "/" schedule: interval: daily time: "04:00" open-pull-requests-limit: 10 target-branch: dev -- package-ecosystem: composer +- package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + time: "04:00" + open-pull-requests-limit: 10 + target-branch: dev +- package-ecosystem: npm directory: "/" schedule: interval: daily diff --git a/.github/workflows/add-issue-to-project.yml b/.github/workflows/add-issue-to-project.yml new file mode 100644 index 0000000..cfa4ba3 --- /dev/null +++ b/.github/workflows/add-issue-to-project.yml @@ -0,0 +1,13 @@ +name: Add Issue to Project + +on: + issues: + types: [ opened ] + +jobs: + add-to-project: + uses: PrestaShop/.github/.github/workflows/reusable-add-to-project.yml@master + with: + project-number: 47 + secrets: + TOKEN: ${{ secrets.JARVIS_TOKEN }} diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index a776b41..db79f23 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,22 +1,12 @@ name: PHP tests on: [push, pull_request] jobs: - # Check there is no syntax errors in the project php-linter: - name: PHP Syntax check 5.4 => 8.1 + name: PHP Syntax check 7.2 => 8.5 runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2.0.0 - - - name: PHP syntax checker 5.4 - uses: prestashop/github-action-php-lint/5.6@master - - - name: PHP syntax checker 5.5 - uses: prestashop/github-action-php-lint/5.6@master - - - name: PHP syntax checker 5.6 - uses: prestashop/github-action-php-lint/5.6@master + uses: actions/checkout@v3.1.0 - name: PHP syntax checker 7.2 uses: prestashop/github-action-php-lint/7.2@master @@ -33,63 +23,128 @@ jobs: - name: PHP syntax checker 8.1 uses: prestashop/github-action-php-lint/8.1@master + - name: PHP syntax checker 8.2 + uses: prestashop/github-action-php-lint/8.2@master + + - name: PHP syntax checker 8.3 + uses: prestashop/github-action-php-lint/8.3@master + + - name: PHP syntax checker 8.4 + uses: prestashop/github-action-php-lint/8.4@master + + - name: PHP syntax checker 8.5 + uses: prestashop/github-action-php-lint/8.5@master + # Check the PHP code follow the coding standards php-cs-fixer: name: PHP-CS-Fixer runs-on: ubuntu-latest steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: Run PHP-CS-Fixer + uses: PrestaShop/.github/.github/actions/php-ci/php-cs@master with: php-version: '7.4' - - name: Checkout - uses: actions/checkout@v2.0.0 - - - name: Cache dependencies - uses: actions/cache@v2 + # Run PHPStan against the module (PHP 7.4 – PS 8.2) + phpstan-74-81: + name: PHPStan (PHP 7.4 - 8.1) + runs-on: ubuntu-latest + strategy: + matrix: + presta_version: ['8.2.x'] + php_version: ['7.4', '8.1'] + fail-fast: false + env: + PHPRC: ${{ github.workspace }}/${{ github.event.repository.name }}/.phpstan-php-ini + steps: + - name: Checkout repository + uses: actions/checkout@v6 with: - path: vendor - key: php-${{ hashFiles('composer.lock') }} - - - name: Install dependencies - run: composer install - - - name: Run PHP-CS-Fixer - run: ./vendor/bin/php-cs-fixer fix --dry-run --diff --using-cache=no --diff-format udiff - - # Run PHPStan against the module and a PrestaShop release - phpstan: - name: PHPStan + path: ${{ github.event.repository.name }} + + - name: Prepare PHP env for PrestaShop 8 (define constants before any bootstrap) + run: | + mkdir -p ${{ github.event.repository.name }}/.phpstan-php-ini + { + echo "auto_prepend_file=$GITHUB_WORKSPACE/${{ github.event.repository.name }}/tests/php/phpstan/prepend-constants.php" + echo "memory_limit=512M" + } > ${{ github.event.repository.name }}/.phpstan-php-ini/php.ini + + - name: Run PHPStan + uses: PrestaShop/.github/.github/actions/php-ci/phpstan@master + with: + php-version: ${{ matrix.php_version }} + presta-version: ${{ matrix.presta_version }} + module-name: ${{ github.event.repository.name }} + phpstan-level: '5' + phpstan-config: tests/php/phpstan/phpstan-${{ matrix.presta_version }}.neon + phpstan-version: '^0.12' + composer-version: '2.2.18' + +# Run PHPStan against the module (PHP 8.1 – 8.4) + phpstan-81-84: + name: PHPStan (PHP 8.1 - 8.4) runs-on: ubuntu-latest strategy: matrix: - presta-versions: ['1.7.2.5', '1.7.3.4', '1.7.4.4', '1.7.5.1', '1.7.6', '1.7.7', '1.7.8', 'latest'] + presta_version: ['9.0.3'] + php_version: ['8.1', '8.4'] + fail-fast: false + env: + PHPRC: ${{ github.workspace }}/${{ github.event.repository.name }}/.phpstan-php-ini steps: - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: Checkout repository + uses: actions/checkout@v6 with: - php-version: '7.4' - - - name: Checkout - uses: actions/checkout@v2.0.0 - - # Add vendor folder in cache to make next builds faster - - name: Cache vendor folder - uses: actions/cache@v1 + path: ${{ github.event.repository.name }} + + - name: Prepare PHP env for PrestaShop 9.1.x and later (define constants before any bootstrap) + run: | + mkdir -p ${{ github.event.repository.name }}/.phpstan-php-ini + { + echo "auto_prepend_file=$GITHUB_WORKSPACE/${{ github.event.repository.name }}/tests/php/phpstan/prepend-constants.php" + echo "memory_limit=512M" + } > ${{ github.event.repository.name }}/.phpstan-php-ini/php.ini + + - name: Run PHPStan + uses: PrestaShop/.github/.github/actions/php-ci/phpstan@master with: - path: vendor - key: php-${{ hashFiles('composer.lock') }} + php-version: ${{ matrix.php_version }} + presta-version: ${{ matrix.presta_version }} + module-name: ${{ github.event.repository.name }} + phpstan-level: '5' + phpstan-config: tests/php/phpstan/phpstan-${{ matrix.presta_version }}.neon - # Add composer local folder in cache to make next builds faster - - name: Cache composer folder - uses: actions/cache@v1 + # Run PHPStan against the module (PHP 8.1 – 8.5) + phpstan: + name: PHPStan (PHP 8.1 - 8.5) + runs-on: ubuntu-latest + strategy: + matrix: + presta_version: ['9.1.5', '9.2.x', 'develop'] + php_version: ['8.1', '8.5'] + fail-fast: false + env: + PHPRC: ${{ github.workspace }}/${{ github.event.repository.name }}/.phpstan-php-ini + steps: + - name: Checkout repository + uses: actions/checkout@v6 with: - path: ~/.composer/cache - key: php-composer-cache - - - run: composer install - - # Docker images prestashop/prestashop may be used, even if the shop remains uninstalled - - name: Execute PHPStan on PrestaShop (Tag ${{ matrix.presta-versions }}) - run: ./tests/phpstan.sh ${{ matrix.presta-versions }} + path: ${{ github.event.repository.name }} + + - name: Prepare PHP env for PrestaShop 9.1.x and later (define constants before any bootstrap) + run: | + mkdir -p ${{ github.event.repository.name }}/.phpstan-php-ini + { + echo "auto_prepend_file=$GITHUB_WORKSPACE/${{ github.event.repository.name }}/tests/php/phpstan/prepend-constants.php" + echo "memory_limit=512M" + } > ${{ github.event.repository.name }}/.phpstan-php-ini/php.ini + + - name: Run PHPStan + uses: PrestaShop/.github/.github/actions/php-ci/phpstan@master + with: + php-version: ${{ matrix.php_version }} + presta-version: ${{ matrix.presta_version }} + module-name: ${{ github.event.repository.name }} + phpstan-level: '5' + phpstan-config: tests/php/phpstan/phpstan-${{ matrix.presta_version }}.neon diff --git a/README.md b/README.md index d101197..d957b18 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Help your customers get in touch when they need, add a contact form on your stor ## Compatibility -PrestaShop: `1.7.2.0` or later +PrestaShop: `8.2.0` or later ## How to test diff --git a/config.xml b/config.xml index 1d29563..f4efaa3 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ contactform - + diff --git a/contactform.php b/contactform.php index 8866693..962ca28 100644 --- a/contactform.php +++ b/contactform.php @@ -54,7 +54,7 @@ public function __construct() $this->name = 'contactform'; $this->author = 'PrestaShop'; $this->tab = 'front_office_features'; - $this->version = '4.4.3'; + $this->version = '5.0.0'; $this->bootstrap = true; parent::__construct(); @@ -66,7 +66,7 @@ public function __construct() 'Modules.Contactform.Admin' ); $this->ps_versions_compliancy = [ - 'min' => '1.7.2.0', + 'min' => '8.2.0', 'max' => _PS_VERSION_, ]; } @@ -530,7 +530,16 @@ public function sendMessage() @chmod(_PS_UPLOAD_DIR_ . basename($file_attachment['rename']), 0664); } $cm->ip_address = (string) ip2long(Tools::getRemoteAddr()); - $cm->user_agent = $_SERVER['HTTP_USER_AGENT']; + + /* + * Adjust user agent length depending on PrestaShop version used. + * The limit was raised on 9.0.2. + */ + if (version_compare(_PS_VERSION_, '9.0.2', '>=')) { + $cm->user_agent = substr($_SERVER['HTTP_USER_AGENT'] ?? '', 0, 255); + } else { + $cm->user_agent = substr($_SERVER['HTTP_USER_AGENT'] ?? '', 0, 128); + } if (!$cm->add()) { $this->context->controller->errors[] = $this->trans( diff --git a/tests/phpstan/index.php b/tests/php/phpstan/index.php similarity index 100% rename from tests/phpstan/index.php rename to tests/php/phpstan/index.php diff --git a/tests/php/phpstan/phpstan-8.2.x.neon b/tests/php/phpstan/phpstan-8.2.x.neon new file mode 100644 index 0000000..b0db9cf --- /dev/null +++ b/tests/php/phpstan/phpstan-8.2.x.neon @@ -0,0 +1,6 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' diff --git a/tests/php/phpstan/phpstan-9.0.3.neon b/tests/php/phpstan/phpstan-9.0.3.neon new file mode 100644 index 0000000..a72bdeb --- /dev/null +++ b/tests/php/phpstan/phpstan-9.0.3.neon @@ -0,0 +1,7 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' + - '#Call to an undefined static method Tools\:\:stripslashes\(\).#' \ No newline at end of file diff --git a/tests/php/phpstan/phpstan-9.1.5.neon b/tests/php/phpstan/phpstan-9.1.5.neon new file mode 100644 index 0000000..a97b152 --- /dev/null +++ b/tests/php/phpstan/phpstan-9.1.5.neon @@ -0,0 +1,7 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' + - '#Call to an undefined static method Tools\:\:stripslashes\(\).#' diff --git a/tests/php/phpstan/phpstan-9.2.x.neon b/tests/php/phpstan/phpstan-9.2.x.neon new file mode 100644 index 0000000..a72bdeb --- /dev/null +++ b/tests/php/phpstan/phpstan-9.2.x.neon @@ -0,0 +1,7 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' + - '#Call to an undefined static method Tools\:\:stripslashes\(\).#' \ No newline at end of file diff --git a/tests/php/phpstan/phpstan-develop.neon b/tests/php/phpstan/phpstan-develop.neon new file mode 100644 index 0000000..a72bdeb --- /dev/null +++ b/tests/php/phpstan/phpstan-develop.neon @@ -0,0 +1,7 @@ +includes: + - %currentWorkingDirectory%/tests/php/phpstan/phpstan.neon + +parameters: + ignoreErrors: + - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' + - '#Call to an undefined static method Tools\:\:stripslashes\(\).#' \ No newline at end of file diff --git a/tests/php/phpstan/phpstan.neon b/tests/php/phpstan/phpstan.neon new file mode 100644 index 0000000..be11823 --- /dev/null +++ b/tests/php/phpstan/phpstan.neon @@ -0,0 +1,2 @@ + # Base PHPStan configuration for the moduleExpand commentComment on line R2ResolvedCode has comments. Press enter to view. + # This file is included by version-specific configs \ No newline at end of file diff --git a/tests/php/phpstan/prepend-constants.php b/tests/php/phpstan/prepend-constants.php new file mode 100644 index 0000000..733689a --- /dev/null +++ b/tests/php/phpstan/prepend-constants.php @@ -0,0 +1,11 @@ + given.#' - - '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array given.#' diff --git a/tests/phpstan/phpstan-1.7.3.4.neon b/tests/phpstan/phpstan-1.7.3.4.neon deleted file mode 100644 index f4b4198..0000000 --- a/tests/phpstan/phpstan-1.7.3.4.neon +++ /dev/null @@ -1,10 +0,0 @@ -includes: - - %currentWorkingDirectory%/tests/phpstan/phpstan.neon - -parameters: - ignoreErrors: - - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' - - '#Access to an undefined property Cookie\:\:\$contactFormTokenTTL.#' - - '#Call to method assign\(\) on an unknown class Smarty_Data.#' - - '#Parameter \#4 \$templateVars of static method MailCore\:\:send\(\) expects string, array given.#' - - '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array given.#' diff --git a/tests/phpstan/phpstan-1.7.4.4.neon b/tests/phpstan/phpstan-1.7.4.4.neon deleted file mode 100644 index 4bb3d01..0000000 --- a/tests/phpstan/phpstan-1.7.4.4.neon +++ /dev/null @@ -1,9 +0,0 @@ -includes: - - %currentWorkingDirectory%/tests/phpstan/phpstan.neon - -parameters: - ignoreErrors: - - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' - - '#Access to an undefined property Cookie\:\:\$contactFormTokenTTL.#' - - '#Parameter \#4 \$templateVars of static method MailCore\:\:send\(\) expects string, array given.#' - - '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array given.#' diff --git a/tests/phpstan/phpstan-1.7.5.1.neon b/tests/phpstan/phpstan-1.7.5.1.neon deleted file mode 100644 index 4bb3d01..0000000 --- a/tests/phpstan/phpstan-1.7.5.1.neon +++ /dev/null @@ -1,9 +0,0 @@ -includes: - - %currentWorkingDirectory%/tests/phpstan/phpstan.neon - -parameters: - ignoreErrors: - - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' - - '#Access to an undefined property Cookie\:\:\$contactFormTokenTTL.#' - - '#Parameter \#4 \$templateVars of static method MailCore\:\:send\(\) expects string, array given.#' - - '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array given.#' diff --git a/tests/phpstan/phpstan-1.7.6.neon b/tests/phpstan/phpstan-1.7.6.neon deleted file mode 100644 index 4bb3d01..0000000 --- a/tests/phpstan/phpstan-1.7.6.neon +++ /dev/null @@ -1,9 +0,0 @@ -includes: - - %currentWorkingDirectory%/tests/phpstan/phpstan.neon - -parameters: - ignoreErrors: - - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' - - '#Access to an undefined property Cookie\:\:\$contactFormTokenTTL.#' - - '#Parameter \#4 \$templateVars of static method MailCore\:\:send\(\) expects string, array given.#' - - '#Parameter \#1 \$hook_name of method ModuleCore\:\:registerHook\(\) expects string, array given.#' diff --git a/tests/phpstan/phpstan-1.7.7.neon b/tests/phpstan/phpstan-1.7.7.neon deleted file mode 100644 index 8b75660..0000000 --- a/tests/phpstan/phpstan-1.7.7.neon +++ /dev/null @@ -1,7 +0,0 @@ -includes: - - %currentWorkingDirectory%/tests/phpstan/phpstan.neon - -parameters: - ignoreErrors: - - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' - - '#Access to an undefined property Cookie\:\:\$contactFormTokenTTL.#' diff --git a/tests/phpstan/phpstan-1.7.8.neon b/tests/phpstan/phpstan-1.7.8.neon deleted file mode 100644 index 8b75660..0000000 --- a/tests/phpstan/phpstan-1.7.8.neon +++ /dev/null @@ -1,7 +0,0 @@ -includes: - - %currentWorkingDirectory%/tests/phpstan/phpstan.neon - -parameters: - ignoreErrors: - - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' - - '#Access to an undefined property Cookie\:\:\$contactFormTokenTTL.#' diff --git a/tests/phpstan/phpstan-latest.neon b/tests/phpstan/phpstan-latest.neon deleted file mode 100644 index 8b75660..0000000 --- a/tests/phpstan/phpstan-latest.neon +++ /dev/null @@ -1,7 +0,0 @@ -includes: - - %currentWorkingDirectory%/tests/phpstan/phpstan.neon - -parameters: - ignoreErrors: - - '#Access to an undefined property Cookie\:\:\$contactFormToken.#' - - '#Access to an undefined property Cookie\:\:\$contactFormTokenTTL.#' diff --git a/tests/phpstan/phpstan.neon b/tests/phpstan/phpstan.neon deleted file mode 100644 index 0c6cd2a..0000000 --- a/tests/phpstan/phpstan.neon +++ /dev/null @@ -1,11 +0,0 @@ -includes: - - %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon - -parameters: - paths: - # From PHPStan 0.12, paths to check are relative to the neon file - - ../../contactform.php - - ../../upgrade/ - ignoreErrors: - reportUnmatchedIgnoredErrors: false - level: 5 diff --git a/views/templates/widget/contactform.tpl b/views/templates/widget/contactform.tpl index 6a5c14a..40ebfc6 100644 --- a/views/templates/widget/contactform.tpl +++ b/views/templates/widget/contactform.tpl @@ -47,15 +47,19 @@ {if !$notifications || $notifications.nw_error}
- - + {if $contact.contacts|count === 1} + {assign var=firstContact value=current($contact.contacts)} + + {else} + + {/if}