Skip to content

Commit

Permalink
API Throw deprecation warnings for bad configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Feb 24, 2023
1 parent ab566b0 commit e01670f
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/Control/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
89 changes: 89 additions & 0 deletions src/Control/HTTPApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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
);
}
}
}
}
7 changes: 7 additions & 0 deletions thirdparty/swiftmailer/Swift/MailTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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() ?? []
Expand Down
1 change: 1 addition & 0 deletions thirdparty/swiftmailer/Swift/Transport/MailInvoker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion thirdparty/swiftmailer/Swift/Transport/MailTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e01670f

Please sign in to comment.