From f54ef3672c2ba8de8adb09c81c87d898e811117e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Wed, 18 Dec 2024 12:03:43 +0100 Subject: [PATCH 1/5] chore: version is not required anymore in docker compose files --- .ddev/docker-compose.magento-volumes.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.ddev/docker-compose.magento-volumes.yaml b/.ddev/docker-compose.magento-volumes.yaml index 3dd6b0044..4752e8bd3 100644 --- a/.ddev/docker-compose.magento-volumes.yaml +++ b/.ddev/docker-compose.magento-volumes.yaml @@ -1,4 +1,3 @@ -version: '3.6' services: web: volumes: From cb44d85777a8774ca09f167313351db808abe2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Wed, 18 Dec 2024 12:04:17 +0100 Subject: [PATCH 2/5] backport: phar build of n98-magerun2 --- .gitignore | 2 + box.json.dist | 23 ++++ build.sh | 221 ++++++++++++++++---------------- composer.json | 1 - composer.lock | 116 +---------------- src/N98/Magento/Application.php | 2 +- 6 files changed, 136 insertions(+), 229 deletions(-) create mode 100644 box.json.dist diff --git a/.gitignore b/.gitignore index 7ed515f85..5ae6f0a2c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ /n98-magerun.phar.asc /build/output/ /build/vendor/ +/*.phar +composer-setup.php # Magerun stopfile /.n98-magerun diff --git a/box.json.dist b/box.json.dist new file mode 100644 index 000000000..1723adfce --- /dev/null +++ b/box.json.dist @@ -0,0 +1,23 @@ +{ + "compression": "GZ", + "algorithm": "SHA512", + "datetime": "release-date", + "files": [ + "config.yaml", + "src/bootstrap.php", + "vendor/composer/installed.php" + ], + "force-autodiscovery": true, + "directories": [ + "src", + "res", + "vendor/rmccue/requests/certificates", + "vendor/twig/twig/src" + ], + "replacements": { + "application_name": "n98-magerun" + }, + "git-commit-short": "git_commit_short", + "stub": "build/phar/_cli_stub.php", + "output": "n98-magerun.phar" +} diff --git a/build.sh b/build.sh index bdc897dd7..c1d747412 100755 --- a/build.sh +++ b/build.sh @@ -2,126 +2,121 @@ # # build from clean checkout # -# usage: ./build.sh [--changes] -# -# options: --changes build with local changes -# -# note: run from project root -# +# usage: ./build.sh from project root set -euo pipefail + IFS=$'\n\t' +PHP_BIN="php" +BOX_BIN="./box.phar" +PHAR_OUTPUT_FILE="./n98-magerun.phar" +COMPOSER_BIN="composer" + +function system_setup() { + if [ "$(uname -s)" != "Darwin" ]; then + ulimit -Sn $(ulimit -Hn) + fi +} + +function check_dependencies() { + DEPENDENCY_ERROR=false + + if command -v curl &>/dev/null; then + echo "curl found" + else + echo "curl not found!" + DEPENDENCY_ERROR=true + fi + + if command -v git &>/dev/null; then + echo "git found" + else + echo "git not found!" + DEPENDENCY_ERROR=true + fi + + if command -v $PHP_BIN &>/dev/null; then + echo "php found" + else + echo "php not found!" + DEPENDENCY_ERROR=true + fi + + if [ $DEPENDENCY_ERROR = true ]; then + echo "Some dependecies are not found. Cannot build." + exit 1 + fi + +} -remove_assume_unchanged() { - local git_dir="${1}" - local path="${2}" - ( - cd "${git_dir}" - rm -f "${path}" - git update-index --assume-unchanged -- "${path}" - ) +function download_box() { + if [ ! -f box.phar ]; then + curl -L https://github.com/box-project/box/releases/download/3.16.0/box.phar -o $BOX_BIN + chmod +x ./box.phar + fi } -exit_trap() { - local status=$? - if [[ -d "${base_dir:?}/${build_dir}" ]]; then - echo "trap: removing '${build_dir}'.." - rm -rf "${base_dir:?}/${build_dir}" +function download_composer() { + if command -v composer &>/dev/null; then + true; # do nothing + else + echo "Composer was not found. Try to install it ..." + # install composer + $PHP_BIN -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" + $PHP_BIN composer-setup.php --install-dir=/usr/local/bin --filename=composer + if [ -f "./composer-setup.php" ]; then + rm "./composer-setup.php"; + fi fi - echo "exit ($status)." } -name="$(awk '/&2 echo "Error: Can not remove build-dir '${build_dir}'" - echo "aborting." - exit 1 -fi -mkdir "${build_dir}" -if [[ ! -d "${build_dir}" ]]; then - >&2 echo "Error: Can not create build-dir '${build_dir}'" - echo "aborting." - exit 1 -fi - -git clone --quiet --no-local --depth 1 -- . "${build_dir}" - -# --changes : incorporate changes into the build, w/o builds latest revision -if [[ "${1-}" == "--changes" ]]; then - echo "apply changes and copy untracked files..." - git diff HEAD | (cd "${build_dir}" && git apply) - # copy over files that are not tracked - git status --porcelain | awk 'match($1, "\\?\\?"){print "cp " $2 " '"${build_dir}"'/" $2}' | sh - (cd "${build_dir}" && git status --short) -fi - -# remove fake-phar directly after clone -remove_assume_unchanged "${build_dir}" "n98-magerun.phar" - -composer_bin="composer" -phing_bin="${base_dir}/vendor/bin/phing" - -# Set COMPOSER_HOME if HOME and COMPOSER_HOME not set (shell with no home-dir, e.g. build server with webhook) -if [[ -z ${HOME+x} && -z ${COMPOSER_HOME+x} ]]; then - echo "provision: create COMPOSER_HOME directory for composer (no HOME)" - mkdir -p "build/composer-home" - export COMPOSER_HOME - COMPOSER_HOME="$(pwd -P)/build/composer-home" -fi - -echo "with: $(php --version|head -n 1)" -echo "with: $("${composer_bin}" --version)" -echo "with: $("${phing_bin}" -version)" - -cd "${build_dir}" - -echo "building in $(pwd -P)" -echo "build version: $(git --no-pager log --oneline -1)" - -echo "provision: ulimits (soft) set from $(ulimit -Sn) to $(ulimit -Hn) (hard) for faster phar builds..." -ulimit -Sn "$(ulimit -Hn)" -timestamp="$(git log --format=format:%ct HEAD -1)" # reproduceable build -echo "build timestamp: ${timestamp}" - -if command -v composer &>/dev/null; then - true; # do nothing -else - echo "Composer was not found. Try to install it ..." - # install composer - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" - php composer-setup.php --install-dir=/usr/local/bin --filename=composer -fi - -php -f "${phing_bin}" -dphar.readonly=0 -- \ - -Dcomposer_suffix="${nice_name}${timestamp}" \ - -Dcomposer_bin="${composer_bin}" \ - dist_clean - -LAST_COMMIT_TIMESTAMP="$(git log --format=format:%ct HEAD -1)" - -php -f "${phar}" -- --version -ls -al "${phar}" - -cd - -cp -vp "${build_dir}"/"${phar}" "${phar}" -rm -rf "${build_dir}" - -php -f build/phar/phar-timestamp.php -- $LAST_COMMIT_TIMESTAMP - -trap - EXIT +function find_commit_timestamp() { + LAST_COMMIT_TIMESTAMP="$(git log --format=format:%ct HEAD -1)" # reproducible build +} + +function create_new_phar() { + # set composer suffix, otherwise Composer will generate a file with a unique identifier + # which will then create a no reproducable phar file with a differenz MD5 + $COMPOSER_BIN config autoloader-suffix N98MagerunNTS + + # Run install again to get the latest install.php and install.json file + $COMPOSER_BIN install + + $PHP_BIN $BOX_BIN compile + + # unset composer suffix + $COMPOSER_BIN config autoloader-suffix --unset + + # Set timestamp of newly generted phar file to the commit timestamp + $PHP_BIN -f build/phar/phar-timestamp.php -- $LAST_COMMIT_TIMESTAMP + + # Run a signature verification after the timestamp manipulation + $PHP_BIN $BOX_BIN verify $PHAR_OUTPUT_FILE + + # make phar executable + chmod +x $PHAR_OUTPUT_FILE + + # Print version of new phar file which is also a test + $PHP_BIN -f $PHAR_OUTPUT_FILE -- --version + + # List new phar file for debugging + ls -al "$PHAR_OUTPUT_FILE" +} + +function print_info_before_build() { + echo "with: $($PHP_BIN --version | head -n 1)" + echo "with: $("${COMPOSER_BIN}" --version)" + echo "with: $("${BOX_BIN}" --version)" + echo "build version: $(git --no-pager log --oneline -1)" + echo "last commit timestamp: ${LAST_COMMIT_TIMESTAMP}" + echo "provision: ulimits (soft) set from $(ulimit -Sn) to $(ulimit -Hn) (hard) for faster phar builds..." +} + +check_dependencies +system_setup +download_box +download_composer +find_commit_timestamp +print_info_before_build +create_new_phar echo "done." diff --git a/composer.json b/composer.json index fcd1c9850..174846ace 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,6 @@ "composer/composer": "^2.7", "friendsofphp/php-cs-fixer": "^3.4", "mikey179/vfsstream": "^1.6", - "phing/phing": "~2.17.0", "phpunit/phpunit": "^9", "rector/rector": "^1.0.0", "seld/phar-utils": "~1.2.0" diff --git a/composer.lock b/composer.lock index 861da0784..d6aa6e90e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2e4eb914eaf242ad8e42ec4efa3b51ee", + "content-hash": "38b6d725fc494fead5c61c767107f0e5", "packages": [ { "name": "fakerphp/faker", @@ -3357,118 +3357,6 @@ }, "time": "2022-02-21T01:04:05+00:00" }, - { - "name": "phing/phing", - "version": "2.17.4", - "source": { - "type": "git", - "url": "https://github.com/phingofficial/phing.git", - "reference": "9f3bc8c72e65452686dcf64497e02a082f138908" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phingofficial/phing/zipball/9f3bc8c72e65452686dcf64497e02a082f138908", - "reference": "9f3bc8c72e65452686dcf64497e02a082f138908", - "shasum": "" - }, - "require": { - "php": ">=5.2.0" - }, - "require-dev": { - "ext-pdo_sqlite": "*", - "mikey179/vfsstream": "^1.6", - "pdepend/pdepend": "2.x", - "pear/archive_tar": "1.4.x", - "pear/http_request2": "dev-trunk", - "pear/net_growl": "dev-trunk", - "pear/pear-core-minimal": "1.10.1", - "pear/versioncontrol_git": "@dev", - "pear/versioncontrol_svn": "~0.5", - "phpdocumentor/phpdocumentor": "2.x", - "phploc/phploc": "~2.0.6", - "phpmd/phpmd": "~2.2", - "phpunit/phpunit": ">=3.7", - "sebastian/git": "~1.0", - "sebastian/phpcpd": "2.x", - "siad007/versioncontrol_hg": "^1.0", - "simpletest/simpletest": "^1.1", - "squizlabs/php_codesniffer": "~2.2", - "symfony/yaml": "^2.8 || ^3.1 || ^4.0" - }, - "suggest": { - "pdepend/pdepend": "PHP version of JDepend", - "pear/archive_tar": "Tar file management class", - "pear/versioncontrol_git": "A library that provides OO interface to handle Git repository", - "pear/versioncontrol_svn": "A simple OO-style interface for Subversion, the free/open-source version control system", - "phpdocumentor/phpdocumentor": "Documentation Generator for PHP", - "phploc/phploc": "A tool for quickly measuring the size of a PHP project", - "phpmd/phpmd": "PHP version of PMD tool", - "phpunit/php-code-coverage": "Library that provides collection, processing, and rendering functionality for PHP code coverage information", - "phpunit/phpunit": "The PHP Unit Testing Framework", - "sebastian/phpcpd": "Copy/Paste Detector (CPD) for PHP code", - "siad007/versioncontrol_hg": "A library for interfacing with Mercurial repositories.", - "tedivm/jshrink": "Javascript Minifier built in PHP" - }, - "bin": [ - "bin/phing" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.16.x-dev" - } - }, - "autoload": { - "classmap": [ - "classes/phing/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "classes" - ], - "license": [ - "LGPL-3.0-only" - ], - "authors": [ - { - "name": "Michiel Rook", - "email": "mrook@php.net" - }, - { - "name": "Phing Community", - "homepage": "https://www.phing.info/trac/wiki/Development/Contributors" - } - ], - "description": "PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.", - "homepage": "https://www.phing.info/", - "keywords": [ - "build", - "phing", - "task", - "tool" - ], - "support": { - "irc": "irc://irc.freenode.net/phing", - "issues": "https://www.phing.info/trac/report", - "source": "https://github.com/phingofficial/phing/tree/2.17.4" - }, - "funding": [ - { - "url": "https://github.com/mrook", - "type": "github" - }, - { - "url": "https://github.com/siad007", - "type": "github" - }, - { - "url": "https://www.patreon.com/michielrook", - "type": "patreon" - } - ], - "time": "2022-07-08T09:07:07+00:00" - }, { "name": "phpstan/phpstan", "version": "1.12.9", @@ -5975,7 +5863,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/N98/Magento/Application.php b/src/N98/Magento/Application.php index f1007c4c4..4dcf43199 100644 --- a/src/N98/Magento/Application.php +++ b/src/N98/Magento/Application.php @@ -39,7 +39,7 @@ class Application extends BaseApplication /** * @var string */ - public const APP_NAME = 'n98-magerun'; + public const APP_NAME = '@application_name@'; /** * @var string From 8eb3ae614cc0441f4ac31edb35b7c9e935972d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Wed, 18 Dec 2024 12:19:34 +0100 Subject: [PATCH 3/5] fix: set default app name --- src/N98/Magento/Application.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/N98/Magento/Application.php b/src/N98/Magento/Application.php index 4dcf43199..831143d80 100644 --- a/src/N98/Magento/Application.php +++ b/src/N98/Magento/Application.php @@ -144,7 +144,14 @@ class Application extends BaseApplication public function __construct($autoloader = null) { $this->autoloader = $autoloader; - parent::__construct(self::APP_NAME, self::APP_VERSION); + + $appName = self::APP_NAME; + + if (strpos($appName, 'application_name') !== false) { + $appName = 'n98-magerun'; + } + + parent::__construct($appName, self::APP_VERSION); } /** From 3cadb9d6d6d94da36c9993f9bd16be4906bf3a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Wed, 18 Dec 2024 12:30:14 +0100 Subject: [PATCH 4/5] fix: phpstan issues with wrong imported classes --- src/N98/Magento/Command/Config/GetCommand.php | 3 +-- src/N98/Magento/Command/Database/AbstractShowCommand.php | 3 +-- .../Magento/Command/Developer/EmailTemplate/UsageCommand.php | 3 +-- src/N98/Magento/Command/Developer/Theme/InfoCommand.php | 3 +-- src/N98/Magento/Command/Script/Repository/ListCommand.php | 4 +--- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/N98/Magento/Command/Config/GetCommand.php b/src/N98/Magento/Command/Config/GetCommand.php index 84083d8d8..6b0bbfb72 100644 --- a/src/N98/Magento/Command/Config/GetCommand.php +++ b/src/N98/Magento/Command/Config/GetCommand.php @@ -2,7 +2,6 @@ namespace N98\Magento\Command\Config; -use Path; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -139,7 +138,7 @@ protected function renderAsTable(OutputInterface $output, $table, $format) $tableHelper = $this->getTableHelper(); $tableHelper - ->setHeaders([Path::class, 'Scope', 'Scope-ID', 'Value']) + ->setHeaders(['Path', 'Scope', 'Scope-ID', 'Value']) ->setRows($formattedTable) ->renderByFormat($output, $formattedTable, $format); } diff --git a/src/N98/Magento/Command/Database/AbstractShowCommand.php b/src/N98/Magento/Command/Database/AbstractShowCommand.php index 46a59a3bb..016371daa 100644 --- a/src/N98/Magento/Command/Database/AbstractShowCommand.php +++ b/src/N98/Magento/Command/Database/AbstractShowCommand.php @@ -2,7 +2,6 @@ namespace N98\Magento\Command\Database; -use Description; use N98\Util\Filesystem; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -92,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int false === $this->_input->getOption('no-description'); $header = ['Variable Name', 'Value']; if (true === $hasDescription) { - $header[] = Description::class; + $header[] = 'Description'; } $this->renderTable($header, $this->generateRows($outputVars, $hasDescription)); diff --git a/src/N98/Magento/Command/Developer/EmailTemplate/UsageCommand.php b/src/N98/Magento/Command/Developer/EmailTemplate/UsageCommand.php index 9e69760ef..d4d9079db 100644 --- a/src/N98/Magento/Command/Developer/EmailTemplate/UsageCommand.php +++ b/src/N98/Magento/Command/Developer/EmailTemplate/UsageCommand.php @@ -6,7 +6,6 @@ use Mage_Adminhtml_Model_Email_Template; use Mage_Core_Model_Template; use N98\Magento\Command\AbstractMagentoCommand; -use Path; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -43,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!empty($templates)) { $tableHelper = $this->getTableHelper(); $tableHelper - ->setHeaders(['id', 'Name', 'Scope', 'Scope Id', Path::class]) + ->setHeaders(['id', 'Name', 'Scope', 'Scope Id', 'Path']) ->renderByFormat($output, $templates, $input->getOption('format')); } else { $output->writeln('No transactional email templates stored in the database.'); diff --git a/src/N98/Magento/Command/Developer/Theme/InfoCommand.php b/src/N98/Magento/Command/Developer/Theme/InfoCommand.php index cf70668d4..77b8a3c01 100644 --- a/src/N98/Magento/Command/Developer/Theme/InfoCommand.php +++ b/src/N98/Magento/Command/Developer/Theme/InfoCommand.php @@ -6,7 +6,6 @@ use Mage_Core_Model_Store; use N98\Magento\Command\AbstractMagentoCommand; use N98\Magento\Command\AbstractMagentoStoreConfigCommand; -use Parameter; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -69,7 +68,7 @@ protected function _displayTable(OutputInterface $output, Mage_Core_Model_Store $tableHelper = $this->getTableHelper(); $tableHelper - ->setHeaders([Parameter::class, 'Value']) + ->setHeaders(['Parameter', 'Value']) ->renderByFormat($output, $storeInfoLines); return $this; diff --git a/src/N98/Magento/Command/Script/Repository/ListCommand.php b/src/N98/Magento/Command/Script/Repository/ListCommand.php index 87e005a2e..0ed4eb797 100644 --- a/src/N98/Magento/Command/Script/Repository/ListCommand.php +++ b/src/N98/Magento/Command/Script/Repository/ListCommand.php @@ -2,8 +2,6 @@ namespace N98\Magento\Command\Script\Repository; -use Description; -use Location; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -66,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $tableHelper = $this->getTableHelper(); $tableHelper - ->setHeaders(['Script', Location::class, Description::class]) + ->setHeaders(['Script', 'Location', 'Description']) ->renderByFormat($output, $table, $input->getOption('format')); return 0; } From 63a9d8ac87ef946446692302b4245ee639b22c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Wed, 18 Dec 2024 12:35:27 +0100 Subject: [PATCH 5/5] fix: remove wrong "Path" class constant --- .../Developer/EmailTemplate/UsageCommand.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/N98/Magento/Command/Developer/EmailTemplate/UsageCommand.php b/src/N98/Magento/Command/Developer/EmailTemplate/UsageCommand.php index d4d9079db..49bea5df3 100644 --- a/src/N98/Magento/Command/Developer/EmailTemplate/UsageCommand.php +++ b/src/N98/Magento/Command/Developer/EmailTemplate/UsageCommand.php @@ -71,11 +71,21 @@ protected function findEmailTemplates() $configPaths = $template->getSystemConfigPathsWhereUsedCurrently(); if (!(is_countable($configPaths) ? count($configPaths) : 0)) { - $configPaths[] = ['scope' => 'Unused', 'scope_id' => 'Unused', 'path' => 'Unused']; + $configPaths[] = [ + 'scope' => 'Unused', + 'scope_id' => 'Unused', + 'path' => 'Unused', + ]; } foreach ($configPaths as $configPath) { - $return[] = ['id' => $this->sanitizeEmailProperty($template->getId()), 'Template Code' => $this->sanitizeEmailProperty($template->getTemplateCode()), 'Scope' => $this->sanitizeEmailProperty($configPath['scope']), 'Scope Id' => $this->sanitizeEmailProperty($configPath['scope_id']), Path::class => $this->sanitizeEmailProperty($configPath['path'])]; + $return[] = [ + 'id' => $this->sanitizeEmailProperty((string) $template->getId()), + 'Template Code' => $this->sanitizeEmailProperty($template->getTemplateCode()), + 'Scope' => $this->sanitizeEmailProperty($configPath['scope']), + 'Scope Id' => $this->sanitizeEmailProperty($configPath['scope_id']), + 'Path' => $this->sanitizeEmailProperty($configPath['path']), + ]; } }