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 7, 2022
1 parent 00d1701 commit 98e654e
Show file tree
Hide file tree
Showing 53 changed files with 197 additions and 183 deletions.
4 changes: 0 additions & 4 deletions _config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use SilverStripe\Dev\Deprecation;
use SilverStripe\View\Shortcodes\EmbedShortcodeProvider;
use SilverStripe\View\Parsers\ShortcodeParser;

Expand All @@ -14,6 +13,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');
3 changes: 0 additions & 3 deletions src/Control/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,9 @@ private function cookieIsSecure(string $sameSite, bool $secure): bool

/**
* Get the correct samesite value - Session cookies use a different configuration variable.
*
* @deprecated 4.12.0 The relevant methods will include a `$sameSite` parameter instead.
*/
private function getSameSite(string $name): string
{
Deprecation::notice('4.12.0', 'The relevant methods will include a `$sameSite` parameter instead.');
if ($name === session_name()) {
return Session::config()->get('cookie_samesite');
}
Expand Down
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
2 changes: 0 additions & 2 deletions src/Control/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,11 @@ public function save(HTTPRequest $request)
* Recursively apply the changes represented in $data to $dest.
* Used to update $_SESSION
*
* @deprecated 4.1.0 Use recursivelyApplyChanges() instead
* @param array $data
* @param array $dest
*/
protected function recursivelyApply($data, &$dest)
{
Deprecation::notice('4.1.0', 'Use recursivelyApplyChanges() instead');
foreach ($data as $k => $v) {
if (is_array($v)) {
if (!isset($dest[$k]) || !is_array($dest[$k])) {
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
5 changes: 0 additions & 5 deletions src/Forms/TreeDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SilverStripe\Forms;

use SilverStripe\Dev\Deprecation;
use Exception;
use InvalidArgumentException;
use SilverStripe\Assets\Folder;
Expand Down Expand Up @@ -622,26 +621,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
4 changes: 0 additions & 4 deletions src/ORM/Connect/DBSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SilverStripe\ORM\Connect;

use SilverStripe\Dev\Deprecation;
use Exception;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
Expand Down Expand Up @@ -60,12 +59,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
Loading

0 comments on commit 98e654e

Please sign in to comment.