diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 00000000..ff3772b5
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,4 @@
+### Checklist
+ - [ ] Pull request has a meaningful description of its purpose
+ - [ ] All commits are accompanied by meaningful commit messages
+ - [ ] Tests have been ran / updated
diff --git a/.gitignore b/.gitignore
index b8673c13..7b0c8337 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
/.idea
/vendor/
+dev/instances/magento*
+dev/output/actual/*
\ No newline at end of file
diff --git a/README.md b/README.md
index 878b93f1..000f3b86 100644
--- a/README.md
+++ b/README.md
@@ -5,16 +5,27 @@ Helper scripts to aid upgrading magento 2 websites
This tool checks for
- Preferences
- Overrides
+ - phtml / js
+ - layout xml
+
+## ⚠️ Warning ⚠️
+
+This tool is experimental and a work in progress. It will not catch every preference/override/etc.
+
+If you have any improvements please raise a PR or an Issue.
+
+Look for todo's in the code base.
## How to use
All the below should be used on a local setup, never do any of this anywhere near a production website.
-### Step 1 - Update the Magento core and dependencies then generate a diff
+### Step 1 - Update the Magento core with dependencies then generate a patch
In your project `composer install` and move the original vendor directory to a backup location
```
+cd /path/to/magento2/
composer install
mv vendor/ vendor_orig/
```
@@ -36,24 +47,42 @@ Once you have a completed the composer steps you can create a diff which can be
diff -ur vendor_orig/ vendor/ > vendor.patch
```
-### Step 2 - Parse the diff file
+### Step 2 - Parse the patch file
-In a clone of this repository you can analyze the project and patch file.
+In a clone of this repository you can analyse the project and patch file.
```php
git clone https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper
+cd ampersand-magento2-upgrade-patch-helper
composer install
php bin/patch-helper.php analyse /path/to/magento2/
```
-This will output a grid like follows
+This will output a grid of files which have overrides/preferences that need to be reviewed and possibly updated to match the patch file.
+
```
-TODO
++---------------------------------------------------------------------------------------+---------------------------------------------+
+| Core file | Preference |
++---------------------------------------------------------------------------------------+---------------------------------------------+
+| vendor/magento/module-advanced-pricing-import-export/Model/Export/AdvancedPricing.php | Ampersand\Test\Model\Export\AdvancedPricing |
++---------------------------------------------------------------------------------------+---------------------------------------------+
++-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+
+| Core file | Override (phtml/js) |
++-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+
+| vendor/magento/module-customer/view/frontend/templates/account/dashboard/info.phtml | app/design/frontend/Ampersand/theme/Magento_Customer/templates/account/dashboard/info.phtml |
+| vendor/magento/module-customer/view/frontend/web/js/model/authentication-popup.js | app/design/frontend/Ampersand/theme/Magento_Customer/web/js/model/authentication-popup.js |
++-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+
++------------------------------------------------------------------------+--------------------------------------------------------------------------------+
+| Core file | Override/extended (layout xml) |
++------------------------------------------------------------------------+--------------------------------------------------------------------------------+
+| vendor/magento/module-sales/view/frontend/layout/sales_order_print.xml | app/design/frontend/Ampersand/theme/Magento_Sales/layout/sales_order_print.xml |
++------------------------------------------------------------------------+--------------------------------------------------------------------------------+
```
-## Warnings
-This tool is experimental and a work in progress. It may not catch every preference/override/etc.
+## Tests
+
+Have a look in the `./dev/Makefile` to see how the tests work.
-Any problems raise a PR or an Issue.
\ No newline at end of file
+They do not run automatically in travis as you cannot run `composer create-project --repository-url=https://repo.magento.com/` without providing and exposing an access token to the world.
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 56365785..be3dfef2 100644
--- a/composer.json
+++ b/composer.json
@@ -10,7 +10,8 @@
}
],
"require": {
- "symfony/console": "^3.4"
+ "symfony/console": "^3.4",
+ "php": "~7.1"
},
"autoload": {
"classmap": ["src/"],
diff --git a/dev/Makefile b/dev/Makefile
new file mode 100644
index 00000000..4402e0b7
--- /dev/null
+++ b/dev/Makefile
@@ -0,0 +1,16 @@
+list: # Lists all available commands, the default command when running `make` with no arguments
+ grep -v -e "^\t" Makefile | grep . | awk -F":.+?#" '{ print $$1 " #" $$2 }' | column -t -s '#'
+
+configure-magento-2-1: # Install magento 2.1 with the test module, and create vendor.patch for analysis
+ ./setup-magento-with-diff.sh 2.1.13 2.1.16 21
+
+test-magento-2-1: # Analyse 2.1 with vendor.patch
+ php ../bin/patch-helper.php analyse $(shell pwd)/instances/magento21 > output/actual/magento21.out.txt
+ diff output/expected/magento21.out.txt output/actual/magento21.out.txt
+
+configure-magento-2-2: # Install magento 2.2 with the test module, and create vendor.patch for analysis
+ ./setup-magento-with-diff.sh 2.2.5 2.2.6 22
+
+test-magento-2-2: # Analyse 2.2 with vendor.patch
+ php ../bin/patch-helper.php analyse $(shell pwd)/instances/magento22 > output/actual/magento22.out.txt
+ diff output/expected/magento22.out.txt output/actual/magento22.out.txt
diff --git a/dev/TestModule/app/code/Ampersand/Test/Model/Admin/Directpost.php b/dev/TestModule/app/code/Ampersand/Test/Model/Admin/Directpost.php
new file mode 100644
index 00000000..e9dcd97d
--- /dev/null
+++ b/dev/TestModule/app/code/Ampersand/Test/Model/Admin/Directpost.php
@@ -0,0 +1,7 @@
+themeProvider = $themeProvider;
+ $this->themeConfig = $themeConfig;
+ $this->themeFactory = $themeFactory;
+ $this->cache = $cache;
+ }
+
+ /**
+ * Upgrades data for a module
+ * @param ModuleDataSetupInterface $setup
+ * @param ModuleContextInterface $context
+ * @return void
+ */
+ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
+ {
+ if (version_compare($context->getVersion(), '1.0.0', '<')) {
+ /** @var \Magento\Theme\Model\Theme $theme */
+ $theme = $this->themeProvider->getThemeByFullPath('frontend/Ampersand/theme');
+ $this->themeConfig->assignToStore($theme, [1]);
+ $this->cache->clean();
+ }
+ }
+}
\ No newline at end of file
diff --git a/dev/TestModule/app/code/Ampersand/Test/etc/adminhtml/di.xml b/dev/TestModule/app/code/Ampersand/Test/etc/adminhtml/di.xml
new file mode 100644
index 00000000..40b44c5f
--- /dev/null
+++ b/dev/TestModule/app/code/Ampersand/Test/etc/adminhtml/di.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/TestModule/app/code/Ampersand/Test/etc/frontend/di.xml b/dev/TestModule/app/code/Ampersand/Test/etc/frontend/di.xml
new file mode 100644
index 00000000..fd80ed79
--- /dev/null
+++ b/dev/TestModule/app/code/Ampersand/Test/etc/frontend/di.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/TestModule/app/code/Ampersand/Test/etc/module.xml b/dev/TestModule/app/code/Ampersand/Test/etc/module.xml
new file mode 100644
index 00000000..f1e2bb8d
--- /dev/null
+++ b/dev/TestModule/app/code/Ampersand/Test/etc/module.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dev/TestModule/app/code/Ampersand/Test/registration.php b/dev/TestModule/app/code/Ampersand/Test/registration.php
new file mode 100644
index 00000000..f2e8e044
--- /dev/null
+++ b/dev/TestModule/app/code/Ampersand/Test/registration.php
@@ -0,0 +1,7 @@
+getPath(ComponentRegistrar::MODULE, 'Ampersand_Test') === null) {
+ ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Ampersand_Test', __DIR__);
+}
\ No newline at end of file
diff --git a/dev/TestModule/app/design/frontend/Ampersand/theme/Magento_Customer/templates/account/dashboard/info.phtml b/dev/TestModule/app/design/frontend/Ampersand/theme/Magento_Customer/templates/account/dashboard/info.phtml
new file mode 100644
index 00000000..e69de29b
diff --git a/dev/TestModule/app/design/frontend/Ampersand/theme/Magento_Customer/web/js/model/authentication-popup.js b/dev/TestModule/app/design/frontend/Ampersand/theme/Magento_Customer/web/js/model/authentication-popup.js
new file mode 100644
index 00000000..e69de29b
diff --git a/dev/TestModule/app/design/frontend/Ampersand/theme/Magento_Sales/layout/sales_order_print.xml b/dev/TestModule/app/design/frontend/Ampersand/theme/Magento_Sales/layout/sales_order_print.xml
new file mode 100644
index 00000000..e69de29b
diff --git a/dev/TestModule/app/design/frontend/Ampersand/theme/etc/view.xml b/dev/TestModule/app/design/frontend/Ampersand/theme/etc/view.xml
new file mode 100644
index 00000000..f5450ba6
--- /dev/null
+++ b/dev/TestModule/app/design/frontend/Ampersand/theme/etc/view.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/dev/TestModule/app/design/frontend/Ampersand/theme/registration.php b/dev/TestModule/app/design/frontend/Ampersand/theme/registration.php
new file mode 100644
index 00000000..b08e377d
--- /dev/null
+++ b/dev/TestModule/app/design/frontend/Ampersand/theme/registration.php
@@ -0,0 +1,9 @@
+
+
+ Ampersand Theme
+ Magento/luma
+
diff --git a/dev/instances/.gitkeep b/dev/instances/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/dev/output/actual/.gitkeep b/dev/output/actual/.gitkeep
new file mode 100644
index 00000000..e69de29b
diff --git a/dev/output/expected/magento21.out.txt b/dev/output/expected/magento21.out.txt
new file mode 100644
index 00000000..9a121c87
--- /dev/null
+++ b/dev/output/expected/magento21.out.txt
@@ -0,0 +1,16 @@
++---------------------------------------------------------+---------------------------------+
+| Core file | Preference |
++---------------------------------------------------------+---------------------------------+
+| vendor/magento/module-authorizenet/Model/Directpost.php | Ampersand\Test\Model\Directpost |
++---------------------------------------------------------+---------------------------------+
++-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+
+| Core file | Override (phtml/js) |
++-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+
+| vendor/magento/module-customer/view/frontend/templates/account/dashboard/info.phtml | app/design/frontend/Ampersand/theme/Magento_Customer/templates/account/dashboard/info.phtml |
+| vendor/magento/module-customer/view/frontend/web/js/model/authentication-popup.js | app/design/frontend/Ampersand/theme/Magento_Customer/web/js/model/authentication-popup.js |
++-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+
++------------------------------------------------------------------------+--------------------------------------------------------------------------------+
+| Core file | Override/extended (layout xml) |
++------------------------------------------------------------------------+--------------------------------------------------------------------------------+
+| vendor/magento/module-sales/view/frontend/layout/sales_order_print.xml | app/design/frontend/Ampersand/theme/Magento_Sales/layout/sales_order_print.xml |
++------------------------------------------------------------------------+--------------------------------------------------------------------------------+
diff --git a/dev/output/expected/magento22.out.txt b/dev/output/expected/magento22.out.txt
new file mode 100644
index 00000000..e0f59de4
--- /dev/null
+++ b/dev/output/expected/magento22.out.txt
@@ -0,0 +1,17 @@
++---------------------------------------------------------------------------------------+---------------------------------------------+
+| Core file | Preference |
++---------------------------------------------------------------------------------------+---------------------------------------------+
+| vendor/magento/module-advanced-pricing-import-export/Model/Export/AdvancedPricing.php | Ampersand\Test\Model\Export\AdvancedPricing |
+| vendor/magento/module-authorizenet/Model/Directpost.php | Ampersand\Test\Model\Directpost |
++---------------------------------------------------------------------------------------+---------------------------------------------+
++-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+
+| Core file | Override (phtml/js) |
++-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+
+| vendor/magento/module-customer/view/frontend/templates/account/dashboard/info.phtml | app/design/frontend/Ampersand/theme/Magento_Customer/templates/account/dashboard/info.phtml |
+| vendor/magento/module-customer/view/frontend/web/js/model/authentication-popup.js | app/design/frontend/Ampersand/theme/Magento_Customer/web/js/model/authentication-popup.js |
++-------------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------+
++------------------------------------------------------------------------+--------------------------------------------------------------------------------+
+| Core file | Override/extended (layout xml) |
++------------------------------------------------------------------------+--------------------------------------------------------------------------------+
+| vendor/magento/module-sales/view/frontend/layout/sales_order_print.xml | app/design/frontend/Ampersand/theme/Magento_Sales/layout/sales_order_print.xml |
++------------------------------------------------------------------------+--------------------------------------------------------------------------------+
diff --git a/dev/setup-magento-with-diff.sh b/dev/setup-magento-with-diff.sh
new file mode 100755
index 00000000..0ce35125
--- /dev/null
+++ b/dev/setup-magento-with-diff.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+set -e
+
+FROM=$1
+TO=$2
+ID=$3
+
+#rm -rf ./instances/magento$ID
+#mysql -hlocalhost -uroot -e "drop database testmagento$ID;"
+mysql -hlocalhost -uroot -e "create database testmagento$ID;"
+
+composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=$FROM ./instances/magento$ID/
+cd instances/magento$ID/
+composer install
+
+# Backup vendor and upgrade magento
+mv vendor/ vendor_orig/
+composer install
+composer require magento/product-community-edition $TO --no-update
+composer update composer/composer magento/product-community-edition --with-dependencies
+composer install
+
+# Install test module and theme
+cd -
+cp -r TestModule/app/code ./instances/magento$ID/app/
+cp -r TestModule/app/design/frontend/Ampersand ./instances/magento$ID/app/design/frontend/
+cd -
+
+# Install magento
+php -d memory_limit=1024M bin/magento setup:install \
+ --admin-firstname=ampersand --admin-lastname=developer --admin-email=example@example.com \
+ --admin-user=admin --admin-password=somepass123 \
+ --db-name=testmagento$ID --db-user=root --db-host=127.0.0.1\
+ --backend-frontname=admin \
+ --base-url=https://magento-$ID-develop.localhost/ \
+ --language=en_GB --currency=GBP --timezone=Europe/London \
+ --use-rewrites=1;
+
+# Generate patch file for analysis
+diff -ur vendor_orig/ vendor/ > vendor.patch || true
+
+cd -
+set +e
\ No newline at end of file
diff --git a/src/Ampersand/PatchHelper/Command/AnalyseCommand.php b/src/Ampersand/PatchHelper/Command/AnalyseCommand.php
index 47fc93c7..03b01e08 100644
--- a/src/Ampersand/PatchHelper/Command/AnalyseCommand.php
+++ b/src/Ampersand/PatchHelper/Command/AnalyseCommand.php
@@ -19,7 +19,7 @@ protected function configure()
$this
->setName('analyse')
->addArgument('project', InputArgument::REQUIRED, 'The path to the magento2 project')
- ->setDescription('Analyse a magento2 project which has had a ./vendor.diff file manually created');
+ ->setDescription('Analyse a magento2 project which has had a ./vendor.patch file manually created');
}
protected function execute(InputInterface $input, OutputInterface $output)
@@ -47,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$templateOverrideTable->setHeaders(['Core file', 'Override (phtml/js)']);
$layoutOverrideTable = new Table($output);
- $layoutOverrideTable->setHeaders(['Core file', 'Override (layout xml)']);
+ $layoutOverrideTable->setHeaders(['Core file', 'Override/extended (layout xml)']);
foreach ($patchFile->getFiles() as $file) {
if (!$patchOverrideValidator->canValidate($file)) {
diff --git a/src/Ampersand/PatchHelper/Helper/PatchOverrideValidator.php b/src/Ampersand/PatchHelper/Helper/PatchOverrideValidator.php
index e1db6845..86733a5b 100644
--- a/src/Ampersand/PatchHelper/Helper/PatchOverrideValidator.php
+++ b/src/Ampersand/PatchHelper/Helper/PatchOverrideValidator.php
@@ -83,7 +83,7 @@ public function canValidate($file)
return false;
}
if (str_contains($file, '/ui_component/')) {
- return false; //todo should these be checked?
+ return false; //todo could these be checked?
}
if (str_contains($file, '/Test/')) {
return false;
@@ -144,6 +144,7 @@ private function validatePhpFile($file)
$class = preg_replace('/\\.[^.\\s]{3,4}$/', '', $class);
$class = str_replace('/', '\\', $class);
+ //todo detect scoped(adminhtml) preferences as well as frontend preferences
$preference = $this->config->getPreference($class);
if ($preference === $class || $preference === "$class\\Interceptor") {
@@ -181,7 +182,7 @@ private function validateFrontendFile($file, $type)
$path = $this->minificationResolver->resolve($type, $name, $area, $this->currentTheme, null, $module);
if (!is_file($path)) {
- throw new LogicException("Could not resolve $file (attempted to resolve to $path)");
+ throw new \LogicException("Could not resolve $file (attempted to resolve to $path)");
}
if ($path && strpos($path, '/vendor/magento/') === false) {
throw new FileOverrideException($path);