From ffaf7a7907d15e454a7e6343b0f27cb044c8f0cb Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Fri, 4 Aug 2023 12:22:33 +0100 Subject: [PATCH 1/6] Report plugins on non-existent classes (fix issue #99) --- .../PatchHelper/Checks/ClassPluginPhpTest.php | 138 ++++++++++++++++++ .../checks/ClassPluginPhp/Plugins.php | 59 ++++++++ .../checks/ClassPluginPhp/vendor.patch | 42 +++++- .../Model/NewBusinessLogic.php | 20 +++ .../Model/FunBusinessLogic.php | 15 ++ .../PatchHelper/Checks/ClassPluginPhp.php | 43 ++++++ src/Ampersand/PatchHelper/Patchfile/Entry.php | 3 +- 7 files changed, 316 insertions(+), 4 deletions(-) create mode 100644 dev/phpunit/unit/resources/checks/ClassPluginPhp/vendor/magento/module-adobe-ims/Model/NewBusinessLogic.php create mode 100644 dev/phpunit/unit/resources/checks/ClassPluginPhp/vendor_orig/magento/module-adobe-ims/Model/FunBusinessLogic.php diff --git a/dev/phpunit/unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php b/dev/phpunit/unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php index 70630496..749eeca9 100644 --- a/dev/phpunit/unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php +++ b/dev/phpunit/unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php @@ -113,4 +113,142 @@ public function testClassPlugins() ]; $this->assertEquals($expectedWarnings, $warnings); } + + /** + * + */ + public function testClassPluginsOnDeletedClass() + { + $this->m2->expects($this->any()) + ->method('getAreaConfig') + ->willReturn( + [ + 'frontend' => [ + 'somePluginClassOnDeleteTarget' => [ + 'type' => 'Some_Plugin_Class_On_Delete_Target' + ], + 'Magento\AdobeIms\Model\FunBusinessLogic' => [ + 'plugins' => [ + [ + 'disabled' => false, + 'instance' => 'somePluginClassOnDeleteTarget' + ] + ] + ] + ], + 'adminhtml' => [ + 'Magento\AdobeIms\Model\FunBusinessLogic' => [ + 'plugins' => [ + [ + 'disabled' => false, + 'instance' => 'Some_Plugin_Class_On_Delete_Target' + ] + ] + ] + ], + ] + ); + + $reader = new Reader( + $this->testResourcesDir . 'vendor.patch' + ); + + $entries = $reader->getFiles(); + $this->assertNotEmpty($entries, 'We should have a patch file to read'); + + $entry = $entries[1]; // Second part of the patchfile + + $appCodeGetter = new GetAppCodePathFromVendorPath($this->m2, $entry); + $appCodeFilePath = $appCodeGetter->getAppCodePathFromVendorPath(); + $this->assertEquals( + 'app/code/Magento/AdobeIms/Model/FunBusinessLogic.php', + $appCodeFilePath + ); + + $warnings = $infos = []; + + $check = new ClassPluginPhp($this->m2, $entry, $appCodeFilePath, $warnings, $infos, []); + $this->assertTrue($check->canCheck(), 'Check should be checkable'); + $check->check(); + + $this->assertEmpty($infos, 'We should have no info level items'); + $this->assertNotEmpty($warnings, 'We should have a warning'); + $expectedWarnings = [ + 'Plugin' => [ + 'Some_Plugin_Class_On_Delete_Target::beforeGetUpdatedAt', + 'Some_Plugin_Class_On_Delete_Target::afterGetUpdatedAt', + 'Some_Plugin_Class_On_Delete_Target::aroundGetUpdatedAt', + ] + ]; + $this->assertEquals($expectedWarnings, $warnings); + } + + /** + * + */ + public function testClassPluginsOnCreatedClass() + { + $this->m2->expects($this->any()) + ->method('getAreaConfig') + ->willReturn( + [ + 'frontend' => [ + 'somePluginClassOnDeleteTarget' => [ + 'type' => 'Some_Plugin_Class_On_Created_Target' + ], + 'Magento\AdobeIms\Model\NewBusinessLogic' => [ + 'plugins' => [ + [ + 'disabled' => false, + 'instance' => 'somePluginClassOnDeleteTarget' + ] + ] + ] + ], + 'adminhtml' => [ + 'Magento\AdobeIms\Model\NewBusinessLogic' => [ + 'plugins' => [ + [ + 'disabled' => false, + 'instance' => 'Some_Plugin_Class_On_Created_Target' + ] + ] + ] + ], + ] + ); + + $reader = new Reader( + $this->testResourcesDir . 'vendor.patch' + ); + + $entries = $reader->getFiles(); + $this->assertNotEmpty($entries, 'We should have a patch file to read'); + + $entry = $entries[2]; // Third part of the patchfile + + $appCodeGetter = new GetAppCodePathFromVendorPath($this->m2, $entry); + $appCodeFilePath = $appCodeGetter->getAppCodePathFromVendorPath(); + $this->assertEquals( + 'app/code/Magento/AdobeIms/Model/NewBusinessLogic.php', + $appCodeFilePath + ); + + $warnings = $infos = []; + + $check = new ClassPluginPhp($this->m2, $entry, $appCodeFilePath, $warnings, $infos, []); + $this->assertTrue($check->canCheck(), 'Check should be checkable'); + $check->check(); + + $this->assertEmpty($infos, 'We should have no info level items'); + $this->assertNotEmpty($warnings, 'We should have a warning'); + $expectedWarnings = [ + 'Plugin' => [ + 'Some_Plugin_Class_On_Created_Target::beforeGetUpdatedAt', + 'Some_Plugin_Class_On_Created_Target::afterGetUpdatedAt', + 'Some_Plugin_Class_On_Created_Target::aroundGetUpdatedAt', + ] + ]; + $this->assertEquals($expectedWarnings, $warnings); + } } diff --git a/dev/phpunit/unit/resources/checks/ClassPluginPhp/Plugins.php b/dev/phpunit/unit/resources/checks/ClassPluginPhp/Plugins.php index 074ca44a..f1332e2d 100644 --- a/dev/phpunit/unit/resources/checks/ClassPluginPhp/Plugins.php +++ b/dev/phpunit/unit/resources/checks/ClassPluginPhp/Plugins.php @@ -1,4 +1,8 @@ getData(self::UPDATED_AT); +- } +-} +diff -ur -N vendor_orig/magento/module-adobe-ims/Model/NewBusinessLogic.php vendor/magento/module-adobe-ims/Model/NewBusinessLogic.php +--- vendor_orig/magento/module-adobe-ims/Model/NewBusinessLogic.php 1970-01-01 01:00:00 ++++ vendor/magento/module-adobe-ims/Model/NewBusinessLogic.php 2023-08-04 12:06:14 +@@ -0,0 +1,15 @@ ++getData(self::UPDATED_AT); ++ } ++} diff --git a/dev/phpunit/unit/resources/checks/ClassPluginPhp/vendor/magento/module-adobe-ims/Model/NewBusinessLogic.php b/dev/phpunit/unit/resources/checks/ClassPluginPhp/vendor/magento/module-adobe-ims/Model/NewBusinessLogic.php new file mode 100644 index 00000000..16dd6c8a --- /dev/null +++ b/dev/phpunit/unit/resources/checks/ClassPluginPhp/vendor/magento/module-adobe-ims/Model/NewBusinessLogic.php @@ -0,0 +1,20 @@ +getData(self::UPDATED_AT); + } + + public function someOtherFunction() + { + return false; + } +} diff --git a/dev/phpunit/unit/resources/checks/ClassPluginPhp/vendor_orig/magento/module-adobe-ims/Model/FunBusinessLogic.php b/dev/phpunit/unit/resources/checks/ClassPluginPhp/vendor_orig/magento/module-adobe-ims/Model/FunBusinessLogic.php new file mode 100644 index 00000000..03e859a8 --- /dev/null +++ b/dev/phpunit/unit/resources/checks/ClassPluginPhp/vendor_orig/magento/module-adobe-ims/Model/FunBusinessLogic.php @@ -0,0 +1,15 @@ +getData(self::UPDATED_AT); + } +} diff --git a/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php b/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php index e0519984..5ec797d9 100644 --- a/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php +++ b/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php @@ -113,6 +113,49 @@ class_exists($areaConfig[$area][$pluginClass]['type']) return; } + if ($this->patchEntry->fileWasAdded() || $this->patchEntry->fileWasRemoved()) { + if ($this->patchEntry->fileWasAdded()) { + $tmpMethods = get_class_methods($class); + if (is_array($tmpMethods)) { + $targetClassMethods = []; + foreach ($tmpMethods as $targetClassMethod) { + $targetClassMethods[strtolower($targetClassMethod)] = strtolower($targetClassMethod); + } + } + unset($tmpMethods); + } + + foreach ($nonMagentoPlugins as $nonMagentoPlugin) { + // These plugins target a deleted class, all methods need reported + foreach (get_class_methods($nonMagentoPlugin) as $method) { + $methodName = false; + if (str_starts_with($method, 'before')) { + $methodName = strtolower(substr($method, 6)); + } + if (str_starts_with($method, 'after')) { + $methodName = strtolower(substr($method, 5)); + } + if (str_starts_with($method, 'around')) { + $methodName = strtolower(substr($method, 6)); + } + if (!$methodName) { + continue; + } + if (isset($targetClassMethods) && is_array($targetClassMethods) && !empty($targetClassMethods)) { + if (isset($targetClassMethods[$methodName])) { + $this->warnings[Checks::TYPE_METHOD_PLUGIN][] = "$nonMagentoPlugin::$method"; + } + // created handling + } else { + // deleted handling + $this->warnings[Checks::TYPE_METHOD_PLUGIN][] = "$nonMagentoPlugin::$method"; + } + + } + } + return; + } + /* * For this patch entry under examination, get a list of all public functions which could be intercepted */ diff --git a/src/Ampersand/PatchHelper/Patchfile/Entry.php b/src/Ampersand/PatchHelper/Patchfile/Entry.php index 2585505a..f1462dc6 100644 --- a/src/Ampersand/PatchHelper/Patchfile/Entry.php +++ b/src/Ampersand/PatchHelper/Patchfile/Entry.php @@ -208,8 +208,7 @@ public function getAffectedInterceptablePhpFunctions() // We are trying to see if we have a plugin on a file which has only been created/removed // We can't do this analysis without the file contents of both before and after so cannot scan // - // If its a new class, we could never have had a plugin on it anyway - // If its a class thats been removed, your plugin will become ineffective and I think logged by magento + // These have specific handling within ClassPlugin.php return []; } $newFileContents = $this->getFileContents($this->newFilePath); From 43a2aba6c0363847015a448d2a253e085c4edb04 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Fri, 4 Aug 2023 12:27:29 +0100 Subject: [PATCH 2/6] Fix static analysis --- src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php b/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php index 5ec797d9..76107c5c 100644 --- a/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php +++ b/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php @@ -150,7 +150,6 @@ class_exists($areaConfig[$area][$pluginClass]['type']) // deleted handling $this->warnings[Checks::TYPE_METHOD_PLUGIN][] = "$nonMagentoPlugin::$method"; } - } } return; From 775010d339eb6b0cedadca9e1332305043558f38 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Fri, 4 Aug 2023 12:40:31 +0100 Subject: [PATCH 3/6] Update test cases --- .../expected_output/magentom23.out.txt | 8 +++++++- .../magentom23VendorNamespaces.out.txt | 8 +++++++- .../PatchHelper/Checks/ClassPluginPhp.php | 18 +++++++++++------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/dev/phpunit/functional/expected_output/magentom23.out.txt b/dev/phpunit/functional/expected_output/magentom23.out.txt index c7615982..210d5959 100644 --- a/dev/phpunit/functional/expected_output/magentom23.out.txt +++ b/dev/phpunit/functional/expected_output/magentom23.out.txt @@ -41,6 +41,12 @@ | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-hyva-fallback-theme/theme/etc/view.xml | | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/etc/view.xml | | WARN | Plugin | vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php | Ampersand\Test\Plugin\PhpCookieManager::beforeSetPublicCookie | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::beforeGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::afterGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::aroundGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::beforeGetUpdatedAt | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::afterCanSendCommentEmail | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::aroundCanSendCommentEmail | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::beforeCanSendCommentEmail | @@ -58,6 +64,6 @@ | WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndDelete.php | Ampersand\Test\Model\ToPreferenceAndDelete | | WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndExtendAndDelete.php | Ampersand\Test\Model\ToPreferenceAndExtendAndDelete | +-------+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+ -WARN count: 56 +WARN count: 62 INFO count: 309 (to view re-run this tool with --show-info) For docs on each check see https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/master/docs/CHECKS_AVAILABLE.md \ No newline at end of file diff --git a/dev/phpunit/functional/expected_output/magentom23VendorNamespaces.out.txt b/dev/phpunit/functional/expected_output/magentom23VendorNamespaces.out.txt index 51335100..c40824cd 100644 --- a/dev/phpunit/functional/expected_output/magentom23VendorNamespaces.out.txt +++ b/dev/phpunit/functional/expected_output/magentom23VendorNamespaces.out.txt @@ -41,6 +41,12 @@ | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-hyva-fallback-theme/theme/etc/view.xml | | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/etc/view.xml | | WARN | Plugin | vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php | Ampersand\Test\Plugin\PhpCookieManager::beforeSetPublicCookie | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::beforeGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::afterGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::aroundGetUpdatedAt | +| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::beforeGetUpdatedAt | | WARN | Plugin | vendor/magento/module-checkout/CustomerData/Cart.php | Amazon\Core\Plugin\CartSection::afterGetSectionData | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::afterCanSendCommentEmail | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::aroundCanSendCommentEmail | @@ -59,6 +65,6 @@ | WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndDelete.php | Ampersand\Test\Model\ToPreferenceAndDelete | | WARN | Preference Removed | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/ToPreferenceAndExtendAndDelete.php | Ampersand\Test\Model\ToPreferenceAndExtendAndDelete | +-------+--------------------------+------------------------------------------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------+ -WARN count: 57 +WARN count: 63 INFO count: 314 (to view re-run this tool with --show-info) For docs on each check see https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/master/docs/CHECKS_AVAILABLE.md \ No newline at end of file diff --git a/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php b/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php index 76107c5c..15c6aebe 100644 --- a/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php +++ b/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php @@ -115,14 +115,18 @@ class_exists($areaConfig[$area][$pluginClass]['type']) if ($this->patchEntry->fileWasAdded() || $this->patchEntry->fileWasRemoved()) { if ($this->patchEntry->fileWasAdded()) { - $tmpMethods = get_class_methods($class); - if (is_array($tmpMethods)) { - $targetClassMethods = []; - foreach ($tmpMethods as $targetClassMethod) { - $targetClassMethods[strtolower($targetClassMethod)] = strtolower($targetClassMethod); + try { + $tmpMethods = get_class_methods($class); + if (is_array($tmpMethods)) { + $targetClassMethods = []; + foreach ($tmpMethods as $targetClassMethod) { + $targetClassMethods[strtolower($targetClassMethod)] = strtolower($targetClassMethod); + } } + unset($tmpMethods); + } catch (\Throwable $throwable) { + // do nothing } - unset($tmpMethods); } foreach ($nonMagentoPlugins as $nonMagentoPlugin) { @@ -142,10 +146,10 @@ class_exists($areaConfig[$area][$pluginClass]['type']) continue; } if (isset($targetClassMethods) && is_array($targetClassMethods) && !empty($targetClassMethods)) { + // created handling if (isset($targetClassMethods[$methodName])) { $this->warnings[Checks::TYPE_METHOD_PLUGIN][] = "$nonMagentoPlugin::$method"; } - // created handling } else { // deleted handling $this->warnings[Checks::TYPE_METHOD_PLUGIN][] = "$nonMagentoPlugin::$method"; From a37b279037f5af664e2ae100778239c71bedd7a1 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Fri, 4 Aug 2023 12:55:21 +0100 Subject: [PATCH 4/6] Split plugin enabled/disabled into own classes --- .../unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php | 4 ++-- src/Ampersand/PatchHelper/Checks.php | 4 ++++ src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php | 5 ++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dev/phpunit/unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php b/dev/phpunit/unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php index 749eeca9..dc127687 100644 --- a/dev/phpunit/unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php +++ b/dev/phpunit/unit/Ampersand/PatchHelper/Checks/ClassPluginPhpTest.php @@ -174,7 +174,7 @@ public function testClassPluginsOnDeletedClass() $this->assertEmpty($infos, 'We should have no info level items'); $this->assertNotEmpty($warnings, 'We should have a warning'); $expectedWarnings = [ - 'Plugin' => [ + 'Plugin Disabled' => [ 'Some_Plugin_Class_On_Delete_Target::beforeGetUpdatedAt', 'Some_Plugin_Class_On_Delete_Target::afterGetUpdatedAt', 'Some_Plugin_Class_On_Delete_Target::aroundGetUpdatedAt', @@ -243,7 +243,7 @@ public function testClassPluginsOnCreatedClass() $this->assertEmpty($infos, 'We should have no info level items'); $this->assertNotEmpty($warnings, 'We should have a warning'); $expectedWarnings = [ - 'Plugin' => [ + 'Plugin Enabled' => [ 'Some_Plugin_Class_On_Created_Target::beforeGetUpdatedAt', 'Some_Plugin_Class_On_Created_Target::afterGetUpdatedAt', 'Some_Plugin_Class_On_Created_Target::aroundGetUpdatedAt', diff --git a/src/Ampersand/PatchHelper/Checks.php b/src/Ampersand/PatchHelper/Checks.php index bc989be3..3f0cc10c 100644 --- a/src/Ampersand/PatchHelper/Checks.php +++ b/src/Ampersand/PatchHelper/Checks.php @@ -11,6 +11,8 @@ class Checks public const TYPE_PREFERENCE_REMOVED = 'Preference Removed'; public const TYPE_PREFERENCE = 'Preference'; public const TYPE_METHOD_PLUGIN = 'Plugin'; + public const TYPE_METHOD_PLUGIN_DISABLED = 'Plugin Disabled'; + public const TYPE_METHOD_PLUGIN_ENABLED = 'Plugin Enabled'; public const TYPE_DB_SCHEMA_ADDED = 'DB schema added'; public const TYPE_DB_SCHEMA_CHANGED = 'DB schema changed'; public const TYPE_DB_SCHEMA_REMOVED = 'DB schema removed'; @@ -41,5 +43,7 @@ class Checks self::TYPE_SETUP_PATCH_SCHEMA, self::TYPE_SETUP_SCRIPT, self::TYPE_METHOD_PLUGIN, + self::TYPE_METHOD_PLUGIN_DISABLED, + self::TYPE_METHOD_PLUGIN_ENABLED, ]; } diff --git a/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php b/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php index 15c6aebe..3fa5788d 100644 --- a/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php +++ b/src/Ampersand/PatchHelper/Checks/ClassPluginPhp.php @@ -146,13 +146,12 @@ class_exists($areaConfig[$area][$pluginClass]['type']) continue; } if (isset($targetClassMethods) && is_array($targetClassMethods) && !empty($targetClassMethods)) { - // created handling if (isset($targetClassMethods[$methodName])) { - $this->warnings[Checks::TYPE_METHOD_PLUGIN][] = "$nonMagentoPlugin::$method"; + $this->warnings[Checks::TYPE_METHOD_PLUGIN_ENABLED][] = "$nonMagentoPlugin::$method"; } } else { // deleted handling - $this->warnings[Checks::TYPE_METHOD_PLUGIN][] = "$nonMagentoPlugin::$method"; + $this->warnings[Checks::TYPE_METHOD_PLUGIN_DISABLED][] = "$nonMagentoPlugin::$method"; } } } From 948f0b83c8f301fd62621835ed2a2397c340bfb9 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Fri, 4 Aug 2023 12:58:57 +0100 Subject: [PATCH 5/6] Split plugin enabled/disabled into own classes --- .../expected_output/magentom23.out.txt | 12 +++---- docs/CHECKS_AVAILABLE.md | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/dev/phpunit/functional/expected_output/magentom23.out.txt b/dev/phpunit/functional/expected_output/magentom23.out.txt index 210d5959..a1b31ed2 100644 --- a/dev/phpunit/functional/expected_output/magentom23.out.txt +++ b/dev/phpunit/functional/expected_output/magentom23.out.txt @@ -41,12 +41,12 @@ | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-hyva-fallback-theme/theme/etc/view.xml | | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/etc/view.xml | | WARN | Plugin | vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php | Ampersand\Test\Plugin\PhpCookieManager::beforeSetPublicCookie | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::beforeGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::afterGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::aroundGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::beforeGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::beforeGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::afterGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::aroundGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::beforeGetUpdatedAt | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::afterCanSendCommentEmail | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::aroundCanSendCommentEmail | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::beforeCanSendCommentEmail | diff --git a/docs/CHECKS_AVAILABLE.md b/docs/CHECKS_AVAILABLE.md index 23ab6179..70a41148 100644 --- a/docs/CHECKS_AVAILABLE.md +++ b/docs/CHECKS_AVAILABLE.md @@ -3,6 +3,8 @@ - [WARN - Preference](#warn---preference) - [WARN - Preference Removed](#warn---preference-removed) - [WARN - Plugin](#warn---plugin) +- [WARN - Plugin Enabled](#warn---plugin-enabled) +- [WARN - Plugin Disabled](#warn---plugin-disabled) - [WARN - Override (phtml/js/html)](#warn---override-phtmljshtml) - [WARN - DB schema added](#warn---db-schema-added) - [WARN - DB schema removed](#warn---db-schema-removed) @@ -70,6 +72,36 @@ You have a plugin `Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt` Check the changes to the core function to see if your plugin is still compatible. Sometimes plugins are used by developers to fix core behaviour, and it may no longer be necessary. +## WARN - Plugin Enabled +A plugin exists on function which was added to the codebase as part of this upgrade. You have new plugin logic firing where previously you did not. + +Example: + +``` ++-------+------------------+-------------------------------------------------------+--------------------------------------------------------------+ +| Level | Type | File | To Check | ++-------+------------------+-------------------------------------------------------+--------------------------------------------------------------+ +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt | ++-------+------------------+-------------------------------------------------------+--------------------------------------------------------------+ +``` + +You have a plugin `Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt` and the core `Magento\AdobeIms\Model\UserProfile::getUpdatedAt` function has been added, so the plugin becomes active. + +## WARN - Plugin Disabled +A plugin exists on function which was added to the codebase as part of this upgrade. You have new plugin logic firing where previously you did not. + +Example: + +``` ++-------+------------------+-------------------------------------------------------+--------------------------------------------------------------+ +| Level | Type | File | To Check | ++-------+------------------+-------------------------------------------------------+--------------------------------------------------------------+ +| WARN | Plugin Disabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt | ++-------+------------------+-------------------------------------------------------+--------------------------------------------------------------+ +``` + +You have a plugin `Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt` and the core `Magento\AdobeIms\Model\UserProfile::getUpdatedAt` function has been deleted, so the plugin becomes deactivated. You have customisations which are no longer firing. + ## WARN - Override (phtml/js/html) There is a `phtml`/`html`/`xml`/`js` extension or override in place for a file which was modified as part of this upgrade. From 9d870c0fddbf85d85250c47bf3ec8b4d419bd8ce Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Fri, 4 Aug 2023 13:20:54 +0100 Subject: [PATCH 6/6] Update test cases --- .../functional/expected_output/magentom23.out.txt | 6 +++--- .../magentom23VendorNamespaces.out.txt | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dev/phpunit/functional/expected_output/magentom23.out.txt b/dev/phpunit/functional/expected_output/magentom23.out.txt index a1b31ed2..dc7f8ce6 100644 --- a/dev/phpunit/functional/expected_output/magentom23.out.txt +++ b/dev/phpunit/functional/expected_output/magentom23.out.txt @@ -41,15 +41,15 @@ | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-hyva-fallback-theme/theme/etc/view.xml | | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/etc/view.xml | | WARN | Plugin | vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php | Ampersand\Test\Plugin\PhpCookieManager::beforeSetPublicCookie | +| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::afterCanSendCommentEmail | +| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::aroundCanSendCommentEmail | +| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::beforeCanSendCommentEmail | | WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt | | WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt | | WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::beforeGetUpdatedAt | | WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::afterGetUpdatedAt | | WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::aroundGetUpdatedAt | | WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::beforeGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::afterCanSendCommentEmail | -| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::aroundCanSendCommentEmail | -| WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::beforeCanSendCommentEmail | | WARN | Preference | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Api/ExampleInterface.php | Ampersand\Test\Model\Example | | WARN | Preference | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/SomeClass.php | Ampersand\Test\Model\ThirdPartyClass | | WARN | Preference | vendor/magento/framework/Locale/Format.php | Ampersand\Test\Model\Locale\Format | diff --git a/dev/phpunit/functional/expected_output/magentom23VendorNamespaces.out.txt b/dev/phpunit/functional/expected_output/magentom23VendorNamespaces.out.txt index c40824cd..434277a7 100644 --- a/dev/phpunit/functional/expected_output/magentom23VendorNamespaces.out.txt +++ b/dev/phpunit/functional/expected_output/magentom23VendorNamespaces.out.txt @@ -41,16 +41,16 @@ | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-hyva-fallback-theme/theme/etc/view.xml | | WARN | Override (phtml/js/html) | vendor/magento/theme-frontend-luma/etc/view.xml | vendor/ampersand/upgrade-patch-helper-test-module/src/theme/etc/view.xml | | WARN | Plugin | vendor/magento/framework/Stdlib/Cookie/PhpCookieManager.php | Ampersand\Test\Plugin\PhpCookieManager::beforeSetPublicCookie | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::beforeGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::afterGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::aroundGetUpdatedAt | -| WARN | Plugin | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::beforeGetUpdatedAt | | WARN | Plugin | vendor/magento/module-checkout/CustomerData/Cart.php | Amazon\Core\Plugin\CartSection::afterGetSectionData | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::afterCanSendCommentEmail | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::aroundCanSendCommentEmail | | WARN | Plugin | vendor/magento/module-sales/Block/Adminhtml/Order/View/History.php | Ampersand\Test\Block\Plugin\OrderViewHistoryPlugin::beforeCanSendCommentEmail | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::afterGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::aroundGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfile::beforeGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::afterGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::aroundGetUpdatedAt | +| WARN | Plugin Enabled | vendor/magento/module-adobe-ims/Model/UserProfile.php | Ampersand\Test\Plugin\AdobeImsUserProfileVirtual::beforeGetUpdatedAt | | WARN | Preference | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Api/ExampleInterface.php | Ampersand\Test\Model\Example | | WARN | Preference | vendor/ampersand/upgrade-patch-helper-test-module/src/module/Model/SomeClass.php | Ampersand\Test\Model\ThirdPartyClass | | WARN | Preference | vendor/magento/framework/Locale/Format.php | Ampersand\Test\Model\Locale\Format |