Skip to content

Commit

Permalink
API Deprecate various APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Sep 10, 2024
1 parent 518dfd9 commit 9ebfe7c
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/Control/CliController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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'
Expand Down
14 changes: 14 additions & 0 deletions src/Control/Middleware/ConfirmationMiddleware/CliBypass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
6 changes: 6 additions & 0 deletions src/Dev/BuildTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct()
*
* @config
* @var string
* @deprecated 5.4.0 Will be replaced with $commandName
*/
private static $segment = null;

Expand All @@ -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';

Expand Down Expand Up @@ -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;
}
}
17 changes: 16 additions & 1 deletion src/Dev/DevBuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{

Expand All @@ -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();
Expand Down Expand Up @@ -68,7 +83,7 @@ public function canInit(): bool
|| Permission::check(static::config()->get('init_permissions'))
);
}

public function providePermissions(): array
{
return [
Expand Down
17 changes: 16 additions & 1 deletion src/Dev/DevConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
Expand Down Expand Up @@ -157,7 +172,7 @@ public function canInit(): bool
|| Permission::check(static::config()->get('init_permissions'))
);
}

public function providePermissions(): array
{
return [
Expand Down
25 changes: 24 additions & 1 deletion src/Dev/DevelopmentAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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])) {
Expand All @@ -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;
Expand All @@ -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 = <<<TXT
Expand Down
7 changes: 7 additions & 0 deletions src/Dev/Tasks/CleanupTestDatabasesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SilverStripe\Control\Director;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\Connect\TempDatabase;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
Expand Down Expand Up @@ -35,6 +36,12 @@ public function run($request)

public function canView(): bool
{
Deprecation::withNoReplacement(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with canRunInBrowser()'
);
});
return Permission::check('ADMIN') || Director::is_cli();
}
}
20 changes: 18 additions & 2 deletions src/Logging/HTTPOutputHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/**
* Output the error to the browser, with the given HTTP status code.
* We recommend that you use a formatter that generates HTML with this.
*
* @deprecated 5.4.0 Will be renamed to ErrorOutputHandler
*/
class HTTPOutputHandler extends AbstractProcessingHandler
{
Expand All @@ -32,6 +34,18 @@ class HTTPOutputHandler extends AbstractProcessingHandler
*/
private $cliFormatter = null;

public function __construct()
{
parent::__construct();
Deprecation::withNoReplacement(function () {
Deprecation::notice(
'5.4.0',
'Will be renamed to ErrorOutputHandler',
Deprecation::SCOPE_CLASS
);
});
}

/**
* Get the mime type to use when displaying this error.
*
Expand Down Expand Up @@ -146,7 +160,7 @@ protected function shouldShowError(int $errorCode): bool
// or our deprecations when the relevant shouldShow method returns true
return $errorCode !== E_USER_DEPRECATED
|| !Deprecation::isTriggeringError()
|| ($this->isCli() ? Deprecation::shouldShowForCli() : Deprecation::shouldShowForHttp());
|| (Director::is_cli() ? Deprecation::shouldShowForCli() : Deprecation::shouldShowForHttp());
}

/**
Expand Down Expand Up @@ -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();
}
}
26 changes: 26 additions & 0 deletions src/ORM/DatabaseAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +25,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
{
Expand All @@ -38,6 +41,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',
Expand All @@ -55,9 +59,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();
Expand Down Expand Up @@ -190,9 +207,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-'
Expand Down
Loading

0 comments on commit 9ebfe7c

Please sign in to comment.