From e01670fc459a9c4978e3904a1e8ed3d5e780fbd6 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Fri, 24 Feb 2023 12:23:02 +1300 Subject: [PATCH] API Throw deprecation warnings for bad configuration --- src/Control/Director.php | 1 - src/Control/HTTPApplication.php | 89 +++++++++++++++++++ .../swiftmailer/Swift/MailTransport.php | 7 ++ .../Swift/Transport/MailInvoker.php | 1 + .../Swift/Transport/MailTransport.php | 7 +- .../Swift/Transport/SimpleMailInvoker.php | 1 + 6 files changed, 104 insertions(+), 2 deletions(-) diff --git a/src/Control/Director.php b/src/Control/Director.php index ca26754d95e..b9eee7b21ca 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -73,7 +73,6 @@ class Director implements TemplateGlobalProvider /** * @config * @var string - * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ private static $alternate_base_folder; diff --git a/src/Control/HTTPApplication.php b/src/Control/HTTPApplication.php index aba38079625..e11c1cb6d9a 100644 --- a/src/Control/HTTPApplication.php +++ b/src/Control/HTTPApplication.php @@ -2,16 +2,23 @@ namespace SilverStripe\Control; +use SilverStripe\Assets\FilenameParsing\FileResolutionStrategy; +use SilverStripe\Assets\FilenameParsing\LegacyFileIDHelper; +use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper; use SilverStripe\Control\Middleware\HTTPMiddlewareAware; use SilverStripe\Core\Application; use SilverStripe\Core\Environment; +use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Kernel; +use SilverStripe\Core\Manifest\Module; use SilverStripe\Core\Startup\FlushDiscoverer; use SilverStripe\Core\Startup\CompositeFlushDiscoverer; use SilverStripe\Core\Startup\CallbackFlushDiscoverer; use SilverStripe\Core\Startup\RequestFlushDiscoverer; use SilverStripe\Core\Startup\ScheduledFlushDiscoverer; use SilverStripe\Core\Startup\DeployFlushDiscoverer; +use SilverStripe\Dev\Deprecation; +use SilverStripe\GraphQL\TypeCreator; /** * Invokes the HTTP application within an ErrorControlChain @@ -133,6 +140,10 @@ public function execute(HTTPRequest $request, callable $callback, $flush = false return $this->callMiddleware($request, function ($request) use ($callback, $flush) { // Pre-request boot $this->getKernel()->boot($flush); + + // This is the earliest point we can do this and guarantee it's hit exactly once per request. + $this->warnAboutDeprecatedSetups(); + return call_user_func($callback, $request); }); } catch (HTTPResponse_Exception $ex) { @@ -141,4 +152,82 @@ public function execute(HTTPRequest $request, callable $callback, $flush = false $this->getKernel()->shutdown(); } } + + /** + * Trigger deprecation notices for legacy configuration which is deprecated but + * doesn't have deprecation notices directly on the relevant API + * + * Don't remove this method even if it's just a no-op - we'll reuse this mechanism + * in the future as needed. + */ + private function warnAboutDeprecatedSetups() + { + // TypeCreator is a class unique to GraphQL v3 - we use it in other areas to detect + // which version is being used. + if (class_exists(TypeCreator::class)) { + Deprecation::notice( + '4.13.0', + 'silverstripe/graphql 3.x is deprecated. Upgrade to 4.x instead.' + . ' See https://docs.silverstripe.org/en/4/upgrading/upgrading_to_graphql_4/', + Deprecation::SCOPE_GLOBAL + ); + } + + // The alternate_public_dir config property is deprecated, but because it's + // always fetched it'll throw a deprecation warning whether you've set it or not. + // There are also multiple mechanisms which can result in this bad configuration. + if (PUBLIC_DIR !== 'public' || Director::publicFolder() !== PUBLIC_DIR) { + Deprecation::notice( + '4.13.0', + 'Use of a public webroot other than "public" is deprecated.' + . ' See https://docs.silverstripe.org/en/4/changelogs/4.1.0#public-folder/', + Deprecation::SCOPE_GLOBAL + ); + } + + // This change of defaults has no other deprecation notice being emitted currently. + $project = new Module(BASE_PATH, BASE_PATH); + if (RESOURCES_DIR !== '_resources' && $project->getResourcesDir() !== RESOURCES_DIR) { + Deprecation::notice( + '4.13.0', + 'The RESOURCES_DIR constant will change to "_resources" by default.' + . ' See https://docs.silverstripe.org/en/5/changelogs/5.0.0/#api-general', + Deprecation::SCOPE_GLOBAL + ); + } + + // File resolution strategy defaults changed in CMS 4.4 - people may not have changed their + // config since then, so alert them their legacy strategy won't work in the future. + $publicResolutionStrat = Injector::inst()->get(FileResolutionStrategy::class . '.public'); + $protectedResolutionStrat = Injector::inst()->get(FileResolutionStrategy::class . '.protected'); + if (method_exists($publicResolutionStrat, 'getResolutionFileIDHelpers')) { + $hasDeprecatedStrategy = false; + foreach ($publicResolutionStrat->getResolutionFileIDHelpers() as $helper) { + if ($helper instanceof LegacyFileIDHelper) { + $hasDeprecatedStrategy = true; + break; + } + } + + if (!$hasDeprecatedStrategy && method_exists($protectedResolutionStrat, 'getResolutionFileIDHelpers')) { + foreach ($protectedResolutionStrat->getResolutionFileIDHelpers() as $helper) { + if ($helper instanceof NaturalFileIDHelper) { + $hasDeprecatedStrategy = true; + break; + } + } + } + + if ($hasDeprecatedStrategy) { + Deprecation::notice( + '4.13.0', + 'Use of legacy file resolution strategies is deprecated.' + . ' See https://docs.silverstripe.org/en/4/developer_guides/files/file_migration/.' + . ' After migrating your files, change your file resolution configuration to match the defaults:' + . ' https://github.com/silverstripe/silverstripe-installer/blob/4/app/_config/assets.yml', + Deprecation::SCOPE_GLOBAL + ); + } + } + } } diff --git a/thirdparty/swiftmailer/Swift/MailTransport.php b/thirdparty/swiftmailer/Swift/MailTransport.php index ec3b892a2cd..f99df290c27 100644 --- a/thirdparty/swiftmailer/Swift/MailTransport.php +++ b/thirdparty/swiftmailer/Swift/MailTransport.php @@ -5,6 +5,8 @@ * It has been slightly modified to meet phpcs standards and initialise Swift_DependencyContainer */ +use SilverStripe\Dev\Deprecation; + /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn @@ -19,6 +21,7 @@ * @author Chris Corbyn * * at deprecated since 5.4.5 (to be removed in 6.0) + * @deprecated 4.12.0 Will be replaced with symfony/mailer */ // @codingStandardsIgnoreStart // ignore missing namespace @@ -32,6 +35,10 @@ class Swift_MailTransport extends Swift_Transport_MailTransport */ public function __construct($extraParams = '-f%s') { + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.12.0', 'Will be replaced with symfony/mailer', Deprecation::SCOPE_CLASS); + }); + call_user_func_array( [$this, 'Swift_Transport_MailTransport::__construct'], $this->getDependencies() ?? [] diff --git a/thirdparty/swiftmailer/Swift/Transport/MailInvoker.php b/thirdparty/swiftmailer/Swift/Transport/MailInvoker.php index 2a23e24d2d5..f36af3b85a9 100644 --- a/thirdparty/swiftmailer/Swift/Transport/MailInvoker.php +++ b/thirdparty/swiftmailer/Swift/Transport/MailInvoker.php @@ -17,6 +17,7 @@ * This interface intercepts calls to the mail() function. * * @author Chris Corbyn + * @deprecated 4.12.0 Will be replaced with symfony/mailer */ // @codingStandardsIgnoreStart // ignore missing namespace diff --git a/thirdparty/swiftmailer/Swift/Transport/MailTransport.php b/thirdparty/swiftmailer/Swift/Transport/MailTransport.php index 84fd03a151a..978a138a4df 100644 --- a/thirdparty/swiftmailer/Swift/Transport/MailTransport.php +++ b/thirdparty/swiftmailer/Swift/Transport/MailTransport.php @@ -5,6 +5,8 @@ * It has been slightly modified to meet phpcs standards and to update method signatures to match the swiftmailer v6 */ +use SilverStripe\Dev\Deprecation; + /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn @@ -26,7 +28,7 @@ * * @author Chris Corbyn * - * at deprecated since 5.4.5 (to be removed in 6.0) + * @deprecated 4.12.0 Will be replaced with symfony/mailer */ // @codingStandardsIgnoreStart // ignore missing namespace @@ -50,6 +52,9 @@ class Swift_Transport_MailTransport implements Swift_Transport */ public function __construct(Swift_Transport_MailInvoker $invoker, Swift_Events_EventDispatcher $eventDispatcher) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.12.0', 'Will be replaced with symfony/mailer', Deprecation::SCOPE_CLASS); + }); // @trigger_error(sprintf('The %s class is deprecated since version 5.4.5 and will be removed in 6.0. Use the Sendmail or SMTP transport instead.', __CLASS__), E_USER_DEPRECATED); $this->_invoker = $invoker; diff --git a/thirdparty/swiftmailer/Swift/Transport/SimpleMailInvoker.php b/thirdparty/swiftmailer/Swift/Transport/SimpleMailInvoker.php index 8094e542856..c6783ecc95f 100644 --- a/thirdparty/swiftmailer/Swift/Transport/SimpleMailInvoker.php +++ b/thirdparty/swiftmailer/Swift/Transport/SimpleMailInvoker.php @@ -17,6 +17,7 @@ * This is the implementation class for {@link Swift_Transport_MailInvoker}. * * @author Chris Corbyn + * @deprecated 4.12.0 Will be replaced with symfony/mailer */ // @codingStandardsIgnoreStart // ignore missing namespace