Skip to content

Commit

Permalink
API Stop using deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 3, 2022
1 parent e454db6 commit fc06859
Show file tree
Hide file tree
Showing 50 changed files with 167 additions and 140 deletions.
3 changes: 0 additions & 3 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@

ShortcodeParser::get('default')
->register('embed', [EmbedShortcodeProvider::class, 'handle_shortcode']);

// Set to 5.0.0 to show APIs marked for removal at that version
Deprecation::notification_version('4.0.0');
2 changes: 1 addition & 1 deletion src/Control/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static function mockRequest(
? $cookies
: Injector::inst()->createWithArgs(Cookie_Backend::class, [$cookies ?: []]);
$newVars['_COOKIE'] = $cookieJar->getAll(false);
Cookie::config()->update('report_errors', false);
Cookie::config()->set('report_errors', false);
Injector::inst()->registerService($cookieJar, Cookie_Backend::class);

// Backup requirements
Expand Down
8 changes: 6 additions & 2 deletions src/Control/Middleware/FlushMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace SilverStripe\Control\Middleware;

use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\BaseKernel;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Flushable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Kernel;

/**
* Triggers a call to flush() on all implementors of Flushable.
Expand All @@ -14,7 +16,9 @@ class FlushMiddleware implements HTTPMiddleware
{
public function process(HTTPRequest $request, callable $delegate)
{
if (Director::isManifestFlushed()) {
/** @var BaseKernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
if ((method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) {
// Disable cache when flushing
HTTPCacheControlMiddleware::singleton()->disableCache(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace SilverStripe\Control\Middleware\URLSpecialsMiddleware;

use SilverStripe\Core\BaseKernel;
use SilverStripe\Core\Kernel;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Startup\ScheduledFlushDiscoverer;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;

/**
Expand All @@ -30,11 +30,12 @@ public function scheduleFlush(HTTPRequest $request)
{
$flush = array_key_exists('flush', $request->getVars() ?? []) || ($request->getURL() === 'dev/build');

if (!$flush || Director::isManifestFlushed()) {
/** @var BaseKernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
if (!$flush || (method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) {
return false;
}

$kernel = Injector::inst()->get(Kernel::class);
ScheduledFlushDiscoverer::scheduleFlush($kernel);

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/Control/RSS/RSSFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function Description()
public function outputToBrowser()
{
$prevState = SSViewer::config()->uninherited('source_file_comments');
SSViewer::config()->update('source_file_comments', false);
SSViewer::config()->set('source_file_comments', false);

$response = Controller::curr()->getResponse();

Expand All @@ -236,7 +236,7 @@ public function outputToBrowser()

$response->addHeader("Content-Type", "application/rss+xml; charset=utf-8");

SSViewer::config()->update('source_file_comments', $prevState);
SSViewer::config()->set('source_file_comments', $prevState);
return $this->renderWith($this->getTemplates());
}

Expand Down
6 changes: 0 additions & 6 deletions src/Core/BaseKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,9 @@ protected function bootErrorHandling()
* Get the environment type
*
* @return string
*
* @deprecated 4.12.0 Use Director::get_environment_type() instead
*/
public function getEnvironment()
{
Deprecation::notice('4.12.0', 'Use Director::get_environment_type() instead');
// Check set
if ($this->enviroment) {
return $this->enviroment;
Expand All @@ -288,12 +285,9 @@ public function getEnvironment()
* Check or update any temporary environment specified in the session.
*
* @return null|string
*
* @deprecated 4.12.0 Use Director::get_session_environment_type() instead
*/
protected function sessionEnvironment()
{
Deprecation::notice('4.12.0', 'Use Director::get_session_environment_type() instead');
if (!$this->booted) {
// session is not initialyzed yet, neither is manifest
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public static function json2obj($val)
/**
* Convert a JSON string into an array.
*
* @deprecated 4.4.0 Use json_decode() instead
* @deprecated 4.4.0 Use json_decode($val, true) instead
* @param string $val JSON string to convert
* @return array|boolean
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static function get_enabled()
// noop
}

private static function get_is_enabled(): bool
public static function get_is_enabled(): bool
{
if (!Director::isDev()) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Dev/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function setUp(): void

// Disable theme, if necessary
if (static::get_disable_themes()) {
SSViewer::config()->update('theme_enabled', false);
SSViewer::config()->set('theme_enabled', false);
}

// Flush user
Expand Down Expand Up @@ -560,7 +560,7 @@ protected function setUp()

// Disable theme, if necessary
if (static::get_disable_themes()) {
SSViewer::config()->update('theme_enabled', false);
SSViewer::config()->set('theme_enabled', false);
}

// Flush user
Expand Down
12 changes: 6 additions & 6 deletions src/Dev/SapphireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ protected function setUp(): void
}

if (class_exists(Cookie::class)) {
Cookie::config()->update('report_errors', false);
Cookie::config()->set('report_errors', false);
}

if (class_exists(RootURLController::class)) {
Expand All @@ -356,7 +356,7 @@ protected function setUp(): void

// turn off template debugging
if (class_exists(SSViewer::class)) {
SSViewer::config()->update('source_file_comments', false);
SSViewer::config()->set('source_file_comments', false);
}

// Set up the test mailer
Expand Down Expand Up @@ -1206,7 +1206,7 @@ protected function useTestTheme($themeBaseDir, $theme, $callback)
if (strpos($themeBaseDir ?? '', BASE_PATH) === 0) {
$themeBaseDir = substr($themeBaseDir ?? '', strlen(BASE_PATH));
}
SSViewer::config()->update('theme_enabled', true);
SSViewer::config()->set('theme_enabled', true);
SSViewer::set_themes([$themeBaseDir . '/themes/' . $theme, '$default']);

try {
Expand Down Expand Up @@ -1649,7 +1649,7 @@ protected function setUp()
}

if (class_exists(Cookie::class)) {
Cookie::config()->update('report_errors', false);
Cookie::config()->set('report_errors', false);
}

if (class_exists(RootURLController::class)) {
Expand All @@ -1676,7 +1676,7 @@ protected function setUp()

// turn off template debugging
if (class_exists(SSViewer::class)) {
SSViewer::config()->update('source_file_comments', false);
SSViewer::config()->set('source_file_comments', false);
}

// Set up the test mailer
Expand Down Expand Up @@ -2556,7 +2556,7 @@ protected function useTestTheme($themeBaseDir, $theme, $callback)
if (strpos($themeBaseDir ?? '', BASE_PATH) === 0) {
$themeBaseDir = substr($themeBaseDir ?? '', strlen(BASE_PATH));
}
SSViewer::config()->update('theme_enabled', true);
SSViewer::config()->set('theme_enabled', true);
SSViewer::set_themes([$themeBaseDir . '/themes/' . $theme, '$default']);

try {
Expand Down
9 changes: 9 additions & 0 deletions src/Dev/Tasks/MigrateFileTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
use SilverStripe\Assets\Dev\Tasks\SecureAssetsMigrationHelper;
use SilverStripe\UserForms\Task\RecoverUploadLocationsHelper;
use \Bramus\Monolog\Formatter\ColoredLineFormatter;
use SilverStripe\Dev\Deprecation;

/**
* Migrates all 3.x file dataobjects to use the new DBFile field.
*
* @deprected 4.12.0 Will be removed without equivalent functionality to replace it
*/
class MigrateFileTask extends BuildTask
{
Expand Down Expand Up @@ -52,6 +55,12 @@ class MigrateFileTask extends BuildTask
/** @var Logger */
private $logger;

public function __construct()
{
Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it', Deprecation::SCOPE_CLASS);
parent::__construct();
}

public function run($request)
{
$this->addLogHandlers();
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridField/GridFieldAddExistingAutocompleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function doSearch($gridField, $request)

$json = [];
Config::nest();
SSViewer::config()->update('source_file_comments', false);
SSViewer::config()->set('source_file_comments', false);
$viewer = SSViewer::fromString($this->resultsFormat);
foreach ($results as $result) {
$title = Convert::html2raw($viewer->process($result));
Expand Down
4 changes: 0 additions & 4 deletions src/Forms/TreeDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,26 +622,22 @@ public function getAttributes()
/**
* HTML-encoded label for this node, including css classes and other markup.
*
* @deprecated 4.0.1 Use setTitleField() instead
* @param string $field
* @return $this
*/
public function setLabelField($field)
{
Deprecation::notice('4.0.1', 'Use setTitleField() instead');
$this->labelField = $field;
return $this;
}

/**
* HTML-encoded label for this node, including css classes and other markup.
*
* @deprecated 4.0.1 Use getTitleField() instead
* @return string
*/
public function getLabelField()
{
Deprecation::notice('4.0.1', 'Use getTitleField() instead');
return $this->labelField;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Forms/UploadReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SilverStripe\Assets\File;
use SilverStripe\Assets\Upload;
use SilverStripe\Assets\Upload_Validator;
use SilverStripe\Core\Convert;

/**
* Represents a form field which has an Upload() instance and can upload to a folder
Expand Down Expand Up @@ -47,8 +48,8 @@ protected function constructUploadReceiver()
);

// get the lower max size
$maxUpload = File::ini2bytes(ini_get('upload_max_filesize'));
$maxPost = File::ini2bytes(ini_get('post_max_size'));
$maxUpload = Convert::memstring2bytes(ini_get('upload_max_filesize'));
$maxPost = Convert::memstring2bytes(ini_get('post_max_size'));
$this->getValidator()->setAllowedMaxFileSize(min($maxUpload, $maxPost));
}

Expand Down
3 changes: 0 additions & 3 deletions src/ORM/Connect/DBSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,9 @@ abstract class DBSchemaManager
/**
* @param string $table
* @param string $class
*
* @deprecated 4.0.1 Will be removed without equivalent functionality
*/
public static function showTableNameWarning($table, $class)
{
Deprecation::notice('4.0.1', 'Will be removed without equivalent functionality');
static::$table_name_warnings[$table] = $class;
}

Expand Down
2 changes: 1 addition & 1 deletion src/View/SSViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static function get_themes()
return $themes;
}

// Support legacy behaviour
// Support @deprecated legacy behaviour
if ($theme = SSViewer::config()->uninherited('theme')) {
return [self::PUBLIC_THEME, $theme, self::DEFAULT_THEME];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Control/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ControllerTest extends FunctionalTest
protected function setUp(): void
{
parent::setUp();
Director::config()->update('alternate_base_url', '/');
Director::config()->set('alternate_base_url', '/');

// Add test theme
$themeDir = substr(__DIR__, strlen(FRAMEWORK_DIR)) . '/ControllerTest/';
Expand Down
4 changes: 4 additions & 0 deletions tests/php/Control/DirectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Environment;
use SilverStripe\Core\Kernel;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;

/**
Expand Down Expand Up @@ -856,6 +857,9 @@ public function testTestIgnoresHashes()

public function testRequestFilterInDirectorTest()
{
if (Deprecation::get_is_enabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$filter = new DirectorTest\TestRequestFilter;

$processor = new RequestProcessor([$filter]);
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Control/Email/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function testGetSwiftMessage()

public function testSetSwiftMessage()
{
Email::config()->update('admin_email', '[email protected]');
Email::config()->set('admin_email', '[email protected]');
DBDatetime::set_mock_now('2017-01-01 07:00:00');
$email = new Email();
$swiftMessage = new Swift_Message();
Expand All @@ -294,7 +294,7 @@ public function testSetSwiftMessage()

public function testAdminEmailApplied()
{
Email::config()->update('admin_email', '[email protected]');
Email::config()->set('admin_email', '[email protected]');
$email = new Email();

$this->assertCount(1, $email->getFrom());
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Control/Email/SwiftMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testSwiftMailer()
$this->assertEquals($swift, $mailer->getSwiftMailer());

SwiftMailer::config()->remove('swift_plugins');
SwiftMailer::config()->update('swift_plugins', [Swift_Plugins_AntiFloodPlugin::class]);
SwiftMailer::config()->merge('swift_plugins', [Swift_Plugins_AntiFloodPlugin::class]);

/** @var Swift_MailTransport $transport */
$transport = $this->getMockBuilder(Swift_MailTransport::class)->getMock();
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Control/Email/SwiftPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function getMailer()

public function testSendAllEmailsTo()
{
Email::config()->update('send_all_emails_to', '[email protected]');
Email::config()->set('send_all_emails_to', '[email protected]');
$email = $this->getEmail();
$this->getMailer()->send($email->getSwiftMessage());
$headers = $email->getSwiftMessage()->getHeaders();
Expand Down Expand Up @@ -68,7 +68,7 @@ public function testSendAllEmailsTo()

public function testSendAllEmailsFrom()
{
Email::config()->update('send_all_emails_from', '[email protected]');
Email::config()->set('send_all_emails_from', '[email protected]');
$email = $this->getEmail();
$this->getMailer()->send($email->getSwiftMessage());

Expand All @@ -88,7 +88,7 @@ public function testSendAllEmailsFrom()

public function testCCAllEmailsTo()
{
Email::config()->update('cc_all_emails_to', '[email protected]');
Email::config()->set('cc_all_emails_to', '[email protected]');
$email = $this->getEmail();
$this->getMailer()->send($email->getSwiftMessage());

Expand All @@ -99,7 +99,7 @@ public function testCCAllEmailsTo()

public function testBCCAllEmailsTo()
{
Email::config()->update('bcc_all_emails_to', '[email protected]');
Email::config()->set('bcc_all_emails_to', '[email protected]');
$email = $this->getEmail();
$this->getMailer()->send($email->getSwiftMessage());

Expand Down
Loading

0 comments on commit fc06859

Please sign in to comment.