From dbe567db392a75842fa292e7216c36e94fccdbe1 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Tue, 10 Sep 2024 14:03:17 +1200 Subject: [PATCH] API Deprecate various APIs --- src/Control/CliController.php | 8 ++++++ .../ConfirmationMiddleware/CliBypass.php | 14 ++++++++++ src/Dev/BuildTask.php | 6 +++++ src/Dev/DevBuildController.php | 17 +++++++++++- src/Dev/DevConfigController.php | 17 +++++++++++- src/Dev/DevelopmentAdmin.php | 25 +++++++++++++++++- src/Dev/Tasks/CleanupTestDatabasesTask.php | 7 +++++ src/Logging/HTTPOutputHandler.php | 20 ++++++++++++-- src/ORM/DatabaseAdmin.php | 26 +++++++++++++++++++ tests/php/Logging/HTTPOutputHandlerTest.php | 21 ++++++++++----- 10 files changed, 149 insertions(+), 12 deletions(-) diff --git a/src/Control/CliController.php b/src/Control/CliController.php index 2377ebab7b4..30d66250b93 100644 --- a/src/Control/CliController.php +++ b/src/Control/CliController.php @@ -4,6 +4,7 @@ use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Injector\Injector; +use SilverStripe\Dev\Deprecation; use SilverStripe\Security\Permission; use SilverStripe\Security\Security; @@ -13,9 +14,16 @@ * call to {@link process()} on every sub-subclass. For instance, calling * "sake DailyTask" from the commandline will call {@link process()} on every subclass * of DailyTask. + * + * @deprecated 5.4.0 Will be replaced with symfony/console commands */ abstract class CliController extends Controller { + public function __construct() + { + parent::__construct(); + Deprecation::notice('5.4.0', 'Will be replaced with symfony/console commands', Deprecation::SCOPE_CLASS); + } private static $allowed_actions = [ 'index' diff --git a/src/Control/Middleware/ConfirmationMiddleware/CliBypass.php b/src/Control/Middleware/ConfirmationMiddleware/CliBypass.php index f834cfb4e65..1a16be0c695 100644 --- a/src/Control/Middleware/ConfirmationMiddleware/CliBypass.php +++ b/src/Control/Middleware/ConfirmationMiddleware/CliBypass.php @@ -5,12 +5,26 @@ use SilverStripe\Control\Director; use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\Kernel; +use SilverStripe\Dev\Deprecation; /** * Allows a bypass when the request has been run in CLI mode + * + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it */ class CliBypass implements Bypass { + public function __construct() + { + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '5.4.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + }); + } + /** * Returns true if the current process is running in CLI mode * diff --git a/src/Dev/BuildTask.php b/src/Dev/BuildTask.php index 9b2659c53f0..5497cc3f0f0 100644 --- a/src/Dev/BuildTask.php +++ b/src/Dev/BuildTask.php @@ -30,6 +30,7 @@ public function __construct() * * @config * @var string + * @deprecated 5.4.0 Will be replaced with $commandName */ private static $segment = null; @@ -55,6 +56,7 @@ public function __construct() /** * @var string $description Describe the implications the task has, * and the changes it makes. Accepts HTML formatting. + * @deprecated 5.4.0 Will be replaced with a static property with the same name */ protected $description = 'No description available'; @@ -90,9 +92,13 @@ public function getTitle() /** * @return string HTML formatted description + * @deprecated 5.4.0 Will be replaced with a static method with the same name */ public function getDescription() { + Deprecation::withNoReplacement( + fn() => Deprecation::notice('5.4.0', 'Will be replaced with a static method with the same name') + ); return $this->description; } } diff --git a/src/Dev/DevBuildController.php b/src/Dev/DevBuildController.php index 6dc791d4294..1559296865a 100644 --- a/src/Dev/DevBuildController.php +++ b/src/Dev/DevBuildController.php @@ -11,6 +11,9 @@ use SilverStripe\Security\PermissionProvider; use SilverStripe\Security\Security; +/** + * @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Command\DbBuild + */ class DevBuildController extends Controller implements PermissionProvider { @@ -28,6 +31,18 @@ class DevBuildController extends Controller implements PermissionProvider 'CAN_DEV_BUILD', ]; + public function __construct() + { + parent::__construct(); + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '5.4.0', + 'Will be replaced with SilverStripe\Dev\Command\DbBuild', + Deprecation::SCOPE_CLASS + ); + }); + } + protected function init(): void { parent::init(); @@ -68,7 +83,7 @@ public function canInit(): bool || Permission::check(static::config()->get('init_permissions')) ); } - + public function providePermissions(): array { return [ diff --git a/src/Dev/DevConfigController.php b/src/Dev/DevConfigController.php index 03c53281056..056f0ee04fe 100644 --- a/src/Dev/DevConfigController.php +++ b/src/Dev/DevConfigController.php @@ -15,6 +15,8 @@ /** * Outputs the full configuration. + * + * @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Command\ConfigDump */ class DevConfigController extends Controller implements PermissionProvider { @@ -41,6 +43,19 @@ class DevConfigController extends Controller implements PermissionProvider 'CAN_DEV_CONFIG', ]; + + public function __construct() + { + parent::__construct(); + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '5.4.0', + 'Will be replaced with SilverStripe\Dev\Command\ConfigDump', + Deprecation::SCOPE_CLASS + ); + }); + } + protected function init(): void { parent::init(); @@ -157,7 +172,7 @@ public function canInit(): bool || Permission::check(static::config()->get('init_permissions')) ); } - + public function providePermissions(): array { return [ diff --git a/src/Dev/DevelopmentAdmin.php b/src/Dev/DevelopmentAdmin.php index 752ae82dd64..ccf279c309e 100644 --- a/src/Dev/DevelopmentAdmin.php +++ b/src/Dev/DevelopmentAdmin.php @@ -54,6 +54,7 @@ class DevelopmentAdmin extends Controller implements PermissionProvider * ] * * @var array + * @deprecated 5.4.0 Will be replaced with "controllers" and "commands" configuration properties */ private static $registered_controllers = []; @@ -82,7 +83,7 @@ protected function init() if (static::config()->get('deny_non_cli') && !Director::is_cli()) { return $this->httpError(404); } - + if (!$this->canViewAll() && empty($this->getLinks())) { Security::permissionFailure($this); return; @@ -201,8 +202,12 @@ protected function getLinks(): array return $links; } + /** + * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it + */ protected function getRegisteredController($baseUrlPart) { + Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it'); $reg = Config::inst()->get(static::class, 'registered_controllers'); if (isset($reg[$baseUrlPart])) { @@ -223,9 +228,18 @@ protected function getRegisteredController($baseUrlPart) * DataObject classes * Should match the $url_handlers rule: * 'build/defaults' => 'buildDefaults', + * + * @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Commands\DbDefaults */ public function buildDefaults() { + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '5.4.0', + 'Will be replaced with SilverStripe\Dev\Command\DbDefaults' + ); + }); + $da = DatabaseAdmin::create(); $renderer = null; @@ -247,9 +261,18 @@ public function buildDefaults() /** * Generate a secure token which can be used as a crypto key. * Returns the token and suggests PHP configuration to set it. + * + * @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Commands\GenerateSecureToken */ public function generatesecuretoken() { + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '5.4.0', + 'Will be replaced with SilverStripe\Dev\Command\GenerateSecureToken' + ); + }); + $generator = Injector::inst()->create('SilverStripe\\Security\\RandomGenerator'); $token = $generator->randomToken('sha1'); $body = <<isCli() ? Deprecation::shouldShowForCli() : Deprecation::shouldShowForHttp()); + || (Director::is_cli() ? Deprecation::shouldShowForCli() : Deprecation::shouldShowForHttp()); } /** @@ -185,10 +199,12 @@ protected function write(LogRecord $record): void } /** - * This method is required and must be protected for unit testing, since we can't mock static or private methods + * This method used to be used for unit testing but is no longer required. + * @deprecated 5.4.0 Use SilverStripe\Control\Director::is_cli() instead */ protected function isCli(): bool { + Deprecation::notice('5.4.0', 'Use ' . Director::class . '::is_cli() instead'); return Director::is_cli(); } } diff --git a/src/ORM/DatabaseAdmin.php b/src/ORM/DatabaseAdmin.php index 5b222599b73..29f56474a23 100644 --- a/src/ORM/DatabaseAdmin.php +++ b/src/ORM/DatabaseAdmin.php @@ -10,6 +10,7 @@ use SilverStripe\Core\Environment; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Manifest\ClassLoader; +use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\DevBuildController; use SilverStripe\Dev\DevelopmentAdmin; use SilverStripe\ORM\Connect\DatabaseException; @@ -25,6 +26,8 @@ * * Utility functions for administrating the database. These can be accessed * via URL, e.g. http://www.yourdomain.com/db/build. + * + * @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Command\DbBuild */ class DatabaseAdmin extends Controller { @@ -39,6 +42,7 @@ class DatabaseAdmin extends Controller /** * Obsolete classname values that should be remapped in dev/build + * @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Command\DbBuild.classname_value_remapping */ private static $classname_value_remapping = [ 'File' => 'SilverStripe\\Assets\\File', @@ -56,9 +60,22 @@ class DatabaseAdmin extends Controller /** * Config setting to enabled/disable the display of record counts on the dev/build output + * @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Command\DbBuild.show_record_counts */ private static $show_record_counts = true; + public function __construct() + { + parent::__construct(); + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '5.4.0', + 'Will be replaced with SilverStripe\Dev\Command\DbBuild', + Deprecation::SCOPE_CLASS + ); + }); + } + protected function init() { parent::init(); @@ -191,9 +208,18 @@ public function buildDefaults() * * @return string Returns the timestamp of the time that the database was * last built + * + * @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Command\DbBuild::lastBuilt() */ public static function lastBuilt() { + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '5.4.0', + 'Will be replaced with SilverStripe\Dev\Command\DbBuild::lastBuilt()' + ); + }); + $file = TEMP_PATH . DIRECTORY_SEPARATOR . 'database-last-generated-' diff --git a/tests/php/Logging/HTTPOutputHandlerTest.php b/tests/php/Logging/HTTPOutputHandlerTest.php index 2f21f118f81..f6572a86952 100644 --- a/tests/php/Logging/HTTPOutputHandlerTest.php +++ b/tests/php/Logging/HTTPOutputHandlerTest.php @@ -6,6 +6,7 @@ use ReflectionClass; use ReflectionMethod; use SilverStripe\Control\Director; +use SilverStripe\Core\Environment; use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; @@ -172,14 +173,20 @@ public function testShouldShowError( } $reflectionDeprecation->setStaticPropertyValue('isTriggeringError', $triggeringError); - $mockHandler = $this->getMockBuilder(HTTPOutputHandler::class)->onlyMethods(['isCli'])->getMock(); - $mockHandler->method('isCli')->willReturn($isCli); + $reflectionDirector = new ReflectionClass(Environment::class); + $origIsCli = $reflectionDirector->getStaticPropertyValue('isCliOverride'); + $reflectionDirector->setStaticPropertyValue('isCliOverride', $isCli); - $result = $reflectionShouldShow->invoke($mockHandler, $errorCode); - $this->assertSame($expected, $result); + try { + $handler = new HTTPOutputHandler(); + $result = $reflectionShouldShow->invoke($handler, $errorCode); + $this->assertSame($expected, $result); - Deprecation::setShouldShowForCli($cliShouldShowOrig); - Deprecation::setShouldShowForHttp($httpShouldShowOrig); - $reflectionDeprecation->setStaticPropertyValue('isTriggeringError', $triggeringErrorOrig); + Deprecation::setShouldShowForCli($cliShouldShowOrig); + Deprecation::setShouldShowForHttp($httpShouldShowOrig); + $reflectionTriggeringError->setValue($triggeringErrorOrig); + } finally { + $reflectionDirector->setStaticPropertyValue('isCliOverride', $origIsCli); + } } }