Skip to content

Commit

Permalink
Merge branch '5' into 6
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Core/CoreKernel.php
#	src/ORM/FieldType/DBDatetime.php
  • Loading branch information
GuySartorelli committed Sep 17, 2024
2 parents dc13324 + 6a3659d commit 68fb4b0
Show file tree
Hide file tree
Showing 18 changed files with 541 additions and 17 deletions.
8 changes: 4 additions & 4 deletions cli-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use SilverStripe\Core\CoreKernel;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\Connect\NullDatabase;
use SilverStripe\Core\DatabaselessKernel;

require __DIR__ . '/src/includes/autoload.php';

Expand All @@ -25,9 +24,10 @@
DB::set_conn(new NullDatabase());
}
// Default application
$kernel = $skipDatabase
? new DatabaselessKernel(BASE_PATH)
: new CoreKernel(BASE_PATH);
$kernel = new CoreKernel(BASE_PATH);
if ($skipDatabase) {
$kernel->setBootDatabase(false);
}

$app = new HTTPApplication($kernel);
$response = $app->handle($request);
Expand Down
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
8 changes: 8 additions & 0 deletions src/Core/BaseKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ protected function setBooted(bool $bool): void
$this->booted = $bool;
}

/**
* Check whether the kernel has booted or not
*/
public function getBooted(): bool
{
return $this->booted;
}

public function shutdown()
{
}
Expand Down
25 changes: 24 additions & 1 deletion src/Core/CoreKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@

use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
use SilverStripe\ORM\Connect\NullDatabase;
use SilverStripe\ORM\DB;
use Exception;
use LogicException;

/**
* Simple Kernel container
*/
class CoreKernel extends BaseKernel
{
protected bool $bootDatabase = true;

/**
* Indicates whether the Kernel has been flushed on boot
*/
private ?bool $flush = null;

/**
* Set whether the database should boot or not.
*/
public function setBootDatabase(bool $bool): static
{
$this->bootDatabase = $bool;
return $this;
}

/**
* @param false $flush
* @throws HTTPResponse_Exception
Expand All @@ -28,6 +38,10 @@ public function boot($flush = false)
{
$this->flush = $flush;

if (!$this->bootDatabase) {
DB::set_conn(new NullDatabase());
}

$this->bootPHP();
$this->bootManifests($flush);
$this->bootErrorHandling();
Expand All @@ -46,6 +60,9 @@ public function boot($flush = false)
*/
protected function validateDatabase()
{
if (!$this->bootDatabase) {
return;
}
$databaseConfig = DB::getConfig();
// Fail if no DB is configured
if (empty($databaseConfig['database'])) {
Expand All @@ -61,6 +78,9 @@ protected function validateDatabase()
*/
protected function bootDatabaseGlobals()
{
if (!$this->bootDatabase) {
return;
}
// Now that configs have been loaded, we can check global for database config
global $databaseConfig;
global $database;
Expand Down Expand Up @@ -93,6 +113,9 @@ protected function bootDatabaseGlobals()
*/
protected function bootDatabaseEnvVars()
{
if (!$this->bootDatabase) {
return;
}
// Set default database config
$databaseConfig = $this->getDatabaseConfig();
$databaseConfig['database'] = $this->getDatabaseName();
Expand Down
12 changes: 12 additions & 0 deletions src/Core/DatabaselessKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\Core;

use Exception;
use SilverStripe\Dev\Deprecation;

/**
* Boot a kernel without requiring a database connection.
Expand All @@ -11,6 +12,7 @@
* around the availability of a database for every execution path.
*
* @internal
* @deprecated 5.4.0 Use SilverStripe\Core\CoreKernel::setBootDatabase() instead
*/
class DatabaselessKernel extends BaseKernel
{
Expand All @@ -29,6 +31,16 @@ class DatabaselessKernel extends BaseKernel
*/
protected $bootErrorHandling = true;

public function __construct($basePath)
{
parent::__construct($basePath);
Deprecation::notice(
'5.4.0',
'Use ' . CoreKernel::class . '::setBootDatabase() instead',
Deprecation::SCOPE_CLASS
);
}

public function setBootErrorHandling(bool $bool)
{
$this->bootErrorHandling = $bool;
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();
}
}
Loading

0 comments on commit 68fb4b0

Please sign in to comment.