From 53c0147f112a011f8cbdfb964a92dc4eb81a8b7f Mon Sep 17 00:00:00 2001 From: Sabina Talipova <87288324+sabina-talipova@users.noreply.github.com> Date: Thu, 8 Dec 2022 10:44:47 +1300 Subject: [PATCH] API Remove deprecated code (#10594) --- .upgrade.yml | 41 -- _config/backtrace.yml | 5 - _config/requestprocessors.yml | 13 +- src/Control/Controller.php | 28 -- src/Control/CookieJar.php | 1 - src/Control/Director.php | 43 +-- src/Control/Email/Mailer.php | 16 - src/Control/HTTP.php | 269 -------------- src/Control/HTTPApplication.php | 3 - src/Control/HTTPRequest.php | 23 -- .../Middleware/HTTPCacheControlMiddleware.php | 7 - src/Control/RequestFilter.php | 32 -- src/Control/RequestProcessor.php | 80 ---- src/Control/Session.php | 1 - src/Control/SimpleResourceURLGenerator.php | 44 +-- src/Core/ClassInfo.php | 21 -- src/Core/Config/Config_ForClass.php | 16 - src/Core/Config/Configurable.php | 30 -- src/Core/Convert.php | 101 +---- src/Core/Extensible.php | 1 - src/Core/Injector/Injector.php | 14 - src/Core/Manifest/Module.php | 90 +---- .../Startup/AbstractConfirmationToken.php | 200 ---------- src/Core/Startup/ConfirmationTokenChain.php | 187 ---------- src/Core/Startup/ErrorControlChain.php | 262 ------------- .../Startup/ErrorControlChainMiddleware.php | 163 -------- src/Core/Startup/ErrorDirector.php | 58 --- .../Startup/ParameterConfirmationToken.php | 165 --------- src/Core/Startup/URLConfirmationToken.php | 143 ------- src/Dev/Backtrace.php | 4 +- src/Dev/CSVParser.php | 341 ----------------- src/Dev/CsvBulkLoader.php | 118 ------ src/Dev/DebugView.php | 63 ---- src/Dev/Deprecation.php | 111 ------ src/Dev/FunctionalTest.php | 47 --- src/Dev/Install/DatabaseAdapterRegistry.php | 9 +- src/Dev/InstallerTest.php | 28 -- src/Dev/SapphireInfo.php | 60 --- src/Dev/SapphireTest.php | 98 ----- src/Dev/Tasks/MigrateFileTask.php | 350 ------------------ src/Forms/FieldList.php | 66 +--- src/Forms/Form.php | 30 +- src/Forms/FormField.php | 1 - src/Forms/GridField/GridFieldFilterHeader.php | 174 +-------- .../GridField/GridFieldSortableHeader.php | 2 +- .../GridField/GridFieldVersionedState.php | 23 -- src/Forms/HTMLEditor/TinyMCEConfig.php | 22 -- src/Forms/PasswordField.php | 10 - src/Forms/TextField.php | 17 - src/Logging/MonologErrorHandler.php | 30 -- src/ORM/ArrayList.php | 23 -- src/ORM/Connect/Database.php | 7 +- src/ORM/Connect/MySQLDatabase.php | 8 +- src/ORM/Connect/MySQLSchemaManager.php | 2 +- src/ORM/Connect/MySQLTransactionManager.php | 2 - src/ORM/Connect/NullDatabase.php | 4 +- src/ORM/Connect/Query.php | 9 - src/ORM/DB.php | 12 - src/ORM/DataExtension.php | 10 - src/ORM/DataObject.php | 60 +-- src/ORM/DataQuery.php | 2 +- src/ORM/DatabaseAdmin.php | 17 - src/ORM/FieldType/DBClassName.php | 12 - src/ORM/ManyManyThroughQueryManipulator.php | 13 +- src/ORM/Queries/SQLConditionalExpression.php | 10 - src/ORM/Queries/SQLSelect.php | 9 - src/ORM/Search/SearchContext.php | 10 - src/ORM/ValidationResult.php | 47 +-- src/Security/LoginAttempt.php | 7 +- src/Security/LoginForm.php | 9 +- src/Security/Member.php | 187 +--------- .../MemberAuthenticator.php | 2 +- src/Security/MemberPassword.php | 1 - src/Security/PasswordValidator.php | 52 +-- src/Security/Permission.php | 85 ----- src/Security/RandomGenerator.php | 25 -- src/Security/Security.php | 148 -------- src/View/Embed/EmbedResource.php | 153 -------- src/View/Requirements.php | 14 +- src/View/Requirements_Backend.php | 93 +---- src/View/Requirements_Minifier.php | 22 -- src/View/SSViewer.php | 29 -- src/View/SSViewer_BasicIteratorSupport.php | 22 -- .../Shortcodes/EmbedShortcodeProvider.php | 27 -- src/View/ViewableData.php | 31 -- src/conf/ConfigureFromEnv.php | 10 - src/i18n/Data/Sources.php | 12 +- .../Symfony/FlushInvalidatedResource.php | 30 +- src/i18n/TextCollection/i18nTextCollector.php | 19 +- src/i18n/i18n.php | 17 +- tests/behat/src/CmsUiContext.php | 9 - tests/php/Control/DirectorTest.php | 42 --- .../DirectorTest/TestRequestFilter.php | 3 +- .../Control/Email/MailerSubscriberTest.php | 8 +- tests/php/Control/HTTPRequestTest.php | 22 -- tests/php/Control/HTTPTest.php | 84 ----- tests/php/Core/Config/ConfigTest.php | 36 +- tests/php/Core/ConvertTest.php | 192 ---------- tests/php/Core/Injector/InjectorTest.php | 2 +- tests/php/Core/ObjectTest.php | 57 --- tests/php/Dev/CSVParserTest.php | 159 -------- .../GridField/GridFieldFilterHeaderTest.php | 12 - tests/php/Logging/MonologErrorHandlerTest.php | 6 - tests/php/ORM/ArrayListTest.php | 1 - tests/php/ORM/DatabaseTest.php | 2 +- .../BasicAuthTest/ControllerNotSecured.php | 8 - tests/php/Security/RandomGeneratorTest.php | 11 - tests/php/View/RequirementsTest.php | 1 - tests/php/View/SSViewerTest.php | 61 --- tests/php/View/ViewableDataTest.php | 19 - 110 files changed, 90 insertions(+), 5558 deletions(-) delete mode 100644 src/Control/Email/Mailer.php delete mode 100644 src/Control/RequestFilter.php delete mode 100644 src/Control/RequestProcessor.php delete mode 100644 src/Core/Startup/AbstractConfirmationToken.php delete mode 100644 src/Core/Startup/ConfirmationTokenChain.php delete mode 100644 src/Core/Startup/ErrorControlChain.php delete mode 100644 src/Core/Startup/ErrorControlChainMiddleware.php delete mode 100644 src/Core/Startup/ErrorDirector.php delete mode 100644 src/Core/Startup/ParameterConfirmationToken.php delete mode 100644 src/Core/Startup/URLConfirmationToken.php delete mode 100644 src/Dev/CSVParser.php delete mode 100644 src/Dev/InstallerTest.php delete mode 100644 src/Dev/SapphireInfo.php delete mode 100644 src/Dev/Tasks/MigrateFileTask.php delete mode 100644 src/Forms/GridField/GridFieldVersionedState.php delete mode 100644 src/View/Embed/EmbedResource.php delete mode 100644 src/View/Requirements_Minifier.php delete mode 100644 src/conf/ConfigureFromEnv.php delete mode 100644 tests/php/Dev/CSVParserTest.php diff --git a/.upgrade.yml b/.upgrade.yml index 4a1a15a81..dff65daae 100644 --- a/.upgrade.yml +++ b/.upgrade.yml @@ -176,8 +176,6 @@ mappings: SS_ClassManifest: SilverStripe\Core\Manifest\ClassManifest SilverStripe\Core\Manifest\SS_ClassManifest: SilverStripe\Core\Manifest\ClassManifest ManifestFileFinder: SilverStripe\Core\Manifest\ManifestFileFinder - ErrorControlChain: SilverStripe\Core\Startup\ErrorControlChain - ParameterConfirmationToken: SilverStripe\Core\Startup\ParameterConfirmationToken DatabaseAdapterRegistry: SilverStripe\Dev\Install\DatabaseAdapterRegistry DatabaseConfigurationHelper: SilverStripe\Dev\Install\DatabaseConfigurationHelper MySQLDatabaseConfigurationHelper: SilverStripe\Dev\Install\MySQLDatabaseConfigurationHelper @@ -192,7 +190,6 @@ mappings: CliDebugView: SilverStripe\Dev\CliDebugView CSSContentParser: SilverStripe\Dev\CSSContentParser CsvBulkLoader: SilverStripe\Dev\CsvBulkLoader - CSVParser: SilverStripe\Dev\CSVParser Debug: SilverStripe\Dev\Debug DebugView: SilverStripe\Dev\DebugView Deprecation: SilverStripe\Dev\Deprecation @@ -201,7 +198,6 @@ mappings: FixtureBlueprint: SilverStripe\Dev\FixtureBlueprint FixtureFactory: SilverStripe\Dev\FixtureFactory FunctionalTest: SilverStripe\Dev\FunctionalTest - InstallerTest: SilverStripe\Dev\InstallerTest MigrationTask: SilverStripe\Dev\MigrationTask SapphireTest: SilverStripe\Dev\SapphireTest TaskRunner: SilverStripe\Dev\TaskRunner @@ -229,17 +225,13 @@ mappings: NestedController: SilverStripe\Control\NestedController NullHTTPRequest: SilverStripe\Control\NullHTTPRequest PjaxResponseNegotiator: SilverStripe\Control\PjaxResponseNegotiator - RequestFilter: SilverStripe\Control\RequestFilter RequestHandler: SilverStripe\Control\RequestHandler - RequestProcessor: SilverStripe\Control\RequestProcessor Session: SilverStripe\Control\Session Email: SilverStripe\Control\Email\Email - Mailer: SilverStripe\Control\Email\Mailer RSSFeed: SilverStripe\Control\RSS\RSSFeed RSSFeed_Entry: SilverStripe\Control\RSS\RSSFeed_Entry CleanupTestDatabasesTask: SilverStripe\Dev\Tasks\CleanupTestDatabasesTask i18nTextCollectorTask: SilverStripe\Dev\Tasks\i18nTextCollectorTask - MigrateFileTask: SilverStripe\Dev\Tasks\MigrateFileTask CheckboxField: SilverStripe\Forms\CheckboxField CheckboxField_Readonly: SilverStripe\Forms\CheckboxField_Readonly CheckboxSetField: SilverStripe\Forms\CheckboxSetField @@ -372,7 +364,6 @@ mappings: GenericTemplateGlobalProvider: SilverStripe\View\GenericTemplateGlobalProvider Requirements: SilverStripe\View\Requirements Requirements_Backend: SilverStripe\View\Requirements_Backend - Requirements_Minifier: SilverStripe\View\Requirements_Minifier SSTemplateParseException: SilverStripe\View\SSTemplateParseException SSTemplateParser: SilverStripe\View\SSTemplateParser SSViewer_Scope: SilverStripe\View\SSViewer_Scope @@ -487,7 +478,6 @@ mappings: CsvBulkLoaderTest_Team: SilverStripe\Dev\Tests\CsvBulkLoaderTest\Team CsvBulkLoaderTest_Player: SilverStripe\Dev\Tests\CsvBulkLoaderTest\Player CsvBulkLoaderTest_PlayerContract: SilverStripe\Dev\Tests\CsvBulkLoaderTest\PlayerContract - CSVParserTest: SilverStripe\Dev\Tests\CSVParserTest DeprecationTest_Deprecation: SilverStripe\Dev\Tests\DeprecationTest\TestDeprecation DeprecationTest: SilverStripe\Dev\Tests\DeprecationTest DevAdminControllerTest: SilverStripe\Dev\Tests\DevAdminControllerTest @@ -847,11 +837,6 @@ mappings: ThemeResourceLoaderTest: SilverStripe\Core\Tests\Manifest\ThemeResourceLoaderTest EmailTest: SilverStripe\Control\Tests\Email\EmailTest MailerTest: SilverStripe\Control\Tests\Email\SwiftMailerTest - ErrorControlChainTest_Chain: SilverStripe\Core\Tests\Startup\ErrorControlChainTest\ErrorControlChainTest_Chain - ErrorControlChainTest: SilverStripe\Core\Tests\Startup\ErrorControlChainTest - ParameterConfirmationTokenTest_Token: SilverStripe\Core\Tests\Startup\ParameterConfirmationTokenTest\ParameterConfirmationTokenTest_Token - ParameterConfirmationTokenTest_ValidToken: SilverStripe\Core\Tests\Startup\ParameterConfirmationTokenTest\ParameterConfirmationTokenTest_ValidToken - ParameterConfirmationTokenTest: SilverStripe\Core\Tests\Startup\ParameterConfirmationTokenTest ConfigTest_DefinesFoo: SilverStripe\Core\Tests\Config\ConfigTest\DefinesFoo ConfigTest_DefinesBar: SilverStripe\Core\Tests\Config\ConfigTest\DefinesBar ConfigTest_DefinesFooAndBar: SilverStripe\Core\Tests\Config\ConfigTest\DefinesFooAndBar @@ -981,8 +966,6 @@ warnings: message: 'Renamed to CMSMain_TreeNode' 'HTMLEditorField_Toolbar': message: 'replaced With SilverStripe\Admin\ModalController' - 'HTMLEditorField_Embed': - message: 'replaced with SilverStripe\View\Embed\EmbedResource' 'HTMLEditorField_File': message: 'Removed' 'HTMLEditorField_Flash': @@ -1009,14 +992,8 @@ warnings: message: 'Use SilverStripe\CMS\BatchActions\CMSBatchAction_Archive instead' 'EncryptAllPasswordsTask': message: 'Removed' - 'SapphireInfo': - message: 'Removed' 'SilverStripe\Dev\SapphireREPL': message: 'Removed' - 'SilverStripe\Dev\SapphireInfo': - message: 'Deprecated' - 'SilverStripe\Dev\InstallerTest': - message: 'Deprecated' methods: 'SilverStripe\Security\Authenticator::register()': message: 'Custom authenticators work differently now' @@ -1309,12 +1286,6 @@ warnings: message: 'Removed SilverStripe\ORM\FieldType\DBDate->day_before()' 'days_between()': message: 'Removed SilverStripe\ORM\FieldType\DBDate->days_between()' - 'SilverStripe\Security\Permission::get_declared_permissions_list()': - message: 'Deprecated' - 'SilverStripe\Security\Permission::get_label_for_permission()': - message: 'Deprecated' - 'SilverStripe\Security\Permission::traverse_declared_permissions()': - message: 'Deprecated' 'SilverStripe\Control\Session::get_all()': message: 'Session can not be accessed statically and `get_all()` is now called `getAll()' 'SilverStripe\Control\Session::clear_all()': @@ -1336,10 +1307,6 @@ warnings: message: 'Renamed to combineFiles' replacement: 'combineFiles' url: 'https://docs.silverstripe.org/en/4/changelogs/4.0.0#requirements' - 'SilverStripe\View\Requirements_Backend->combine_js_with_min': - message: 'Renamed to $minifyCombinedFiles' - url: 'https://docs.silverstripe.org/en/4/changelogs/4.0.0#requirements' - replacement: 'minifyCombinedFiles' 'SilverStripe\View\Requirements_Backend->write_header_comments': message: 'Renamed to writeHeaderComment' url: 'https://docs.silverstripe.org/en/4/changelogs/4.0.0#requirements' @@ -1350,12 +1317,6 @@ warnings: replacement: 'writeJavascriptToBody' 'SilverStripe\Forms\Formfield->dontEscape': message: 'FormField::$dontEscape has been removed. Escaping is now managed on a class by class basis.' - 'SilverStripe\Security\LoginForm->authenticator_class': - message: 'authenticator_class is deprecated. Use getAuthenticatorClass/setAuthenticatorClass.' - 'SilverStripe\Security\Permission->declared_permissions': - message: 'Deprecated' - 'SilverStripe\Security\Permission->declared_permissions_list': - message: 'Deprecated' functions: 'file_get_contents()': message: 'Use new asset abstraction' @@ -1428,8 +1389,6 @@ visibilities: visibility: private 'SilverStripe\ORM\DataObject::default_classname': visibility: private - 'SilverStripe\ORM\DataObject->destroyed': - visibility: public 'SilverStripe\ORM\DataObject->record': visibility: protected 'SilverStripe\ORM\DataObject->joinRecord': diff --git a/_config/backtrace.yml b/_config/backtrace.yml index f7b657c28..fb19e77fd 100644 --- a/_config/backtrace.yml +++ b/_config/backtrace.yml @@ -12,9 +12,6 @@ SilverStripe\Dev\Backtrace: - ['SilverStripe\Control\Middleware\ConfirmationMiddleware\GetParameter', buildConfirmationItem] - ['SilverStripe\Control\Middleware\ConfirmationMiddleware\Url', buildConfirmationItem] - ['SilverStripe\Control\Middleware\ConfirmationMiddleware\UrlPathStartswith', buildConfirmationItem] - - ['SilverStripe\Core\Startup\AbstractConfirmationToken', 'checkToken'] - - ['SilverStripe\Core\Startup\AbstractConfirmationToken', 'pathForToken'] - - ['SilverStripe\Core\Startup\AbstractConfirmationToken', 'prepare_tokens'] - ['SilverStripe\ORM\DB', 'connect'] - ['SilverStripe\ORM\DB', 'createDatabase'] - ['SilverStripe\Security\Confirmation\Item', '__construct'] @@ -33,9 +30,7 @@ SilverStripe\Dev\Backtrace: - ['SilverStripe\Security\PasswordEncryptor_Blowfish', 'encryptY'] - ['SilverStripe\Security\PasswordValidator', 'validate'] - ['SilverStripe\Security\RememberLoginHash', 'setToken'] - - ['SilverStripe\Security\Security', 'check_default_admin'] - ['SilverStripe\Security\Security', 'encrypt_password'] - - ['SilverStripe\Security\Security', 'setDefaultAdmin'] - ['*', 'checkPassword'] - ['*', 'onAfterChangePassword'] - ['*', 'onBeforeChangePassword'] diff --git a/_config/requestprocessors.yml b/_config/requestprocessors.yml index 777fba21e..46d9c72cf 100644 --- a/_config/requestprocessors.yml +++ b/_config/requestprocessors.yml @@ -3,13 +3,12 @@ Name: requestprocessors --- SilverStripe\Core\Injector\Injector: SilverStripe\Control\Director: - # Note: Don't add 'class' config here, as it will affect ErrorDirector as well + # Note: Don't add 'class' config here properties: Middlewares: TrustedProxyMiddleware: '%$SilverStripe\Control\Middleware\TrustedProxyMiddleware' AllowedHostsMiddleware: '%$SilverStripe\Control\Middleware\AllowedHostsMiddleware' SessionMiddleware: '%$SilverStripe\Control\Middleware\SessionMiddleware' - RequestProcessorMiddleware: '%$SilverStripe\Control\RequestProcessor' FlushMiddleware: '%$SilverStripe\Control\Middleware\FlushMiddleware' ChangeDetectionMiddleware: '%$SilverStripe\Control\Middleware\ChangeDetectionMiddleware' HTTPCacheControleMiddleware: '%$SilverStripe\Control\Middleware\HTTPCacheControlMiddleware' @@ -33,16 +32,6 @@ SilverStripe\Core\Injector\Injector: Middlewares: - '%$SecurityRateLimitMiddleware' ---- -Name: errorrequestprocessors -After: - - '#requestprocessors' ---- -SilverStripe\Core\Injector\Injector: - # Note: If Director config changes, take note it will affect this config too - SilverStripe\Core\Startup\ErrorDirector: '%$SilverStripe\Control\Director' - - --- Name: canonicalurls --- diff --git a/src/Control/Controller.php b/src/Control/Controller.php index 4d53bc37e..fa3ae3f36 100644 --- a/src/Control/Controller.php +++ b/src/Control/Controller.php @@ -4,10 +4,7 @@ namespace SilverStripe\Control; use SilverStripe\Core\ClassInfo; use SilverStripe\Dev\Debug; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\FieldType\DBHTMLText; -use SilverStripe\Security\BasicAuth; -use SilverStripe\Security\BasicAuthMiddleware; use SilverStripe\Security\Member; use SilverStripe\Security\Security; use SilverStripe\View\SSViewer; @@ -62,13 +59,6 @@ class Controller extends RequestHandler implements TemplateGlobalProvider */ protected $templates = []; - /** - * @deprecated 4.1.0:5.0.0 Add this controller's url to - * SilverStripe\Security\BasicAuthMiddleware.URLPatterns injected property instead of setting false - * @var bool - */ - protected $basicAuthEnabled = true; - /** * The response object that the controller returns. * @@ -106,11 +96,6 @@ class Controller extends RequestHandler implements TemplateGlobalProvider */ protected function init() { - // @todo This will be removed in 5.0 and will be controlled by middleware instead - if ($this->basicAuthEnabled) { - BasicAuth::protect_site_if_necessary(); - } - // This is used to test that subordinate controllers are actually calling parent::init() - a common bug $this->baseInitCalled = true; } @@ -523,19 +508,6 @@ class Controller extends RequestHandler implements TemplateGlobalProvider return $template->process($obj); } - /** - * Call this to disable site-wide basic authentication for a specific controller. This must be - * called before Controller::init(). That is, you must call it in your controller's init method - * before it calls parent::init(). - * - * @deprecated 4.1.0 Add this controller's url to SilverStripe\Security\BasicAuthMiddleware.URLPatterns injected property instead - */ - public function disableBasicAuth() - { - Deprecation::notice('4.1.0', 'Add this controller\'s url to SilverStripe\Security\BasicAuthMiddleware.URLPatterns injected property instead'); - $this->basicAuthEnabled = false; - } - /** * Returns the current controller. * diff --git a/src/Control/CookieJar.php b/src/Control/CookieJar.php index 6c3b0a26c..fb71bbc6e 100644 --- a/src/Control/CookieJar.php +++ b/src/Control/CookieJar.php @@ -2,7 +2,6 @@ namespace SilverStripe\Control; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\FieldType\DBDatetime; use LogicException; diff --git a/src/Control/Director.php b/src/Control/Director.php index 880561253..8c749d1f1 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -12,7 +12,6 @@ use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Kernel; use SilverStripe\Core\Path; -use SilverStripe\Dev\Deprecation; use SilverStripe\Versioned\Versioned; use SilverStripe\View\Requirements; use SilverStripe\View\Requirements_Backend; @@ -375,34 +374,6 @@ class Director implements TemplateGlobalProvider return $response; } - /** - * Returns indication whether the manifest cache has been flushed - * in the beginning of the current request. - * - * That could mean the current active request has `?flush` parameter. - * Another possibility is a race condition when the current request - * hits the server in between another request `?flush` authorisation - * and a redirect to the actual flush. - * - * @return bool - * - * @deprecated 4.12.0 Use Kernel::isFlushed instead - */ - public static function isManifestFlushed() - { - Deprecation::notice('4.12.0', 'Use Kernel::isFlushed instead'); - $kernel = Injector::inst()->get(Kernel::class); - - // Only CoreKernel implements this method at the moment - // Introducing it to the Kernel interface is a breaking change - if (method_exists($kernel, 'isFlushed')) { - return $kernel->isFlushed(); - } - - $classManifest = $kernel->getClassLoader()->getManifest(); - return $classManifest->isFlushed(); - } - /** * Return the {@link SiteTree} object that is currently being viewed. If there is no SiteTree * object to return, then this will return the current controller. @@ -433,19 +404,9 @@ class Director implements TemplateGlobalProvider * - BASE - Append this path to the base url (i.e. behaves as though `` tag is provided in a html document). This is the default. * - REQUEST - Resolve this path to the current url (i.e. behaves as though no `` tag is provided in a html document) * - ROOT - Treat this as though it was an absolute path, and append it to the protocol and hostname. - * - * @param string $url The url or path to resolve to absolute url. - * @param string $relativeParent Disambiguation method to use for evaluating relative paths - * @return string The absolute url */ - public static function absoluteURL($url, $relativeParent = self::BASE) + public static function absoluteURL(string $url, string $relativeParent = self::BASE): string|bool { - if (is_bool($relativeParent)) { - // Deprecate old boolean second parameter - Deprecation::notice('5.0', 'Director::absoluteURL takes an explicit parent for relative url'); - $relativeParent = $relativeParent ? self::BASE : self::REQUEST; - } - // Check if there is already a protocol given if (preg_match('/^http(s?):\/\//', $url ?? '')) { return $url; @@ -1151,7 +1112,7 @@ class Director implements TemplateGlobalProvider 'isLive', 'is_ajax', 'isAjax' => 'is_ajax', - 'BaseHref' => 'absoluteBaseURL', //@deprecated 3.0 + 'BaseHref' => 'absoluteBaseURL', ]; } diff --git a/src/Control/Email/Mailer.php b/src/Control/Email/Mailer.php deleted file mode 100644 index e90342bb8..000000000 --- a/src/Control/Email/Mailer.php +++ /dev/null @@ -1,16 +0,0 @@ -setMaxAge($age) instead - * @var int - */ - protected static $cache_age = 0; - - /** - * @deprecated 4.2.0:5.0.0 Handled by HTTPCacheControlMiddleware - * @var int - */ - protected static $modification_date = null; - - /** - * @deprecated 4.2.0:5.0.0 Handled by ChangeDetectionMiddleware - * @var string - */ - protected static $etag = null; - - /** - * @config - * @var bool - * @deprecated 4.2.0:5.0.0 'HTTP.cache_ajax_requests config is deprecated. - * Use HTTPCacheControlMiddleware::disableCache() instead' - */ - private static $cache_ajax_requests = false; - - /** - * @config - * @var bool - * @deprecated 4.2.0:5.0.0 Use HTTPCacheControlMiddleware.defaultState/.defaultForcingLevel instead - */ - private static $disable_http_cache = false; - /** * Set to true to disable all deprecated HTTP Cache settings * @@ -68,25 +31,6 @@ class HTTP */ private static $MimeTypes = []; - /** - * List of names to add to the Cache-Control header. - * - * @deprecated 4.2.0:5.0.0 Handled by HTTPCacheControlMiddleware instead - * @see HTTPCacheControlMiddleware::__construct() - * @config - * @var array Keys are cache control names, values are boolean flags - */ - private static $cache_control = []; - - /** - * Vary string; A comma separated list of var header names - * - * @deprecated 4.2.0:5.0.0 Handled by HTTPCacheControlMiddleware instead - * @config - * @var string|null - */ - private static $vary = null; - /** * Turns a local system filename into a URL by comparing it to the script filename. * @@ -368,217 +312,4 @@ class HTTP return $mimeTypes[$ext]; } - - /** - * Set the maximum age of this page in web caches, in seconds. - * - * @deprecated 4.2.0 Use HTTPCacheControlMiddleware::singleton()->setMaxAge($age) instead - * @param int $age - */ - public static function set_cache_age($age) - { - Deprecation::notice('4.2.0', 'Use HTTPCacheControlMiddleware::singleton()->setMaxAge($age) instead'); - self::$cache_age = $age; - HTTPCacheControlMiddleware::singleton()->setMaxAge($age); - } - - /** - * @param string $dateString - * @deprecated 4.2.0 Use HTTPCacheControlMiddleware::registerModificationDate() instead - */ - public static function register_modification_date($dateString) - { - Deprecation::notice('4.2.0', 'Use HTTPCacheControlMiddleware::registerModificationDate() instead'); - HTTPCacheControlMiddleware::singleton()->registerModificationDate($dateString); - } - - /** - * @param int $timestamp - * @deprecated 4.2.0 Use HTTPCacheControlMiddleware::registerModificationDate() instead - */ - public static function register_modification_timestamp($timestamp) - { - Deprecation::notice('4.2.0', 'Use HTTPCacheControlMiddleware::registerModificationDate() instead'); - HTTPCacheControlMiddleware::singleton()->registerModificationDate($timestamp); - } - - /** - * @deprecated 4.2.0 Use ChangeDetectionMiddleware instead - * @param string $etag - */ - public static function register_etag($etag) - { - Deprecation::notice('4.2.0', 'Use ChangeDetectionMiddleware instead'); - if (strpos($etag ?? '', '"') !== 0) { - $etag = "\"{$etag}\""; - } - self::$etag = $etag; - } - - /** - * Add the appropriate caching headers to the response, including If-Modified-Since / 304 handling. - * Note that setting HTTP::$cache_age will overrule any cache headers set by PHP's - * session_cache_limiter functionality. It is your responsibility to ensure only cacheable data - * is in fact cached, and HTTP::$cache_age isn't set when the HTTP body contains session-specific - * content. - * - * Omitting the $body argument or passing a string is deprecated; in these cases, the headers are - * output directly. - * - * @param HTTPResponse $response - * @deprecated 4.2.0 Headers are added automatically by HTTPCacheControlMiddleware instead. - */ - public static function add_cache_headers($response = null) - { - Deprecation::notice('4.2.0', 'Headers are added automatically by HTTPCacheControlMiddleware instead.'); - - // Skip if deprecated API is disabled - if (Config::inst()->get(HTTP::class, 'ignoreDeprecatedCaching')) { - return; - } - - // Ensure a valid response object is provided - if (!$response instanceof HTTPResponse) { - user_error("HTTP::add_cache_headers() must be passed an HTTPResponse object", E_USER_WARNING); - return; - } - - // Warn if already assigned cache-control headers - if ($response->getHeader('Cache-Control')) { - trigger_error( - 'Cache-Control header has already been set. ' - . 'Please use HTTPCacheControlMiddleware API to set caching options instead.', - E_USER_WARNING - ); - return; - } - - // Ensure a valid request object exists in the current context - if (!Injector::inst()->has(HTTPRequest::class)) { - user_error("HTTP::add_cache_headers() cannot work without a current HTTPRequest object", E_USER_WARNING); - return; - } - - /** @var HTTPRequest $request */ - $request = Injector::inst()->get(HTTPRequest::class); - - // Run middleware - ChangeDetectionMiddleware::singleton()->process($request, function (HTTPRequest $request) use ($response) { - return HTTPCacheControlMiddleware::singleton()->process($request, function (HTTPRequest $request) use ($response) { - return $response; - }); - }); - } - - /** - * Ensure that all deprecated HTTP cache settings are respected - * - * @deprecated 4.2.0 Use HTTPCacheControlMiddleware instead - * Simply delete this method in CMS 5 and the calls to it from HTTPCacheControlMiddleware - * - * @throws \LogicException - * @param HTTPRequest $request - * @param HTTPResponse $response - */ - public static function augmentState(HTTPRequest $request, HTTPResponse $response) - { - Deprecation::notice('4.2.0', 'Use HTTPCacheControlMiddleware instead'); - // Skip if deprecated API is disabled - $config = Config::forClass(HTTP::class); - if ($config->get('ignoreDeprecatedCaching')) { - return; - } - - $cacheControlMiddleware = HTTPCacheControlMiddleware::singleton(); - - // if http caching is disabled by config, disable it - used on dev environments due to frequently changing - // templates and other data. will be overridden by forced publicCache(true) or privateCache(true) calls - Deprecation::withNoReplacement(function () use ($config, $cacheControlMiddleware) { - if ($config->get('disable_http_cache')) { - $cacheControlMiddleware->disableCache(); - } - }); - - // if no caching ajax requests, disable ajax if is ajax request - Deprecation::withNoReplacement(function () use ($config, $cacheControlMiddleware) { - if (!$config->get('cache_ajax_requests') && Director::is_ajax()) { - $cacheControlMiddleware->disableCache(); - } - }); - - // Pass vary to middleware - $configVary = Deprecation::withNoReplacement(function () use ($config) { - return $config->get('vary'); - }); - if ($configVary) { - $cacheControlMiddleware->addVary($configVary); - } - - // Pass cache_control to middleware - $configCacheControl = Deprecation::withNoReplacement(function () use ($config) { - return $config->get('cache_control'); - }); - if ($configCacheControl) { - $supportedDirectives = ['max-age', 'no-cache', 'no-store', 'must-revalidate']; - if ($foundUnsupported = array_diff(array_keys($configCacheControl ?? []), $supportedDirectives)) { - throw new \LogicException( - 'Found unsupported legacy directives in HTTP.cache_control: ' . - implode(', ', $foundUnsupported) . - '. Please use HTTPCacheControlMiddleware API instead' - ); - } - - if (isset($configCacheControl['max-age'])) { - $cacheControlMiddleware->setMaxAge($configCacheControl['max-age']); - } - - if (isset($configCacheControl['no-cache'])) { - $cacheControlMiddleware->setNoCache((bool)$configCacheControl['no-cache']); - } - - if (isset($configCacheControl['no-store'])) { - $cacheControlMiddleware->setNoStore((bool)$configCacheControl['no-store']); - } - - if (isset($configCacheControl['must-revalidate'])) { - $cacheControlMiddleware->setMustRevalidate((bool)$configCacheControl['must-revalidate']); - } - } - - // Set modification date - if (self::$modification_date) { - Deprecation::notice('5.0', 'Use HTTPCacheControlMiddleware::registerModificationDate() instead'); - $cacheControlMiddleware->registerModificationDate(self::$modification_date); - } - - // Ensure deprecated $etag property is assigned - if (self::$etag && !$cacheControlMiddleware->hasDirective('no-store') && !$response->getHeader('ETag')) { - Deprecation::notice('5.0', 'Etag should not be set explicitly'); - $response->addHeader('ETag', self::$etag); - } - } - - /** - * Return an {@link http://www.faqs.org/rfcs/rfc2822 RFC 2822} date in the GMT timezone (a timestamp - * is always in GMT: the number of seconds since January 1 1970 00:00:00 GMT) - * - * @param int $timestamp - * @deprecated 4.2.0 Use native php function gmdate() instead - * @return string - */ - public static function gmt_date($timestamp) - { - Deprecation::notice('4.2.0', 'Use native php function gmdate() instead'); - return gmdate('D, d M Y H:i:s', $timestamp) . ' GMT'; - } - - /** - * Return static variable cache_age in second - * - * @return int - */ - public static function get_cache_age() - { - return self::$cache_age; - } } diff --git a/src/Control/HTTPApplication.php b/src/Control/HTTPApplication.php index aba380796..d9c1373ae 100644 --- a/src/Control/HTTPApplication.php +++ b/src/Control/HTTPApplication.php @@ -13,9 +13,6 @@ use SilverStripe\Core\Startup\RequestFlushDiscoverer; use SilverStripe\Core\Startup\ScheduledFlushDiscoverer; use SilverStripe\Core\Startup\DeployFlushDiscoverer; -/** - * Invokes the HTTP application within an ErrorControlChain - */ class HTTPApplication implements Application { use HTTPMiddlewareAware; diff --git a/src/Control/HTTPRequest.php b/src/Control/HTTPRequest.php index 8ac2059b1..2ceb7e239 100644 --- a/src/Control/HTTPRequest.php +++ b/src/Control/HTTPRequest.php @@ -2,7 +2,6 @@ namespace SilverStripe\Control; -use SilverStripe\Dev\Deprecation; use ArrayAccess; use BadMethodCallException; use InvalidArgumentException; @@ -903,28 +902,6 @@ class HTTPRequest implements ArrayAccess return in_array(strtoupper($method ?? ''), ['GET','POST','PUT','DELETE','HEAD']); } - /** - * Gets the "real" HTTP method for a request. This method is no longer used to mitigate the risk of web cache - * poisoning. - * - * @see https://www.silverstripe.org/download/security-releases/CVE-2019-19326 - * @param string $origMethod Original HTTP method from the browser request - * @param array $postVars - * @return string HTTP method (all uppercase) - * @deprecated 4.4.7 Will be removed without equivalent functionality - */ - public static function detect_method($origMethod, $postVars) - { - Deprecation::notice('4.4.7', 'Will be removed without equivalent functionality'); - if (isset($postVars['_method'])) { - if (!self::isValidHttpMethod($postVars['_method'])) { - throw new InvalidArgumentException('HTTPRequest::detect_method(): Invalid "_method" parameter'); - } - return strtoupper($postVars['_method'] ?? ''); - } - return $origMethod; - } - /** * Determines whether the request has a session * diff --git a/src/Control/Middleware/HTTPCacheControlMiddleware.php b/src/Control/Middleware/HTTPCacheControlMiddleware.php index 1a64b4b54..4c7f0ab5a 100644 --- a/src/Control/Middleware/HTTPCacheControlMiddleware.php +++ b/src/Control/Middleware/HTTPCacheControlMiddleware.php @@ -3,7 +3,6 @@ namespace SilverStripe\Control\Middleware; use InvalidArgumentException; -use SilverStripe\Control\HTTP; use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse_Exception; @@ -12,7 +11,6 @@ use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Resettable; use SilverStripe\ORM\FieldType\DBDatetime; -use SilverStripe\Dev\Deprecation; class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable { @@ -51,11 +49,6 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable // Update state based on current request and response objects $this->augmentState($request, $response); - // Update state based on deprecated HTTP settings - Deprecation::withNoReplacement(function () use ($request, $response) { - HTTP::augmentState($request, $response); - }); - // Add all headers to this response object $this->applyToResponse($response); diff --git a/src/Control/RequestFilter.php b/src/Control/RequestFilter.php deleted file mode 100644 index 644ae17c0..000000000 --- a/src/Control/RequestFilter.php +++ /dev/null @@ -1,32 +0,0 @@ -filters = $filters; - } - - /** - * Assign a list of request filters - * - * @param RequestFilter[] $filters - * @return $this - */ - public function setFilters($filters) - { - $this->filters = $filters; - return $this; - } - - /** - * @inheritdoc - */ - public function process(HTTPRequest $request, callable $delegate) - { - if ($this->filters) { - Deprecation::notice( - '5.0', - 'Deprecated RequestFilters are in use. Apply HTTPMiddleware to Director.middlewares instead.' - ); - } - - foreach ($this->filters as $filter) { - $res = $filter->preRequest($request); - if ($res === false) { - return new HTTPResponse(_t(__CLASS__ . '.INVALID_REQUEST', 'Invalid request'), 400); - } - } - - $response = $delegate($request); - - foreach ($this->filters as $filter) { - $res = $filter->postRequest($request, $response); - if ($res === false) { - return new HTTPResponse(_t(__CLASS__ . '.REQUEST_ABORTED', 'Request aborted'), 500); - } - } - - return $response; - } -} diff --git a/src/Control/Session.php b/src/Control/Session.php index 5d49b92b3..552f77a0e 100644 --- a/src/Control/Session.php +++ b/src/Control/Session.php @@ -4,7 +4,6 @@ namespace SilverStripe\Control; use BadMethodCallException; use SilverStripe\Core\Config\Configurable; -use SilverStripe\Dev\Deprecation; /** * Handles all manipulation of the session. diff --git a/src/Control/SimpleResourceURLGenerator.php b/src/Control/SimpleResourceURLGenerator.php index 40bd6189d..ae4b59cb4 100644 --- a/src/Control/SimpleResourceURLGenerator.php +++ b/src/Control/SimpleResourceURLGenerator.php @@ -2,7 +2,6 @@ namespace SilverStripe\Control; -use SilverStripe\Dev\Deprecation; use InvalidArgumentException; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; @@ -78,17 +77,8 @@ class SimpleResourceURLGenerator implements ResourceURLGenerator if (strpos($relativePath ?? '', '?') !== false) { list($relativePath, $query) = explode('?', $relativePath ?? ''); } - - // Determine lookup mechanism based on existence of public/ folder. - // From 5.0 onwards only resolvePublicResource() will be used. - if (!Director::publicDir()) { - $ret = Deprecation::withNoReplacement(function () use ($relativePath) { - return $this->resolveUnsecuredResource($relativePath); - }); - list($exists, $absolutePath, $relativePath) = $ret; - } else { - list($exists, $absolutePath, $relativePath) = $this->resolvePublicResource($relativePath); - } + + list($exists, $absolutePath, $relativePath) = $this->resolvePublicResource($relativePath); } if (!$exists) { trigger_error("File {$relativePath} does not exist", E_USER_NOTICE); @@ -160,36 +150,6 @@ class SimpleResourceURLGenerator implements ResourceURLGenerator return [$exists, $absolutePath, $relativePath]; } - /** - * Resolve resource in the absence of a public/ folder - * - * @deprecated 4.1.0 Will be removed without equivalent functionality when public/ folder becomes mandatory - * @param string $relativePath - * @return array List of [$exists, $absolutePath, $relativePath] - */ - protected function resolveUnsecuredResource($relativePath) - { - Deprecation::notice('4.1.0', 'Will be removed without equivalent functionality when public/ folder becomes mandatory'); - // Check if the path requested is public-only, but we have no public folder - $publicOnly = $this->inferPublicResourceRequired($relativePath); - if ($publicOnly) { - trigger_error('Requesting a public resource without a public folder has no effect', E_USER_WARNING); - } - - // Resolve path to base - $absolutePath = Path::join(Director::baseFolder(), $relativePath); - $exists = file_exists($absolutePath ?? ''); - - // Rewrite vendor/ to _resources/ folder - if (stripos($relativePath ?? '', ManifestFileFinder::VENDOR_DIR . DIRECTORY_SEPARATOR) === 0) { - $relativePath = Path::join( - RESOURCES_DIR, - substr($relativePath ?? '', strlen(ManifestFileFinder::VENDOR_DIR ?? '')) - ); - } - return [$exists, $absolutePath, $relativePath]; - } - /** * Determine if the requested $relativePath requires a public-only resource. * An error will occur if this file isn't immediately available in the public/ assets folder. diff --git a/src/Core/ClassInfo.php b/src/Core/ClassInfo.php index 38542c1d3..f127470d3 100644 --- a/src/Core/ClassInfo.php +++ b/src/Core/ClassInfo.php @@ -7,7 +7,6 @@ use ReflectionClass; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Director; use SilverStripe\Core\Manifest\ClassLoader; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DB; use SilverStripe\View\ViewableData; @@ -155,17 +154,6 @@ class ClassInfo }); } - /** - * @deprecated 4.0.1 Use DataObject::getSchema()->baseDataClass() - * @param string $class - * @return string - */ - public static function baseDataClass($class) - { - Deprecation::notice('4.0.1', 'Use DataObject::getSchema()->baseDataClass()'); - return DataObject::getSchema()->baseDataClass($class); - } - /** * Returns a list of classes that inherit from the given class. * The resulting array includes the base class passed @@ -370,15 +358,6 @@ class ClassInfo return strtolower(self::$_cache_methods[$lClass][$lMethod] ?? '') === $lCompclass; } - /** - * @deprecated 4.0.1 Use DataObject::getSchema()->tableForField() - */ - public static function table_for_object_field($candidateClass, $fieldName) - { - Deprecation::notice('4.0.1', 'Use DataObject::getSchema()->tableForField()'); - return DataObject::getSchema()->tableForField($candidateClass, $fieldName); - } - /** * Strip namespace from class * diff --git a/src/Core/Config/Config_ForClass.php b/src/Core/Config/Config_ForClass.php index 5fd1066b3..8e48f73aa 100644 --- a/src/Core/Config/Config_ForClass.php +++ b/src/Core/Config/Config_ForClass.php @@ -2,8 +2,6 @@ namespace SilverStripe\Core\Config; -use SilverStripe\Dev\Deprecation; - class Config_ForClass { /** @@ -37,20 +35,6 @@ class Config_ForClass $this->set($name, $val); } - /** - * Explicit pass-through to Config::update() - * - * @param string $name - * @param mixed $value - * @return $this - * @deprecated 4.12.0 Use merge() instead - */ - public function update($name, $value) - { - Deprecation::notice('4.12.0', 'Use merge() instead'); - return $this->merge($name, $value); - } - /** * Merge a given config * diff --git a/src/Core/Config/Configurable.php b/src/Core/Config/Configurable.php index 6cc007bdb..9d2213259 100644 --- a/src/Core/Config/Configurable.php +++ b/src/Core/Config/Configurable.php @@ -2,8 +2,6 @@ namespace SilverStripe\Core\Config; -use SilverStripe\Dev\Deprecation; - /** * Provides extensions to this object to integrate it with standard config API methods. * @@ -22,19 +20,6 @@ trait Configurable return Config::forClass(get_called_class()); } - /** - * Get inherited config value - * - * @deprecated 5.0 Use ->config()->get() instead - * @param string $name - * @return mixed - */ - public function stat($name) - { - Deprecation::notice('5.0', 'Use ->get'); - return $this->config()->get($name); - } - /** * Gets the uninherited value for the given config option * @@ -45,19 +30,4 @@ trait Configurable { return $this->config()->uninherited($name); } - - /** - * Update the config value for a given property - * - * @deprecated 5.0 Use ->config()->set() instead - * @param string $name - * @param mixed $value - * @return $this - */ - public function set_stat($name, $value) - { - Deprecation::notice('5.0', 'Use ->config()->set()'); - $this->config()->set($name, $value); - return $this; - } } diff --git a/src/Core/Convert.php b/src/Core/Convert.php index 2021e8446..3e8743bcf 100644 --- a/src/Core/Convert.php +++ b/src/Core/Convert.php @@ -2,9 +2,7 @@ namespace SilverStripe\Core; -use InvalidArgumentException; use SimpleXMLElement; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\DB; use SilverStripe\View\Parsers\URLSegmentFilter; @@ -157,37 +155,6 @@ class Convert ); } - /** - * Encode a value as a JSON encoded string. You can optionally pass a bitmask of - * JSON constants as options through to the encode function. - * - * @deprecated 4.4.0 Use json_encode() instead - * @param mixed $val Value to be encoded - * @param int $options Optional bitmask of JSON constants - * @return string JSON encoded string - */ - public static function raw2json($val, $options = 0) - { - Deprecation::notice('4.4.0', 'Use json_encode() instead'); - - return json_encode($val, $options ?? 0); - } - - /** - * Encode an array as a JSON encoded string. - * - * @deprecated 4.4.0 Use json_encode() instead - * @param array $val Array to convert - * @param int $options Optional bitmask of JSON constants - * @return string JSON encoded string - */ - public static function array2json($val, $options = 0) - { - Deprecation::notice('4.4.0', 'Use json_encode() instead'); - - return json_encode($val, $options ?? 0); - } - /** * Safely encodes a value (or list of values) using the current database's * safe string encoding method @@ -258,75 +225,9 @@ class Convert return html_entity_decode($val ?? '', ENT_QUOTES, 'UTF-8'); } - /** - * Convert a JSON encoded string into an object. - * - * @deprecated 4.4.0 Use json_decode() instead - * @param string $val - * @return object|boolean - */ - public static function json2obj($val) - { - Deprecation::notice('4.4.0', 'Use json_decode() instead'); - - return json_decode($val ?? ''); - } - - /** - * Convert a JSON string into an array. - * - * @deprecated 4.4.0 Use json_decode($val, true) instead - * @param string $val JSON string to convert - * @return array|boolean - */ - public static function json2array($val) - { - Deprecation::notice('4.4.0', 'Use json_decode() instead'); - - return json_decode($val ?? '', true); - } - - /** - * Converts an XML string to a PHP array - * See http://phpsecurity.readthedocs.org/en/latest/Injection-Attacks.html#xml-external-entity-injection - * - * @uses recursiveXMLToArray() - * @param string $val - * @param boolean $disableDoctypes Disables the use of DOCTYPE, and will trigger an error if encountered. - * false by default. - * @param boolean $disableExternals Does nothing because xml entities are removed - * @deprecated 4.11.0 Use a dedicated XML library instead - * @return array - * @throws Exception - */ - public static function xml2array($val, $disableDoctypes = false, $disableExternals = false) - { - Deprecation::notice('4.11.0', 'Use a dedicated XML library instead'); - - // Check doctype - if ($disableDoctypes && strpos($val ?? '', '/', '', $val ?? ''); - - // If there's still an present, then it would be the result of a maliciously - // crafted XML document e.g. ENTITY ext SYSTEM "http://evil.com"> - if (strpos($val ?? '', ' before it was removed - $xml = new SimpleXMLElement($val ?? ''); - return self::recursiveXMLToArray($xml); - } - /** * Convert a XML string to a PHP array recursively. Do not - * call this function directly, Please use {@link Convert::xml2array()} + * call this function directly. * * @param SimpleXMLElement $xml * diff --git a/src/Core/Extensible.php b/src/Core/Extensible.php index 85b2778e4..da66ebed7 100644 --- a/src/Core/Extensible.php +++ b/src/Core/Extensible.php @@ -5,7 +5,6 @@ namespace SilverStripe\Core; use InvalidArgumentException; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; use SilverStripe\View\ViewableData; /** diff --git a/src/Core/Injector/Injector.php b/src/Core/Injector/Injector.php index 73b33e8a2..75b971d0c 100644 --- a/src/Core/Injector/Injector.php +++ b/src/Core/Injector/Injector.php @@ -8,11 +8,9 @@ use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use ReflectionMethod; use ReflectionObject; -use ReflectionProperty; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Environment; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\DataObject; /** @@ -853,18 +851,6 @@ class Injector implements ContainerInterface } } - /** - * @deprecated 4.0.1 Use Injector::has() instead - * @param $name - * @return string - */ - public function hasService($name) - { - Deprecation::notice('4.0.1', 'Use Injector::has() instead'); - - return $this->has($name); - } - /** * Does the given service exist? * diff --git a/src/Core/Manifest/Module.php b/src/Core/Manifest/Module.php index c6b0517a8..b335dbc2d 100644 --- a/src/Core/Manifest/Module.php +++ b/src/Core/Manifest/Module.php @@ -4,21 +4,14 @@ namespace SilverStripe\Core\Manifest; use Exception; use InvalidArgumentException; -use Serializable; use SilverStripe\Core\Path; -use SilverStripe\Dev\Deprecation; /** * Abstraction of a PHP Package. Can be used to retrieve information about Silverstripe CMS modules, and other packages * managed via composer, by reading their `composer.json` file. */ -class Module implements Serializable +class Module { - /** - * @deprecated 4.1.0:5.0.0 Use Path::normalise() instead - */ - const TRIM_CHARS = ' /\\'; - /** * Full directory path to this module with no trailing slash * @@ -182,34 +175,7 @@ class Module implements Serializable $this->composerData = $data['composerData']; $this->resources = []; } - - /** - * The __serialize() magic method will be automatically used instead of this - * - * @return string - * @deprecated 4.12.0 Use __serialize() instead - */ - public function serialize() - { - Deprecation::notice('4.12.0', 'Use __serialize() instead'); - return json_encode([$this->path, $this->basePath, $this->composerData]); - } - - /** - * The __unserialize() magic method will be automatically used instead of this almost all the time - * This method will be automatically used if existing serialized data was not saved as an associative array - * and the PHP version used in less than PHP 9.0 - * - * @param string $serialized - * @deprecated 4.12.0 Use __unserialize() instead - */ - public function unserialize($serialized) - { - Deprecation::notice('4.12.0', 'Use __unserialize() instead'); - list($this->path, $this->basePath, $this->composerData) = json_decode($serialized ?? '', true); - $this->resources = []; - } - + /** * Activate _config.php for this module, if one exists */ @@ -256,58 +222,6 @@ class Module implements Serializable } return $this->resources[$path] = new ModuleResource($this, $path); } - - /** - * @deprecated 4.0.1 Use getResource($path)->getRelativePath() instead - * @param string $path - * @return string - */ - public function getRelativeResourcePath($path) - { - Deprecation::notice('4.0.1', 'Use getResource($path)->getRelativePath() instead'); - return $this - ->getResource($path) - ->getRelativePath(); - } - - /** - * @deprecated 4.0.1 Use getResource($path)->getPath() instead - * @param string $path - * @return string - */ - public function getResourcePath($path) - { - Deprecation::notice('4.0.1', 'Use getResource($path)->getPath() instead'); - return $this - ->getResource($path) - ->getPath(); - } - - /** - * @deprecated 4.0.1 Use getResource($path)->getURL() instead - * @param string $path - * @return string - */ - public function getResourceURL($path) - { - Deprecation::notice('4.0.1', 'Use getResource($path)->getURL() instead'); - return $this - ->getResource($path) - ->getURL(); - } - - /** - * @deprecated 4.0.1 Use getResource($path)->exists() instead - * @param string $path - * @return string - */ - public function hasResource($path) - { - Deprecation::notice('4.0.1', 'Use getResource($path)->exists() instead'); - return $this - ->getResource($path) - ->exists(); - } } /** diff --git a/src/Core/Startup/AbstractConfirmationToken.php b/src/Core/Startup/AbstractConfirmationToken.php deleted file mode 100644 index 00c03ead8..000000000 --- a/src/Core/Startup/AbstractConfirmationToken.php +++ /dev/null @@ -1,200 +0,0 @@ -reloadRequired() || $token->reloadRequiredIfError()) { - $token->suppress(); - $target = $token; - } - } - return $target; - } - - /** - * Generate a local filesystem path to store a token - * - * @param $token - * @return string - */ - protected function pathForToken($token) - { - return TEMP_PATH . DIRECTORY_SEPARATOR . 'token_' . preg_replace('/[^a-z0-9]+/', '', $token ?? ''); - } - - /** - * Generate a new random token and store it - * - * @return string Token name - */ - protected function genToken() - { - // Generate a new random token (as random as possible) - $rg = new RandomGenerator(); - $token = $rg->randomToken('md5'); - - // Store a file in the session save path (safer than /tmp, as open_basedir might limit that) - file_put_contents($this->pathForToken($token) ?? '', $token); - - return $token; - } - - /** - * Is the necessary token provided for this parameter? - * A value must be provided for the token - * - * @return bool - */ - public function tokenProvided() - { - return !empty($this->token); - } - - /** - * Validate a token - * - * @param string $token - * @return boolean True if the token is valid - */ - protected function checkToken($token) - { - if (!$token) { - return false; - } - - $file = $this->pathForToken($token); - $content = null; - - if (file_exists($file ?? '')) { - $content = file_get_contents($file ?? ''); - unlink($file ?? ''); - } - - return $content === $token; - } - - /** - * Get redirect url, excluding querystring - * - * @return string - */ - public function currentURL() - { - return Controller::join_links(Director::baseURL(), $this->request->getURL(false)); - } - - /** - * Forces a reload of the request with the token included - * - * @return HTTPResponse - */ - public function reloadWithToken() - { - $location = $this->redirectURL(); - $locationJS = Convert::raw2js($location); - $locationATT = Convert::raw2att($location); - $body = <<location.href='$locationJS'; - -You are being redirected. If you are not redirected soon, click here to continue -HTML; - - // Build response - $result = new HTTPResponse($body); - $result->redirect($location); - return $result; - } - - /** - * Is this parameter requested without a valid token? - * - * @return bool True if the parameter is given without a valid token - */ - abstract public function reloadRequired(); - - /** - * Check if this token is provided either in the backurl, or directly, - * but without a token - * - * @return bool - */ - abstract public function reloadRequiredIfError(); - - /** - * Suppress the current parameter for the duration of this request - */ - abstract public function suppress(); - - /** - * Determine the querystring parameters to include - * - * @param bool $includeToken Include the token value? - * @return array List of querystring parameters, possibly including token parameter - */ - abstract public function params($includeToken = true); - - /** - * @return string - */ - abstract public function getRedirectUrlBase(); - - /** - * @return array - */ - abstract public function getRedirectUrlParams(); - - /** - * Get redirection URL - * - * @return string - */ - abstract protected function redirectURL(); -} diff --git a/src/Core/Startup/ConfirmationTokenChain.php b/src/Core/Startup/ConfirmationTokenChain.php deleted file mode 100644 index aa6b29610..000000000 --- a/src/Core/Startup/ConfirmationTokenChain.php +++ /dev/null @@ -1,187 +0,0 @@ -tokens[] = $token; - } - - /** - * Collect all tokens that require a redirect - * - * @return \Generator - */ - protected function filteredTokens() - { - foreach ($this->tokens as $token) { - if ($token->reloadRequired() || $token->reloadRequiredIfError()) { - yield $token; - } - } - } - - /** - * @return bool - */ - public function suppressionRequired() - { - foreach ($this->tokens as $token) { - if ($token->reloadRequired()) { - return true; - } - } - - return false; - } - - /** - * Suppress URLs & GET vars from tokens that require a redirect - */ - public function suppressTokens() - { - foreach ($this->filteredTokens() as $token) { - $token->suppress(); - } - } - - /** - * @return bool - */ - public function reloadRequired() - { - foreach ($this->tokens as $token) { - if ($token->reloadRequired()) { - return true; - } - } - - return false; - } - - /** - * @return bool - */ - public function reloadRequiredIfError() - { - foreach ($this->tokens as $token) { - if ($token->reloadRequiredIfError()) { - return true; - } - } - - return false; - } - - /** - * @param bool $includeToken - * @return array - */ - public function params($includeToken = true) - { - $params = []; - foreach ($this->tokens as $token) { - $params = array_merge($params, $token->params($includeToken)); - } - - return $params; - } - - /** - * Fetch the URL we want to redirect to, excluding query string parameters. This may - * be the same URL (with a token to be added outside this method), or to a different - * URL if the current one has been suppressed - * - * @return string - */ - public function getRedirectUrlBase() - { - // URLConfirmationTokens may alter the URL to suppress the URL they're protecting, - // so we need to ensure they're inspected last and therefore take priority - $tokens = iterator_to_array($this->filteredTokens(), false); - usort($tokens, function ($a, $b) { - return ($a instanceof URLConfirmationToken) ? 1 : 0; - }); - - $urlBase = Director::baseURL(); - foreach ($tokens as $token) { - $urlBase = $token->getRedirectUrlBase(); - } - - return $urlBase; - } - - /** - * Collate GET vars from all token providers that need to apply a token - * - * @return array - */ - public function getRedirectUrlParams() - { - $params = $_GET; - unset($params['url']); // CLIRequestBuilder may add this - foreach ($this->filteredTokens() as $token) { - $params = array_merge($params, $token->params()); - } - - return $params; - } - - /** - * @return string - */ - protected function redirectURL() - { - $params = http_build_query($this->getRedirectUrlParams() ?? []); - return Controller::join_links($this->getRedirectUrlBase(), '?' . $params); - } - - /** - * @return HTTPResponse - */ - public function reloadWithTokens() - { - $location = $this->redirectURL(); - $locationJS = Convert::raw2js($location); - $locationATT = Convert::raw2att($location); - $body = <<location.href='$locationJS'; - -You are being redirected. If you are not redirected soon, click here to continue -HTML; - - // Build response - $result = new HTTPResponse($body); - $result->redirect($location); - return $result; - } -} diff --git a/src/Core/Startup/ErrorControlChain.php b/src/Core/Startup/ErrorControlChain.php deleted file mode 100644 index eef68fbe1..000000000 --- a/src/Core/Startup/ErrorControlChain.php +++ /dev/null @@ -1,262 +0,0 @@ -then($callback1)->then($callback2)->thenIfErrored($callback3)->execute(); - * - * @internal This class is designed specifically for use pre-startup and may change without warning - * - * @deprecated 4.12.0 Will be removed without equivalent functionality - */ -class ErrorControlChain -{ - public static $fatal_errors = null; // Initialised after class definition - - /** - * Is there an error? - * - * @var bool - */ - protected $error = false; - - /** - * List of steps - * - * @var array - */ - protected $steps = []; - - /** - * True if errors should be hidden - * - * @var bool - */ - protected $suppression = true; - - /** We can't unregister_shutdown_function, so this acts as a flag to enable handling */ - protected $handleFatalErrors = false; - - /** We overload display_errors to hide errors during execution, so we need to remember the original to restore to */ - protected $originalDisplayErrors = null; - - /** - * Any exceptions passed through the chain - * - * @var Exception - */ - protected $lastException = null; - - /** - * Determine if an error has been found - * - * @return bool - */ - public function __construct() - { - Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality', Deprecation::SCOPE_CLASS); - } - - public function hasErrored() - { - return $this->error; - } - - public function setErrored($error) - { - $this->error = (bool)$error; - } - - /** - * Sets whether errors are suppressed or not - * Notes: - * - Errors cannot be suppressed if not handling errors. - * - Errors cannot be un-suppressed if original mode dis-allowed visible errors - * - * @param bool $suppression - */ - public function setSuppression($suppression) - { - $this->suppression = (bool)$suppression; - // If handling fatal errors, conditionally disable, or restore error display - // Note: original value of display_errors could also evaluate to "off" - if ($this->handleFatalErrors) { - if ($suppression) { - $this->setDisplayErrors(0); - } else { - $this->setDisplayErrors($this->originalDisplayErrors); - } - } - } - - /** - * Set display_errors - * - * @param mixed $errors - */ - protected function setDisplayErrors($errors) - { - ini_set('display_errors', $errors); - } - - /** - * Get value of display_errors ini value - * - * @return mixed - */ - protected function getDisplayErrors() - { - return ini_get('display_errors'); - } - - /** - * Add this callback to the chain of callbacks to call along with the state - * that $error must be in this point in the chain for the callback to be called - * - * @param $callback - The callback to call - * @param $onErrorState - false if only call if no errors yet, true if only call if already errors, null for either - * @return $this - */ - public function then($callback, $onErrorState = false) - { - $this->steps[] = [ - 'callback' => $callback, - 'onErrorState' => $onErrorState - ]; - return $this; - } - - /** - * Request that the callback is invoked if not errored - * - * @param callable $callback - * @return $this - */ - public function thenWhileGood($callback) - { - return $this->then($callback, false); - } - - /** - * Request that the callback is invoked on error - * - * @param callable $callback - * @return $this - */ - public function thenIfErrored($callback) - { - return $this->then($callback, true); - } - - /** - * Request that the callback is invoked always - * - * @param callable $callback - * @return $this - */ - public function thenAlways($callback) - { - return $this->then($callback, null); - } - - /** - * Return true if the last error was fatal - * - * @return boolean - */ - protected function lastErrorWasFatal() - { - if ($this->lastException) { - return true; - } - $error = error_get_last(); - return $error && ($error['type'] & self::$fatal_errors) != 0; - } - - protected function lastErrorWasMemoryExhaustion() - { - $error = error_get_last(); - $message = $error ? $error['message'] : ''; - return stripos($message ?? '', 'memory') !== false && stripos($message ?? '', 'exhausted') !== false; - } - - static $transtable = [ - 'k' => 1024, - 'm' => 1048576, - 'g' => 1073741824 - ]; - - protected function translateMemstring($memString) - { - $char = strtolower(substr($memString ?? '', -1)); - $fact = isset(self::$transtable[$char]) ? self::$transtable[$char] : 1; - return ((int)$memString) * $fact; - } - - public function handleFatalError() - { - if ($this->handleFatalErrors && $this->suppression) { - if ($this->lastErrorWasFatal()) { - if ($this->lastErrorWasMemoryExhaustion()) { - // Bump up memory limit by an arbitrary 10% / 10MB (whichever is bigger) since we've run out - $cur = $this->translateMemstring(ini_get('memory_limit')); - if ($cur != -1) { - ini_set('memory_limit', $cur + max(round($cur*0.1), 10000000)); - } - } - - $this->error = true; - $this->step(); - } - } - } - - public function execute() - { - register_shutdown_function([$this, 'handleFatalError']); - $this->handleFatalErrors = true; - - $this->originalDisplayErrors = $this->getDisplayErrors(); - $this->setSuppression($this->suppression); - - $this->step(); - } - - protected function step() - { - if ($this->steps) { - $step = array_shift($this->steps); - - if ($step['onErrorState'] === null || $step['onErrorState'] === $this->error) { - try { - call_user_func($step['callback'], $this); - } catch (Exception $ex) { - $this->lastException = $ex; - throw $ex; - } - } - - $this->step(); - } else { - // Now clean up - $this->handleFatalErrors = false; - $this->setDisplayErrors($this->originalDisplayErrors); - } - } -} - -ErrorControlChain::$fatal_errors = E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR; -if (defined('E_RECOVERABLE_ERROR')) { - ErrorControlChain::$fatal_errors |= E_RECOVERABLE_ERROR; -} diff --git a/src/Core/Startup/ErrorControlChainMiddleware.php b/src/Core/Startup/ErrorControlChainMiddleware.php deleted file mode 100644 index c4c2ffd89..000000000 --- a/src/Core/Startup/ErrorControlChainMiddleware.php +++ /dev/null @@ -1,163 +0,0 @@ -application = $application; - $this->legacy = $legacy; - } - - /** - * @param HTTPRequest $request - * @return ConfirmationTokenChain - */ - protected function prepareConfirmationTokenChain(HTTPRequest $request) - { - $chain = new ConfirmationTokenChain(); - $chain->pushToken(new URLConfirmationToken('dev/build', $request)); - $chain->pushToken(new ParameterConfirmationToken('flush', $request)); - - return $chain; - } - - public function process(HTTPRequest $request, callable $next) - { - if (!$this->legacy) { - return call_user_func($next, $request); - } - - $result = null; - - // Prepare tokens and execute chain - $confirmationTokenChain = $this->prepareConfirmationTokenChain($request); - $errorControlChain = new ErrorControlChain(); - $errorControlChain - ->then(function () use ($request, $errorControlChain, $confirmationTokenChain, $next, &$result) { - if ($confirmationTokenChain->suppressionRequired()) { - $confirmationTokenChain->suppressTokens(); - } else { - // If no redirection is necessary then we can disable error suppression - $errorControlChain->setSuppression(false); - } - - try { - // Check if a token is requesting a redirect - if ($confirmationTokenChain && $confirmationTokenChain->reloadRequired()) { - $result = $this->safeReloadWithTokens($request, $confirmationTokenChain); - } else { - // If no reload necessary, process application - $result = call_user_func($next, $request); - } - } catch (HTTPResponse_Exception $exception) { - $result = $exception->getResponse(); - } - }) - // Finally if a token was requested but there was an error while figuring out if it's allowed, do it anyway - ->thenIfErrored(function () use ($confirmationTokenChain) { - if ($confirmationTokenChain && $confirmationTokenChain->reloadRequiredIfError()) { - try { - // Reload requires manual boot - $this->getApplication()->getKernel()->boot(false); - } finally { - // Given we're in an error state here, try to continue even if the kernel boot fails - $result = $confirmationTokenChain->reloadWithTokens(); - $result->output(); - } - } - }) - ->execute(); - return $result; - } - - /** - * Reload application with the given token, but only if either the user is authenticated, - * or authentication is impossible. - * - * @param HTTPRequest $request - * @param ConfirmationTokenChain $confirmationTokenChain - * @return HTTPResponse - */ - protected function safeReloadWithTokens(HTTPRequest $request, ConfirmationTokenChain $confirmationTokenChain) - { - // Safe reload requires manual boot - $this->getApplication()->getKernel()->boot(false); - - // Ensure session is started - $request->getSession()->init($request); - - // Request with ErrorDirector - $result = ErrorDirector::singleton()->handleRequestWithTokenChain( - $request, - $confirmationTokenChain, - $this->getApplication()->getKernel() - ); - if ($result) { - return $result; - } - - // Fail and redirect the user to the login page - $params = array_merge($request->getVars(), $confirmationTokenChain->params(false)); - $backURL = $confirmationTokenChain->getRedirectUrlBase() . '?' . http_build_query($params ?? []); - $loginPage = Director::absoluteURL(Security::config()->get('login_url')); - $loginPage .= "?BackURL=" . urlencode($backURL ?? ''); - $result = new HTTPResponse(); - $result->redirect($loginPage); - return $result; - } - - /** - * @return Application - */ - public function getApplication() - { - return $this->application; - } - - /** - * @param Application $application - * @return $this - */ - public function setApplication(Application $application) - { - $this->application = $application; - return $this; - } -} diff --git a/src/Core/Startup/ErrorDirector.php b/src/Core/Startup/ErrorDirector.php deleted file mode 100644 index 421015a5d..000000000 --- a/src/Core/Startup/ErrorDirector.php +++ /dev/null @@ -1,58 +0,0 @@ -registerService($request, HTTPRequest::class); - - // Next, check if we're in dev mode, or the database doesn't have any security data, or we are admin - $reload = function (HTTPRequest $request) use ($confirmationTokenChain, $kernel) { - if ($kernel->getEnvironment() === Kernel::DEV || !Security::database_is_ready() || Permission::check('ADMIN')) { - return $confirmationTokenChain->reloadWithTokens(); - } - return null; - }; - - try { - return $this->callMiddleware($request, $reload); - } finally { - // Ensure registered request is un-registered - Injector::inst()->unregisterNamedObject(HTTPRequest::class); - } - } -} diff --git a/src/Core/Startup/ParameterConfirmationToken.php b/src/Core/Startup/ParameterConfirmationToken.php deleted file mode 100644 index bd738cfd0..000000000 --- a/src/Core/Startup/ParameterConfirmationToken.php +++ /dev/null @@ -1,165 +0,0 @@ -parameterName = $parameterName; - $this->request = $request; - - // Store the parameter value - $this->parameter = $request->getVar($parameterName); - $this->parameterBackURL = $this->backURLToken($request); - - // If the token provided is valid, mark it as such - $token = $request->getVar($parameterName . 'token'); - if ($this->checkToken($token)) { - $this->token = $token; - } - } - - /** - * Check if this token exists in the BackURL - * - * @param HTTPRequest $request - * @return string Value of token in backurl, or null if not in backurl - */ - protected function backURLToken(HTTPRequest $request) - { - $backURL = $request->getVar('BackURL'); - if (!strstr($backURL ?? '', '?')) { - return null; - } - - // Filter backURL if it contains the given request parameter - list(,$query) = explode('?', $backURL ?? ''); - parse_str($query ?? '', $queryArgs); - $name = $this->getName(); - if (isset($queryArgs[$name])) { - return $queryArgs[$name]; - } - return null; - } - - /** - * Get the name of this token - * - * @return string - */ - public function getName() - { - return $this->parameterName; - } - - /** - * Is the parameter requested? - * ?parameter and ?parameter=1 are both considered requested - * - * @return bool - */ - public function parameterProvided() - { - return $this->parameter !== null; - } - - /** - * Is the parameter requested in a BackURL param? - * - * @return bool - */ - public function existsInReferer() - { - return $this->parameterBackURL !== null; - } - - public function reloadRequired() - { - return $this->parameterProvided() && !$this->tokenProvided(); - } - - public function reloadRequiredIfError() - { - // Don't reload if token exists - return $this->reloadRequired() || $this->existsInReferer(); - } - - public function suppress() - { - $this->request->offsetUnset($this->parameterName); - } - - public function params($includeToken = true) - { - $params = [ - $this->parameterName => $this->parameter, - ]; - if ($includeToken) { - $params[$this->parameterName . 'token'] = $this->genToken(); - } - return $params; - } - - public function getRedirectUrlBase() - { - return ($this->existsInReferer() && !$this->parameterProvided()) ? Director::baseURL() : $this->currentURL(); - } - - public function getRedirectUrlParams() - { - return ($this->existsInReferer() && !$this->parameterProvided()) - ? $this->params() - : array_merge($this->request->getVars(), $this->params()); - } - - protected function redirectURL() - { - $query = http_build_query($this->getRedirectUrlParams() ?? []); - return Controller::join_links($this->getRedirectUrlBase(), '?' . $query); - } -} diff --git a/src/Core/Startup/URLConfirmationToken.php b/src/Core/Startup/URLConfirmationToken.php deleted file mode 100644 index bbab5c101..000000000 --- a/src/Core/Startup/URLConfirmationToken.php +++ /dev/null @@ -1,143 +0,0 @@ -urlToCheck = $urlToCheck; - $this->request = $request; - $this->currentURL = $request->getURL(false); - - $this->tokenParameterName = preg_replace('/[^a-z0-9]/i', '', $urlToCheck ?? '') . 'token'; - $this->urlExistsInBackURL = $this->getURLExistsInBackURL($request); - - // If the token provided is valid, mark it as such - $token = $request->getVar($this->tokenParameterName); - if ($this->checkToken($token)) { - $this->token = $token; - } - } - - /** - * @param HTTPRequest $request - * @return bool - */ - protected function getURLExistsInBackURL(HTTPRequest $request) - { - $backURL = ltrim($request->getVar('BackURL') ?? '', '/'); - return (strpos($backURL ?? '', $this->urlToCheck ?? '') === 0); - } - - /** - * @return bool - */ - protected function urlMatches() - { - return ($this->currentURL === $this->urlToCheck); - } - - /** - * @return string - */ - public function getURLToCheck() - { - return $this->urlToCheck; - } - - /** - * @return bool - */ - public function urlExistsInBackURL() - { - return $this->urlExistsInBackURL; - } - - public function reloadRequired() - { - return $this->urlMatches() && !$this->tokenProvided(); - } - - public function reloadRequiredIfError() - { - return $this->reloadRequired() || $this->urlExistsInBackURL(); - } - - public function suppress() - { - $_SERVER['REQUEST_URI'] = '/'; - $this->request->setURL('/'); - } - - public function params($includeToken = true) - { - $params = []; - if ($includeToken) { - $params[$this->tokenParameterName] = $this->genToken(); - } - - return $params; - } - - public function currentURL() - { - return Controller::join_links(Director::baseURL(), $this->currentURL); - } - - public function getRedirectUrlBase() - { - return ($this->urlExistsInBackURL && !$this->urlMatches()) ? Director::baseURL() : $this->currentURL(); - } - - public function getRedirectUrlParams() - { - return ($this->urlExistsInBackURL && !$this->urlMatches()) - ? $this->params() - : array_merge($this->request->getVars(), $this->params()); - } - - protected function redirectURL() - { - $query = http_build_query($this->getRedirectUrlParams() ?? []); - return Controller::join_links($this->getRedirectUrlBase(), '?' . $query); - } -} diff --git a/src/Dev/Backtrace.php b/src/Dev/Backtrace.php index cd4fa92fc..bef017108 100644 --- a/src/Dev/Backtrace.php +++ b/src/Dev/Backtrace.php @@ -52,8 +52,8 @@ class Backtrace 'Zend_Log->log', 'Zend_Log->__call', 'Zend_Log->err', - 'SilverStripe\\Dev\\DebugView->writeTrace', - 'SilverStripe\\Dev\\CliDebugView->writeTrace', + 'SilverStripe\\Dev\\DebugView->renderTrace', + 'SilverStripe\\Dev\\CliDebugView->renderTrace', 'SilverStripe\\Dev\\Debug::emailError', 'SilverStripe\\Dev\\Debug::warningHandler', 'SilverStripe\\Dev\\Debug::noticeHandler', diff --git a/src/Dev/CSVParser.php b/src/Dev/CSVParser.php deleted file mode 100644 index fda09190c..000000000 --- a/src/Dev/CSVParser.php +++ /dev/null @@ -1,341 +0,0 @@ - - * $parser = new CSVParser('myfile.csv'); - * $parser->mapColumns(array( - * 'first name' => 'FirstName', - * 'lastname' => 'Surname', - * 'last name' => 'Surname', - * )); - * foreach($parser as $row) { - * // $row is a map of column name => column value - * $obj = new MyDataObject(); - * $obj->update($row); - * $obj->write(); - * } - * - */ -class CSVParser implements Iterator -{ - use Injectable; - - /** - * @var string $filename - */ - protected $filename; - - /** - * @var resource $fileHandle - */ - protected $fileHandle; - - /** - * Map of source columns to output columns. - * - * Once they get into this variable, all of the source columns are in - * lowercase. - * - * @var array - */ - protected $columnMap = []; - - /** - * The header row used to map data in the CSV file. - * - * To begin with, this is null. Once it has been set, data will get - * returned from the CSV file. - * - * @var array - */ - protected $headerRow = null; - - /** - * A custom header row provided by the caller. - * - * @var array - */ - protected $providedHeaderRow = null; - - /** - * The data of the current row. - * - * @var array - */ - protected $currentRow = null; - - /** - * The current row number. - * - * 1 is the first data row in the CSV file; the header row, if it exists, - * is ignored. - * - * @var int - */ - protected $rowNum = 0; - - /** - * The character for separating columns. - * - * @var string - */ - protected $delimiter = ","; - - /** - * The character for quoting columns. - * - * @var string - */ - protected $enclosure = '"'; - - /** - * Open a CSV file for parsing. - * - * You can use the object returned in a foreach loop to extract the data. - * - * @param string $filename The name of the file. If relative, it will be relative to the site's base dir - * @param string $delimiter The character for separating columns - * @param string $enclosure The character for quoting or enclosing columns - */ - public function __construct($filename, $delimiter = ",", $enclosure = '"') - { - Deprecation::notice('5.0', __CLASS__ . ' is deprecated, use ' . Reader::class . ' instead'); - $filename = Director::getAbsFile($filename); - $this->filename = $filename; - $this->delimiter = $delimiter; - $this->enclosure = $enclosure; - } - - /** - * Re-map columns in the CSV file. - * - * This can be useful for identifying synonyms in the file. For example: - * - * - * $csv->mapColumns(array( - * 'firstname' => 'FirstName', - * 'last name' => 'Surname', - * )); - * - * - * @param array $columnMap - */ - public function mapColumns($columnMap) - { - if ($columnMap) { - $lowerColumnMap = []; - - foreach ($columnMap as $k => $v) { - $lowerColumnMap[strtolower($k)] = $v; - } - - $this->columnMap = array_merge($this->columnMap, $lowerColumnMap); - } - } - - /** - * If your CSV file doesn't have a header row, then you can call this - * function to provide one. - * - * If you call this function, then the first row of the CSV will be - * included in the data returned. - * - * @param array $headerRow - */ - public function provideHeaderRow($headerRow) - { - $this->providedHeaderRow = $headerRow; - } - - /** - * Open the CSV file for reading. - */ - protected function openFile() - { - $this->fileHandle = fopen($this->filename ?? '', 'r'); - - if ($this->providedHeaderRow) { - $this->headerRow = $this->remapHeader($this->providedHeaderRow); - } - } - - /** - * Close the CSV file and re-set all of the internal variables. - */ - protected function closeFile() - { - if ($this->fileHandle) { - fclose($this->fileHandle); - } - - $this->fileHandle = null; - $this->rowNum = 0; - $this->currentRow = null; - $this->headerRow = null; - } - - - /** - * Get a header row from the CSV file. - */ - protected function fetchCSVHeader() - { - $srcRow = fgetcsv( - $this->fileHandle, - 0, - $this->delimiter ?? '', - $this->enclosure ?? '' - ); - - $this->headerRow = $this->remapHeader($srcRow); - } - - /** - * Map the contents of a header array using $this->mappedColumns. - * - * @param array $header - * - * @return array - */ - protected function remapHeader($header) - { - $mappedHeader = []; - - foreach ($header as $item) { - if (isset($this->columnMap[strtolower($item)])) { - $item = $this->columnMap[strtolower($item)]; - } - - $mappedHeader[] = $item; - } - return $mappedHeader; - } - - /** - * Get a row from the CSV file and update $this->currentRow; - * - * @return array - */ - protected function fetchCSVRow() - { - if (!$this->fileHandle) { - $this->openFile(); - } - - if (!$this->headerRow) { - $this->fetchCSVHeader(); - } - - $this->rowNum++; - - $srcRow = fgetcsv( - $this->fileHandle, - 0, - $this->delimiter ?? '', - $this->enclosure ?? '' - ); - - if ($srcRow) { - $row = []; - - foreach ($srcRow as $i => $value) { - // Allow escaping of quotes and commas in the data - $value = str_replace( - ['\\' . $this->enclosure,'\\' . $this->delimiter], - [$this->enclosure, $this->delimiter], - $value ?? '' - ); - // Trim leading tab - // [SS-2017-007] Ensure all cells with leading [@=+] have a leading tab - $value = ltrim($value ?? '', "\t"); - if (array_key_exists($i, $this->headerRow ?? [])) { - if ($this->headerRow[$i]) { - $row[$this->headerRow[$i]] = $value; - } - } else { - user_error("No heading for column $i on row $this->rowNum", E_USER_WARNING); - } - } - - $this->currentRow = $row; - } else { - $this->closeFile(); - } - - return $this->currentRow; - } - - /** - * @ignore - */ - public function __destruct() - { - $this->closeFile(); - } - - //// ITERATOR FUNCTIONS - - /** - * @ignore - */ - #[\ReturnTypeWillChange] - public function rewind() - { - $this->closeFile(); - $this->fetchCSVRow(); - } - - /** - * @ignore - */ - #[\ReturnTypeWillChange] - public function current() - { - return $this->currentRow; - } - - /** - * @ignore - */ - #[\ReturnTypeWillChange] - public function key() - { - return $this->rowNum; - } - - /** - * @ignore - */ - #[\ReturnTypeWillChange] - public function next() - { - $this->fetchCSVRow(); - - return $this->currentRow; - } - - /** - * @ignore - */ - #[\ReturnTypeWillChange] - public function valid() - { - return $this->currentRow ? true : false; - } -} diff --git a/src/Dev/CsvBulkLoader.php b/src/Dev/CsvBulkLoader.php index d506f7458..ae8b7bb88 100644 --- a/src/Dev/CsvBulkLoader.php +++ b/src/Dev/CsvBulkLoader.php @@ -159,124 +159,6 @@ class CsvBulkLoader extends BulkLoader return $map; } - /** - * Splits a large file up into many smaller files. - * - * @param string $path Path to large file to split - * @param int $lines Number of lines per file - * - * @return array List of file paths - * @deprecated 4.12.0 Process files using a stream instead - */ - protected function splitFile($path, $lines = null) - { - Deprecation::notice('4.12.0', 'Process files using a stream instead'); - - if (!is_int($lines)) { - $lines = $this->config()->get("lines"); - } - - $new = $this->getNewSplitFileName(); - - $to = fopen($new ?? '', 'w+'); - $from = fopen($path ?? '', 'r'); - - $header = null; - - if ($this->hasHeaderRow) { - $header = fgets($from); - fwrite($to, $header ?? ''); - } - - $files = []; - $files[] = $new; - - $count = 0; - - while (!feof($from)) { - fwrite($to, fgets($from) ?? ''); - - $count++; - - if ($count >= $lines) { - fclose($to); - - // get a new temporary file name, to write the next lines to - $new = $this->getNewSplitFileName(); - - $to = fopen($new ?? '', 'w+'); - - if ($this->hasHeaderRow) { - // add the headers to the new file - fwrite($to, $header ?? ''); - } - - $files[] = $new; - - $count = 0; - } - } - fclose($to); - - return $files; - } - - /** - * @return string - * @deprecated 4.12.0 Name files yourself instead - */ - protected function getNewSplitFileName() - { - Deprecation::notice('4.12.0', 'Name files yourself instead'); - return TEMP_PATH . DIRECTORY_SEPARATOR . uniqid(str_replace('\\', '_', static::class) ?? '', true) . '.csv'; - } - - /** - * @param string $filepath - * @param boolean $preview - * - * @return BulkLoader_Result - * @deprecated 4.12.0 Process rows individually instead - */ - protected function processChunk($filepath, $preview = false) - { - Deprecation::notice('4.12.0', 'Process rows individually instead'); - $results = BulkLoader_Result::create(); - - $csv = new CSVParser( - $filepath, - $this->delimiter, - $this->enclosure - ); - - // ColumnMap has two uses, depending on whether hasHeaderRow is set - if ($this->columnMap) { - // if the map goes to a callback, use the same key value as the map - // value, rather than function name as multiple keys may use the - // same callback - $map = []; - foreach ($this->columnMap as $k => $v) { - if (strpos($v ?? '', "->") === 0) { - $map[$k] = $k; - } else { - $map[$k] = $v; - } - } - - if ($this->hasHeaderRow) { - $csv->mapColumns($map); - } else { - $csv->provideHeaderRow($map); - } - } - - foreach ($csv as $row) { - $this->processRecord($row, $this->columnMap, $results, $preview); - } - - return $results; - } - /** * @todo Better messages for relation checks and duplicate detection * Note that columnMap isn't used. diff --git a/src/Dev/DebugView.php b/src/Dev/DebugView.php index 4cc3298d8..b6bd389d1 100644 --- a/src/Dev/DebugView.php +++ b/src/Dev/DebugView.php @@ -142,69 +142,6 @@ class DebugView return implode(' → ', $pathLinks); } - /** - * @deprecated 4.0.1 Use renderHeader() instead - */ - public function writeHeader() - { - Deprecation::notice('4.0.1', 'Use renderHeader() instead'); - echo $this->renderHeader(); - } - - /** - * @deprecated 4.0.1 Use renderInfo() instead - */ - public function writeInfo($title, $subtitle, $description = false) - { - Deprecation::notice('4.0.1', 'Use renderInfo() instead'); - echo $this->renderInfo($title, $subtitle, $description); - } - - /** - * @deprecated 4.0.1 Use renderFooter() instead - */ - public function writeFooter() - { - Deprecation::notice('4.0.1', 'Use renderFooter() instead'); - echo $this->renderFooter(); - } - - /** - * @deprecated 4.0.1 Use renderError() instead - */ - public function writeError($httpRequest, $errno, $errstr, $errfile, $errline) - { - Deprecation::notice('4.0.1', 'Use renderError() instead'); - echo $this->renderError($httpRequest, $errno, $errstr, $errfile, $errline); - } - - /** - * @deprecated 4.0.1 Use renderSourceFragment() instead - */ - public function writeSourceFragment($lines, $errline) - { - Deprecation::notice('4.0.1', 'Use renderSourceFragment() instead'); - echo $this->renderSourceFragment($lines, $errline); - } - - /** - * @deprecated 4.0.1 Use renderTrace() instead - */ - public function writeTrace($trace) - { - Deprecation::notice('4.0.1', 'Use renderTrace() instead'); - echo $this->renderTrace($trace); - } - - /** - * @deprecated 4.0.1 Use renderVariable() instead - */ - public function writeVariable($val, $caller) - { - Deprecation::notice('4.0.1', 'Use renderVariable() instead'); - echo $this->renderVariable($val, $caller); - } - /** * Render HTML header for development views * diff --git a/src/Dev/Deprecation.php b/src/Dev/Deprecation.php index 3ca6a0d3b..a0015d191 100644 --- a/src/Dev/Deprecation.php +++ b/src/Dev/Deprecation.php @@ -31,38 +31,6 @@ class Deprecation const SCOPE_GLOBAL = 4; const SCOPE_CONFIG = 8; - /** - * @var string - * @deprecated 4.12.0 Will be removed without equivalent functionality to replace it - */ - protected static $version; - - /** - * Override whether deprecation is enabled. If null, then fallback to - * SS_DEPRECATION_ENABLED, and then true if not defined. - * - * Deprecation is only available on dev. - * - * Must be configured outside of the config API, as deprecation API - * must be available before this to avoid infinite loops. - * - * @var boolean|null - * @deprecated 4.12.0 Use $currentlyEnabled instead - */ - protected static $enabled = null; - - /** - * @var array - * @deprecated 4.12.0 Will be removed without equivalent functionality to replace it - */ - protected static $module_version_overrides = []; - - /** - * @var array - * @deprecated 4.12.0 Will be removed without equivalent functionality to replace it - */ - public static $notice_level = E_USER_DEPRECATED; - /** * Must be configured outside of the config API, as deprecation API * must be available before this to avoid infinite loops. @@ -131,37 +99,6 @@ class Deprecation } } - /** - * This method is no longer used - * - * @static - * @param $ver string - - * A php standard version string, see http://php.net/manual/en/function.version-compare.php for details. - * @param null $forModule string - - * The name of a module. The passed version will be used as the check value for - * calls directly from this module rather than the global value - * @return void - * @deprecated 4.12.0 Use enable() instead - */ - public static function notification_version($ver, $forModule = null) - { - static::notice('4.12.0', 'Use enable() instead'); - // noop - } - - /** - * This method is no longer used - * - * @param array $backtrace A backtrace as returned from debug_backtrace - * @return Module The module being called - * @deprecated 4.12.0 Will be removed without equivalent functionality to replace it - */ - protected static function get_calling_module_from_trace($backtrace) - { - static::notice('4.12.0', 'Will be removed without equivalent functionality to replace it'); - // noop - } - /** * Given a backtrace, get the method name from the immediate parent caller (the caller of #notice) * @@ -191,18 +128,6 @@ class Deprecation return ($called['class'] ?? '') . ($called['type'] ?? '') . ($called['function'] ?? ''); } - /** - * This method is no longer used - * - * @return bool - * @deprecated 4.12.0 Will be removed without equivalent functionality to replace it - */ - public static function get_enabled() - { - static::notice('4.12.0', 'Will be removed without equivalent functionality to replace it'); - // noop - } - public static function isEnabled(): bool { if (!Director::isDev()) { @@ -211,18 +136,6 @@ class Deprecation return static::$currentlyEnabled || Environment::getEnv('SS_DEPRECATION_ENABLED'); } - /** - * This method is no longer used - * - * @param bool $enabled - * @deprecated 4.12.0 Use enable() instead - */ - public static function set_enabled($enabled) - { - static::notice('4.12.0', 'Use enable() instead'); - // noop - } - public static function outputNotices(): void { if (!self::isEnabled()) { @@ -322,28 +235,4 @@ class Deprecation static::$insideNotice = false; } } - - /** - * This method is no longer used - * - * @return array Opaque array that should only be used to pass to {@see Deprecation::restore_settings()} - * @deprecated 4.12.0 Will be removed without equivalent functionality to replace it - */ - public static function dump_settings() - { - static::notice('4.12.0', 'Will be removed without equivalent functionality to replace it'); - // noop - } - - /** - * This method is no longer used - * - * @param $settings array An array as returned by {@see Deprecation::dump_settings()} - * @deprecated 4.12.0 Will be removed without equivalent functionality to replace it - */ - public static function restore_settings($settings) - { - static::notice('4.12.0', 'Will be removed without equivalent functionality to replace it'); - // noop - } } diff --git a/src/Dev/FunctionalTest.php b/src/Dev/FunctionalTest.php index 804775192..b6926dad3 100644 --- a/src/Dev/FunctionalTest.php +++ b/src/Dev/FunctionalTest.php @@ -11,7 +11,6 @@ use SilverStripe\Security\BasicAuth; use SilverStripe\Security\SecurityToken; use SilverStripe\View\SSViewer; use SimpleXMLElement; -use SilverStripe\Dev\Deprecation; /** * SilverStripe-specific testing object designed to support functional testing of your web app. It simulates get/post @@ -43,14 +42,6 @@ abstract class FunctionalTest extends SapphireTest implements TestOnly */ protected static $disable_themes = false; - /** - * Set this to true on your sub-class to use the draft site by default for every test in this class. - * - * @deprecated 4.2.0 Use ?stage=Stage in your request's querystring instead - * @var bool - */ - protected static $use_draft_site = false; - /** * @var TestSession */ @@ -101,14 +92,6 @@ abstract class FunctionalTest extends SapphireTest implements TestOnly // Flush user $this->logOut(); - // Switch to draft site, if necessary - // If you rely on this you should be crafting stage-specific urls instead though. - Deprecation::withNoReplacement(function () { - if (static::get_use_draft_site()) { - $this->useDraftSite(); - } - }); - // Unprotect the site, tests are running with the assumption it's off. They will enable it on a case-by-case // basis. BasicAuth::protect_entire_site(false); @@ -402,26 +385,6 @@ abstract class FunctionalTest extends SapphireTest implements TestOnly $this->assertTrue($expectedMatches == $actuals, $message); } - /** - * Use the draft (stage) site for testing. - * This is helpful if you're not testing publication functionality and don't want "stage management" cluttering - * your test. - * - * @deprecated 4.2.0 Use ?stage=Stage in your request's querystring instead - * @param bool $enabled toggle the use of the draft site - */ - public function useDraftSite($enabled = true) - { - Deprecation::notice('4.2.0', 'Use ?stage=Stage in your request\'s querystring instead'); - if ($enabled) { - $this->session()->set('readingMode', 'Stage.Stage'); - $this->session()->set('unsecuredDraftSite', true); - } else { - $this->session()->clear('readingMode'); - $this->session()->clear('unsecuredDraftSite'); - } - } - /** * @return bool */ @@ -429,14 +392,4 @@ abstract class FunctionalTest extends SapphireTest implements TestOnly { return static::$disable_themes; } - - /** - * @deprecated 4.2.0 Use ?stage=Stage in your request's querystring instead - * @return bool - */ - public static function get_use_draft_site() - { - Deprecation::notice('4.2.0', 'Use ?stage=Stage in your request\'s querystring instead'); - return static::$use_draft_site; - } } diff --git a/src/Dev/Install/DatabaseAdapterRegistry.php b/src/Dev/Install/DatabaseAdapterRegistry.php index a0d79bc5a..0a77da807 100644 --- a/src/Dev/Install/DatabaseAdapterRegistry.php +++ b/src/Dev/Install/DatabaseAdapterRegistry.php @@ -5,7 +5,6 @@ namespace SilverStripe\Dev\Install; use InvalidArgumentException; use Psr\SimpleCache\CacheInterface; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; use SilverStripe\Core\Flushable; /** @@ -141,12 +140,8 @@ class DatabaseAdapterRegistry implements Flushable */ public static function autoconfigure(&$config = null) { - if (!isset($config)) { - Deprecation::notice('5.0', 'Configuration via global is deprecated'); - global $databaseConfig; - } else { - $databaseConfig = $config; - } + $databaseConfig = $config; + foreach (static::getConfigureDatabasePaths() as $configureDatabasePath) { include_once $configureDatabasePath; } diff --git a/src/Dev/InstallerTest.php b/src/Dev/InstallerTest.php deleted file mode 100644 index d9e89faba..000000000 --- a/src/Dev/InstallerTest.php +++ /dev/null @@ -1,28 +0,0 @@ -getStateByName('fixtures'); - return $state->getFixtureFactory(static::class); - } - - /** - * Sets a new fixture factory - * @param FixtureFactory $factory - * @return $this - * @deprecated 4.0.1 Use FixtureTestState instead - */ - public function setFixtureFactory(FixtureFactory $factory) - { - Deprecation::notice('4.0.1', 'Use FixtureTestState instead'); - /** @var FixtureTestState $state */ - $state = static::$state->getStateByName('fixtures'); - $state->setFixtureFactory($factory, static::class); - $this->fixtureFactory = $factory; - return $this; - } - /** * Get the ID of an object from the fixture. * @@ -518,21 +484,6 @@ abstract class SapphireTest extends TestCase implements TestOnly return $obj; } - /** - * Load a YAML fixture file into the database. - * Once loaded, you can use idFromFixture() and objFromFixture() to get items from the fixture. - * Doesn't clear existing fixtures. - * @param string $fixtureFile The location of the .yml fixture file, relative to the site base dir - * @deprecated 4.0.1 Use FixtureTestState instead - * - */ - public function loadFixture($fixtureFile) - { - Deprecation::notice('4.0.1', 'Use FixtureTestState instead'); - $fixture = Injector::inst()->create(YamlFixture::class, $fixtureFile); - $fixture->writeInto($this->getFixtureFactory()); - } - /** * Clear all fixtures which were previously loaded through * {@link loadFixture()} @@ -716,18 +667,6 @@ abstract class SapphireTest extends TestCase implements TestOnly ); } - /** - * @param $matches - * @param $dataObjectSet - * @deprecated 4.0.1 Use assertListContains() instead - * - */ - public function assertDOSContains($matches, $dataObjectSet) - { - Deprecation::notice('4.0.1', 'Use assertListContains() instead'); - static::assertListContains($matches, $dataObjectSet); - } - /** * Asserts that no items in a given list appear in the given dataobject list * @@ -770,18 +709,6 @@ abstract class SapphireTest extends TestCase implements TestOnly ); } - /** - * @param $matches - * @param $dataObjectSet - * @deprecated 4.0.1 Use assertListNotContains() instead - * - */ - public static function assertNotDOSContains($matches, $dataObjectSet) - { - Deprecation::notice('4.0.1', 'Use assertListNotContains() instead'); - static::assertListNotContains($matches, $dataObjectSet); - } - /** * Assert that the given {@link SS_List} includes only DataObjects matching the given * key-value pairs. Each match must correspond to 1 distinct record. @@ -818,19 +745,6 @@ abstract class SapphireTest extends TestCase implements TestOnly ); } - /** - * @param $matches - * @param SS_List $dataObjectSet - * @deprecated 4.0.1 Use assertListEquals() instead - * - */ - public function assertDOSEquals($matches, $dataObjectSet) - { - Deprecation::notice('4.0.1', 'Use assertListEquals() instead'); - static::assertListEquals($matches, $dataObjectSet); - } - - /** * Assert that the every record in the given {@link SS_List} matches the given key-value * pairs. @@ -862,18 +776,6 @@ abstract class SapphireTest extends TestCase implements TestOnly ); } - /** - * @param $match - * @param SS_List $dataObjectSet - * @deprecated 4.0.1 Use assertListAllMatch() instead - * - */ - public function assertDOSAllMatch($match, SS_List $dataObjectSet) - { - Deprecation::notice('4.0.1', 'Use assertListAllMatch() instead'); - static::assertListAllMatch($match, $dataObjectSet); - } - /** * Removes sequences of repeated whitespace characters from SQL queries * making them suitable for string comparison diff --git a/src/Dev/Tasks/MigrateFileTask.php b/src/Dev/Tasks/MigrateFileTask.php deleted file mode 100644 index 797e58ec3..000000000 --- a/src/Dev/Tasks/MigrateFileTask.php +++ /dev/null @@ -1,350 +0,0 @@ - '%$' . LoggerInterface::class, - ]; - - /** @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(); - - $args = $request->getVars(); - $this->validateArgs($args); - - Injector::inst()->get(FileHashingService::class)->enableCache(); - - // Set max time and memory limit - Environment::increaseTimeLimitTo(); - Environment::setMemoryLimitMax(-1); - Environment::increaseMemoryLimitTo(-1); - - $this->extend('preFileMigration'); - - $this->logger->warn( - 'Please read https://docs.silverstripe.org/en/4/developer_guides/files/file_migration/ ' . - 'before running this task.' - ); - - $subtasks = !empty($args['only']) ? explode(',', $args['only']) : $this->defaultSubtasks; - - $subtask = 'move-files'; - if (in_array($subtask, $subtasks ?? [])) { - if (!class_exists(FileMigrationHelper::class)) { - $this->logger->error("No file migration helper detected"); - } else { - $this->extend('preFileMigrationSubtask', $subtask); - - $this->logger->notice("######################################################"); - $this->logger->notice("Migrating filesystem and database records ({$subtask})"); - $this->logger->notice("######################################################"); - - FileMigrationHelper::singleton() - ->setLogger($this->logger) - ->run(); - - $this->extend('postFileMigrationSubtask', $subtask); - } - } - - $subtask = 'migrate-folders'; - if (in_array($subtask, $subtasks ?? [])) { - if (!class_exists(FolderMigrationHelper::class)) { - $this->logger->error("No folder migration helper detected"); - } else { - $this->extend('preFileMigrationSubtask', $subtask); - - $this->logger->notice("######################################################"); - $this->logger->notice("Migrating folder database records ({$subtask})"); - $this->logger->notice("######################################################"); - - FolderMigrationHelper::singleton() - ->setLogger($this->logger) - ->run(); - - $this->extend('postFileMigrationSubtask', $subtask); - } - } - - $subtask = 'move-thumbnails'; - if (in_array($subtask, $subtasks ?? [])) { - if (!class_exists(LegacyThumbnailMigrationHelper::class)) { - $this->logger->error("LegacyThumbnailMigrationHelper not found"); - } else { - $this->extend('preFileMigrationSubtask', $subtask); - - $this->logger->notice("#############################################################"); - $this->logger->notice("Migrating existing thumbnails to new file format ({$subtask})"); - $this->logger->notice("#############################################################"); - - $paths = LegacyThumbnailMigrationHelper::singleton() - ->setLogger($this->logger) - ->run($this->getStore()); - - if ($paths) { - $this->logger->info(sprintf("%d thumbnails moved", count($paths ?? []))); - } else { - $this->logger->info("No thumbnails needed to be moved"); - } - - $this->extend('postFileMigrationSubtask', $subtask); - } - } - - $subtask = 'generate-cms-thumbnails'; - if (in_array($subtask, $subtasks ?? [])) { - if (!class_exists(ImageThumbnailHelper::class)) { - $this->logger->error("ImageThumbnailHelper not found"); - } else { - $this->extend('preFileMigrationSubtask', $subtask); - - $this->logger->notice("#############################################"); - $this->logger->notice("Generating new CMS UI thumbnails ({$subtask})"); - $this->logger->notice("#############################################"); - - $count = ImageThumbnailHelper::singleton() - ->setLogger($this->logger) - ->run(); - - if ($count > 0) { - $this->logger->info("Created {$count} CMS UI thumbnails"); - } else { - $this->logger->info("No CMS UI thumbnails needed to be created"); - } - - $this->extend('postFileMigrationSubtask', $subtask); - } - } - - $subtask = 'fix-folder-permissions'; - if (in_array($subtask, $subtasks ?? [])) { - if (!class_exists(FixFolderPermissionsHelper::class)) { - $this->logger->error("FixFolderPermissionsHelper not found"); - } else { - $this->extend('preFileMigrationSubtask', $subtask); - - $this->logger->notice("####################################################"); - $this->logger->notice("Fixing secure-assets folder permissions ({$subtask})"); - $this->logger->notice("####################################################"); - $this->logger->debug('Only required if the 3.x project included silverstripe/secure-assets'); - - $count = FixFolderPermissionsHelper::singleton() - ->setLogger($this->logger) - ->run(); - - if ($count > 0) { - $this->logger->info("Repaired {$count} folders with broken CanViewType settings"); - } else { - $this->logger->info("No folders required fixes"); - } - - $this->extend('postFileMigrationSubtask', $subtask); - } - } - - $subtask = 'fix-secureassets'; - if (in_array($subtask, $subtasks ?? [])) { - if (!class_exists(SecureAssetsMigrationHelper::class)) { - $this->logger->error("SecureAssetsMigrationHelper not found"); - } else { - $this->extend('preFileMigrationSubtask', $subtask); - - $this->logger->notice("#####################################################"); - $this->logger->notice("Fixing secure-assets folder restrictions ({$subtask})"); - $this->logger->notice("#####################################################"); - $this->logger->debug('Only required if the 3.x project included silverstripe/secure-assets'); - - $paths = SecureAssetsMigrationHelper::singleton() - ->setLogger($this->logger) - ->run($this->getStore()); - - if (count($paths ?? []) > 0) { - $this->logger->info(sprintf("Repaired %d folders broken folder restrictions", count($paths ?? []))); - } else { - $this->logger->info("No folders required fixes"); - } - - $this->extend('postFileMigrationSubtask', $subtask); - } - } - - $subtask = 'normalise-access'; - if (in_array($subtask, $subtasks ?? [])) { - if (!class_exists(NormaliseAccessMigrationHelper::class)) { - $this->logger->error("No normalise access migration helper detected"); - } else { - $this->extend('preFileMigrationSubtask', $subtask); - - $this->logger->notice("######################################################"); - $this->logger->notice("Migrating filesystem and database records ({$subtask})"); - $this->logger->notice("######################################################"); - - NormaliseAccessMigrationHelper::singleton() - ->setLogger($this->logger) - ->run(); - - $this->extend('postFileMigrationSubtask', $subtask); - } - } - - $subtask = 'relocate-userform-uploads-2020-9280'; - if (in_array($subtask, $subtasks ?? [])) { - if (!class_exists(RecoverUploadLocationsHelper::class)) { - $this->logger->error("No UserForms helper detected"); - } else { - $this->extend('preFileMigrationSubtask', $subtask); - - $this->logger->notice("######################################################"); - $this->logger->notice("Recovering UserForm uploaded file locations ({$subtask})"); - $this->logger->notice("######################################################"); - - RecoverUploadLocationsHelper::singleton() - ->setLogger($this->logger) - ->run(); - - $this->extend('postFileMigrationSubtask', $subtask); - } - } - - $this->extend('postFileMigration'); - - $this->logger->info("Done!"); - } - - public function getDescription() - { - return <<logger = $logger; - - return $this; - } - - /** - * @return AssetStore - */ - protected function getStore() - { - return singleton(AssetStore::class); - } - - /** - * @param array $args - * @throws \InvalidArgumentException - */ - protected function validateArgs($args) - { - if (!empty($args['only'])) { - $only = explode(',', $args['only'] ?? ''); - - $diff = array_diff($only ?? [], $this->defaultSubtasks); - $diff = array_diff($diff ?? [], $this->optInSubtasks); - - if ($diff) { - throw new \InvalidArgumentException('Invalid subtasks detected: ' . implode(', ', $diff)); - } - } - } - - /** - * TODO Refactor this whole mess into Symfony Console on a TaskRunner level, - * with a thin wrapper to show coloured console output via a browser: - * https://github.com/silverstripe/silverstripe-framework/issues/5542 - * @throws \Exception - */ - protected function addLogHandlers() - { - // Using a global service here so other systems can control and redirect log output, - // for example when this task is run as part of a queuedjob - $logger = Injector::inst()->get(LoggerInterface::class)->withName('log'); - - $formatter = new ColoredLineFormatter(); - $formatter->ignoreEmptyContextAndExtra(); - - $errorHandler = new StreamHandler('php://stderr', Logger::ERROR); - $errorHandler->setFormatter($formatter); - - $standardHandler = new StreamHandler('php://stdout'); - $standardHandler->setFormatter($formatter); - - // Avoid double logging of errors - $standardFilterHandler = new FilterHandler( - $standardHandler, - Logger::DEBUG, - Logger::WARNING - ); - - $logger->pushHandler($standardFilterHandler); - $logger->pushHandler($errorHandler); - - $this->logger = $logger; - } -} diff --git a/src/Forms/FieldList.php b/src/Forms/FieldList.php index c27471bc6..62156bc36 100644 --- a/src/Forms/FieldList.php +++ b/src/Forms/FieldList.php @@ -2,7 +2,6 @@ namespace SilverStripe\Forms; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\ArrayList; /** @@ -17,7 +16,6 @@ class FieldList extends ArrayList * Cached flat representation of all fields in this set, * including fields nested in {@link CompositeFields}. * - * @uses self::collateDataFields() * @var FormField[] */ protected $sequentialSet; @@ -179,46 +177,6 @@ class FieldList extends ArrayList $this->sequentialSaveableSet = null; } - /** - * @deprecated 4.1.0 Please use dataFields or saveableFields instead - * @param $list - * @param bool $saveableOnly - */ - protected function collateDataFields(&$list, $saveableOnly = false) - { - Deprecation::notice('4.1.0', 'Please use dataFields or saveableFields instead'); - if (!isset($list)) { - $list = []; - } - /** @var FormField $field */ - foreach ($this as $field) { - if ($field instanceof CompositeField) { - $field->collateDataFields($list, $saveableOnly); - } - - if ($saveableOnly) { - $isIncluded = $field->canSubmitValue(); - } else { - $isIncluded = $field->hasData(); - } - if ($isIncluded) { - $name = $field->getName(); - if (isset($list[$name])) { - if ($this->form) { - $formClass = get_class($this->form); - $errSuffix = " in your '{$formClass}' form called '" . $this->form->Name() . "'"; - } else { - $errSuffix = ''; - } - throw new \RuntimeException( - "collateDataFields() I noticed that a field called '$name' appears twice$errSuffix." - ); - } - $list[$name] = $field; - } - } - } - /** * Add an extra field to a tab within this FieldList. * This is most commonly used when overloading getCMSFields() @@ -563,19 +521,9 @@ class FieldList extends ArrayList /** * Inserts a field before a particular field in a FieldList. * Will traverse CompositeFields depth-first to find the matching $name, and insert before the first match - * - * @param string $name Name of the field to insert before - * @param FormField $item The form field to insert - * @param bool $appendIfMissing Append to the end of the list if $name isn't found - * @return FormField|false Field if it was successfully inserted, false if not inserted */ - public function insertBefore($name, $item, $appendIfMissing = true) + public function insertBefore(string $name, FormField $item, bool $appendIfMissing = true): FormField|bool { - // Backwards compatibility for order of arguments - if ($name instanceof FormField) { - Deprecation::notice('5.0', 'Incorrect order of arguments for insertBefore'); - list($item, $name) = [$name, $item]; - } $this->onBeforeInsert($item); $item->setContainerFieldList($this); @@ -605,19 +553,9 @@ class FieldList extends ArrayList /** * Inserts a field after a particular field in a FieldList. * Will traverse CompositeFields depth-first to find the matching $name, and insert after the first match - * - * @param string $name Name of the field to insert after - * @param FormField $item The form field to insert - * @param bool $appendIfMissing Append to the end of the list if $name isn't found - * @return FormField|false Field if it was successfully inserted, false if not inserted */ - public function insertAfter($name, $item, $appendIfMissing = true) + public function insertAfter(string $name, FormField $item, bool $appendIfMissing = true): FormField|bool { - // Backwards compatibility for order of arguments - if ($name instanceof FormField) { - Deprecation::notice('5.0', 'Incorrect order of arguments for insertAfter'); - list($item, $name) = [$name, $item]; - } $this->onBeforeInsert($item); $item->setContainerFieldList($this); diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 9e0f852db..9325d2e89 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -11,9 +11,7 @@ use SilverStripe\Control\NullHTTPRequest; use SilverStripe\Control\RequestHandler; use SilverStripe\Control\Session; use SilverStripe\Core\ClassInfo; -use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObjectInterface; use SilverStripe\ORM\FieldType\DBHTMLText; @@ -85,7 +83,7 @@ class Form extends ViewableData implements HasRequestHandler const ENC_TYPE_MULTIPART = 'multipart/form-data'; /** - * Accessed by Form.ss; modified by {@link formHtmlContent()}. + * Accessed by Form.ss. * A performance enhancement over the generate-the-form-tag-and-then-remove-it code that was there previously * * @var bool @@ -1583,32 +1581,6 @@ class Form extends ViewableData implements HasRequestHandler return $return; } - /** - * Returns an HTML rendition of this form, without the
tag itself. - * - * Attaches 3 extra hidden files, _form_action, _form_name, _form_method, - * and _form_enctype. These are the attributes of the form. These fields - * can be used to send the form to Ajax. - * - * @deprecated 4.12.0 Will be removed without equivalent functionality - * @return string - */ - public function formHtmlContent() - { - Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality'); - $this->IncludeFormTag = false; - $content = $this->forTemplate(); - $this->IncludeFormTag = true; - - $content .= "FormName() . "_form_action\"" - . " value=\"" . $this->FormAction() . "\" />\n"; - $content .= "FormName() . "\" />\n"; - $content .= "FormMethod() . "\" />\n"; - $content .= "getEncType() . "\" />\n"; - - return $content; - } - /** * Render this form using the given template, and return the result as a string * You can pass either an SSViewer or a template name diff --git a/src/Forms/FormField.php b/src/Forms/FormField.php index bd24b8392..d0983303f 100644 --- a/src/Forms/FormField.php +++ b/src/Forms/FormField.php @@ -1058,7 +1058,6 @@ class FormField extends RequestHandler * make sense for data-focused methods to look at them. By overloading hasData() to return * false, you can prevent any data-focused methods from looking at it. * - * @see FieldList::collateDataFields() * * @return bool */ diff --git a/src/Forms/GridField/GridFieldFilterHeader.php b/src/Forms/GridField/GridFieldFilterHeader.php index 58599b2fe..2fbd1198c 100755 --- a/src/Forms/GridField/GridFieldFilterHeader.php +++ b/src/Forms/GridField/GridFieldFilterHeader.php @@ -6,15 +6,9 @@ use LogicException; use SilverStripe\Admin\LeftAndMain; use SilverStripe\Control\Controller; use SilverStripe\Control\HTTPResponse; -use SilverStripe\Core\Config\Config; -use SilverStripe\Core\Convert; -use SilverStripe\Dev\Deprecation; -use SilverStripe\Forms\FieldGroup; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\Form; use SilverStripe\Forms\Schema\FormSchema; -use SilverStripe\Forms\TextField; -use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\Filterable; use SilverStripe\ORM\SS_List; use SilverStripe\View\ArrayData; @@ -35,25 +29,6 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi */ protected $throwExceptionOnBadDataType = true; - /** - * Indicates that this component should revert to displaying it's legacy - * table header style rather than the react driven search box - * - * @deprecated 4.3.0:5.0.0 Will be removed in 5.0 - * @var bool - */ - public $useLegacyFilterHeader = false; - - /** - * Forces all filter components to revert to displaying the legacy - * table header style rather than the react driven search box - * - * @deprecated 4.3.0:5.0.0 Will be removed in 5.0 - * @config - * @var bool - */ - private static $force_legacy = false; - /** * @var \SilverStripe\ORM\Search\SearchContext */ @@ -64,18 +39,6 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi */ protected $searchForm = null; - /** - * @var callable - * @deprecated 4.3.0:5.0.0 Will be removed in 5.0 - */ - protected $updateSearchContextCallback = null; - - /** - * @var callable - * @deprecated 4.3.0:5.0.0 Will be removed in 5.0 - */ - protected $updateSearchFormCallback = null; - /** * The name of the default search field * @var string|null @@ -92,24 +55,6 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi ]; } - /** - * @param bool $useLegacy This will be removed in 5.0 - * @param callable|null $updateSearchContext This will be removed in 5.0 - * @param callable|null $updateSearchForm This will be removed in 5.0 - */ - public function __construct( - $useLegacy = false, - callable $updateSearchContext = null, - callable $updateSearchForm = null - ) { - $forceLegacy = Deprecation::withNoReplacement(function () { - return Config::inst()->get(self::class, 'force_legacy'); - }); - $this->useLegacyFilterHeader = $forceLegacy || $useLegacy; - $this->updateSearchContextCallback = $updateSearchContext; - $this->updateSearchFormCallback = $updateSearchForm; - } - /** * Determine what happens when this component is used with a list that isn't {@link SS_Filterable}. * @@ -283,10 +228,6 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi { if (!$this->searchContext) { $this->searchContext = singleton($gridField->getModelClass())->getDefaultSearchContext(); - - if ($this->updateSearchContextCallback) { - call_user_func($this->updateSearchContextCallback, $this->searchContext); - } } return $this->searchContext; @@ -322,7 +263,7 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi // Prefix "Search__" onto the filters for the React component $filters = $context->getSearchParams(); - if (!$this->useLegacyFilterHeader && !empty($filters)) { + if (!empty($filters)) { $filters = array_combine(array_map(function ($key) { return 'Search__' . $key; }, array_keys($filters ?? [])), $filters ?? []); @@ -403,10 +344,6 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi $form->disableSecurityToken(); // This form is not tied to session so we disable this $form->loadDataFrom($searchContext->getSearchParams()); - if ($this->updateSearchFormCallback) { - call_user_func($this->updateSearchFormCallback, $form); - } - return $this->searchForm; } @@ -435,82 +372,6 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi return $response; } - /** - * Generate fields for the legacy filter header row - * - * @deprecated 4.12.0 Use search field instead - * @param GridField $gridfield - * @return ArrayList|null - */ - public function getLegacyFilterHeader(GridField $gridField) - { - Deprecation::notice('4.12.0', 'Use search field instead'); - - $list = $gridField->getList(); - if (!$this->checkDataType($list)) { - return null; - } - - $columns = $gridField->getColumns(); - $filterArguments = $this->getState($gridField)->Columns->toArray(); - $currentColumn = 0; - $canFilter = false; - $fieldsList = new ArrayList(); - - foreach ($columns as $columnField) { - $currentColumn++; - $metadata = $gridField->getColumnMetadata($columnField); - $title = $metadata['title']; - $fields = new FieldGroup(); - - if ($title && $list->canFilterBy($columnField)) { - $canFilter = true; - - $value = ''; - if (isset($filterArguments[$columnField])) { - $value = $filterArguments[$columnField]; - } - $field = new TextField('filter[' . $gridField->getName() . '][' . $columnField . ']', '', $value); - $field->addExtraClass('grid-field__sort-field'); - $field->addExtraClass('no-change-track'); - - $field->setAttribute( - 'placeholder', - _t('SilverStripe\\Forms\\GridField\\GridField.FilterBy', "Filter by ") . _t('SilverStripe\\Forms\\GridField\\GridField.' . $metadata['title'], $metadata['title']) - ); - - $fields->push($field); - $fields->push( - GridField_FormAction::create($gridField, 'reset', false, 'reset', null) - ->addExtraClass('btn font-icon-cancel btn-secondary btn--no-text ss-gridfield-button-reset') - ->setAttribute('title', _t('SilverStripe\\Forms\\GridField\\GridField.ResetFilter', "Reset")) - ->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField) - ); - } - - if ($currentColumn == count($columns ?? [])) { - $fields->push( - GridField_FormAction::create($gridField, 'filter', false, 'filter', null) - ->addExtraClass('btn font-icon-search btn--no-text btn--icon-large grid-field__filter-submit ss-gridfield-button-filter') - ->setAttribute('title', _t('SilverStripe\\Forms\\GridField\\GridField.Filter', 'Filter')) - ->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField) - ); - $fields->push( - GridField_FormAction::create($gridField, 'reset', false, 'reset', null) - ->addExtraClass('btn font-icon-cancel btn--no-text grid-field__filter-clear btn--icon-md ss-gridfield-button-close') - ->setAttribute('title', _t('SilverStripe\\Forms\\GridField\\GridField.ResetFilter', "Reset")) - ->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField) - ); - $fields->addExtraClass('grid-field__filter-buttons'); - $fields->addExtraClass('no-change-track'); - } - - $fieldsList->push($fields); - } - - return $canFilter ? $fieldsList : null; - } - /** * Either returns the legacy filter header or the search button and field * @@ -525,26 +386,17 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi return null; } - if ($this->useLegacyFilterHeader) { - $fieldsList = Deprecation::withNoReplacement(function () use ($gridField) { - return $this->getLegacyFilterHeader($gridField); - }); - $forTemplate->Fields = $fieldsList; - $filterTemplates = SSViewer::get_templates_by_class($this, '_Row', __CLASS__); - return ['header' => $forTemplate->renderWith($filterTemplates)]; - } else { - $fieldSchema = $this->getSearchFieldSchema($gridField); - $forTemplate->SearchFieldSchema = $fieldSchema; - $searchTemplates = SSViewer::get_templates_by_class($this, '_Search', __CLASS__); - return [ - 'before' => $forTemplate->renderWith($searchTemplates), - 'buttons-before-right' => sprintf( - '', - _t('SilverStripe\\Forms\\GridField\\GridField.OpenFilter', "Open search and filter"), - _t('SilverStripe\\Forms\\GridField\\GridField.OpenFilter', "Open search and filter") - ) - ]; - } + $fieldSchema = $this->getSearchFieldSchema($gridField); + $forTemplate->SearchFieldSchema = $fieldSchema; + $searchTemplates = SSViewer::get_templates_by_class($this, '_Search', __CLASS__); + return [ + 'before' => $forTemplate->renderWith($searchTemplates), + 'buttons-before-right' => sprintf( + '', + _t('SilverStripe\\Forms\\GridField\\GridField.OpenFilter', "Open search and filter"), + _t('SilverStripe\\Forms\\GridField\\GridField.OpenFilter', "Open search and filter") + ) + ]; } } diff --git a/src/Forms/GridField/GridFieldSortableHeader.php b/src/Forms/GridField/GridFieldSortableHeader.php index e6943f348..d12dc0383 100644 --- a/src/Forms/GridField/GridFieldSortableHeader.php +++ b/src/Forms/GridField/GridFieldSortableHeader.php @@ -190,7 +190,7 @@ class GridFieldSortableHeader extends AbstractGridFieldComponent implements Grid if ($currentColumn == count($columns ?? [])) { $filter = $gridField->getConfig()->getComponentByType(GridFieldFilterHeader::class); - if ($filter && $filter->useLegacyFilterHeader && $filter->canFilterAnyColumns($gridField)) { + if ($filter && $filter->canFilterAnyColumns($gridField)) { $field = new LiteralField( $fieldName, sprintf( diff --git a/src/Forms/GridField/GridFieldVersionedState.php b/src/Forms/GridField/GridFieldVersionedState.php deleted file mode 100644 index 643adb14a..000000000 --- a/src/Forms/GridField/GridFieldVersionedState.php +++ /dev/null @@ -1,23 +0,0 @@ -getTinyMCEResourcePath(); - } - - /** - * @return Module - * @deprecated 4.0.1 Set base_dir or editor_css config instead - */ - protected function getAdminModule() - { - Deprecation::notice('4.0.1', 'Set base_dir or editor_css config instead'); - return ModuleLoader::getModule('silverstripe/admin'); - } - /** * Sets the upload folder name used by the insert media dialog * diff --git a/src/Forms/PasswordField.php b/src/Forms/PasswordField.php index de357d403..bd1adf7ab 100644 --- a/src/Forms/PasswordField.php +++ b/src/Forms/PasswordField.php @@ -2,8 +2,6 @@ namespace SilverStripe\Forms; -use SilverStripe\Dev\Deprecation; - /** * Password input field. */ @@ -34,14 +32,6 @@ class PasswordField extends TextField */ public function __construct($name, $title = null, $value = '') { - if (count(func_get_args()) > 3) { - Deprecation::notice( - '3.0', - 'Use setMaxLength() instead of constructor arguments', - Deprecation::SCOPE_GLOBAL - ); - } - parent::__construct($name, $title, $value); } diff --git a/src/Forms/TextField.php b/src/Forms/TextField.php index 20cac19ff..7988f6196 100644 --- a/src/Forms/TextField.php +++ b/src/Forms/TextField.php @@ -2,8 +2,6 @@ namespace SilverStripe\Forms; -use SilverStripe\Dev\Deprecation; - /** * Text input field. */ @@ -119,21 +117,6 @@ class TextField extends FormField implements TippableFieldInterface return $data; } - /** - * @return string - * @deprecated 4.0.1 Use setValue() instead - */ - public function InternallyLabelledField() - { - Deprecation::notice('4.0.1', 'Use setValue() instead'); - - if (!$this->value) { - $this->value = $this->Title(); - } - - return $this->Field(); - } - /** * Validate this field * diff --git a/src/Logging/MonologErrorHandler.php b/src/Logging/MonologErrorHandler.php index d9bbd3ba9..cd2bea834 100644 --- a/src/Logging/MonologErrorHandler.php +++ b/src/Logging/MonologErrorHandler.php @@ -5,7 +5,6 @@ namespace SilverStripe\Logging; use InvalidArgumentException; use Psr\Log\LoggerInterface; use Monolog\ErrorHandler as MonologHandler; -use SilverStripe\Dev\Deprecation; class MonologErrorHandler implements ErrorHandler { @@ -14,35 +13,6 @@ class MonologErrorHandler implements ErrorHandler */ private $loggers = []; - /** - * Set the PSR-3 logger to send errors & exceptions to. Will overwrite any previously configured - * loggers - * - * @deprecated 4.4.0 Use pushLogger() instead - * @param LoggerInterface $logger - * @return $this - */ - public function setLogger(LoggerInterface $logger) - { - Deprecation::notice('4.4.0', 'Use pushLogger() instead'); - - $this->loggers = [$logger]; - return $this; - } - - /** - * Get the first registered PSR-3 logger to send errors & exceptions to - * - * @deprecated 4.4.0 Use getLoggers() instead - * @return LoggerInterface - */ - public function getLogger() - { - Deprecation::notice('4.4.0', 'Use getLoggers() instead'); - - return reset($this->loggers); - } - /** * Adds a PSR-3 logger to send messages to, to the end of the stack * diff --git a/src/ORM/ArrayList.php b/src/ORM/ArrayList.php index 0a9482235..eae6272dc 100644 --- a/src/ORM/ArrayList.php +++ b/src/ORM/ArrayList.php @@ -6,7 +6,6 @@ use ArrayIterator; use InvalidArgumentException; use LogicException; use SilverStripe\Dev\Debug; -use SilverStripe\Dev\Deprecation; use SilverStripe\View\ArrayData; use SilverStripe\View\ViewableData; @@ -187,29 +186,7 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ public function limit($length, $offset = 0) { - // Type checking: designed for consistency with DataList::limit() - if ((!is_numeric($length) || !is_numeric($offset)) && !is_null($length)) { - Deprecation::notice( - '4.3', - 'Arguments to ArrayList::limit() should be numeric or null' - ); - } - - if ($length < 0 || $offset < 0) { - Deprecation::notice( - '4.3', - 'Arguments to ArrayList::limit() should be positive' - ); - } - if (!$length) { - if ($length === 0) { - Deprecation::notice( - '4.3', - "limit(0) is deprecated in SS4. In SS5 a limit of 0 will instead return no records." - ); - } - $length = count($this->items ?? []); } diff --git a/src/ORM/Connect/Database.php b/src/ORM/Connect/Database.php index 72054c662..9a46eed03 100644 --- a/src/ORM/Connect/Database.php +++ b/src/ORM/Connect/Database.php @@ -752,12 +752,11 @@ abstract class Database /** * Commit everything inside this transaction so far - * - * @param bool $chain - * @return bool|null Boolean is returned if success state is known, or null if + * + * Boolean is returned if success state is known, or null if * unknown. Note: For error checking purposes null should not be treated as error. */ - abstract public function transactionEnd($chain = false); + abstract public function transactionEnd(): bool|null; /** * Return depth of current transaction diff --git a/src/ORM/Connect/MySQLDatabase.php b/src/ORM/Connect/MySQLDatabase.php index b46e6e341..ef7cd1601 100644 --- a/src/ORM/Connect/MySQLDatabase.php +++ b/src/ORM/Connect/MySQLDatabase.php @@ -6,7 +6,6 @@ use SilverStripe\Assets\File; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Convert; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\PaginatedList; use SilverStripe\ORM\DataList; use SilverStripe\ORM\ArrayList; @@ -353,15 +352,10 @@ class MySQLDatabase extends Database implements TransactionManager return $this->getTransactionManager()->transactionDepth(); } - public function transactionEnd($chain = false) + public function transactionEnd():bool|null { $result = $this->getTransactionManager()->transactionEnd(); - if ($chain) { - Deprecation::notice('4.4', '$chain argument is deprecated'); - return $this->getTransactionManager()->transactionStart(); - } - return $result; } diff --git a/src/ORM/Connect/MySQLSchemaManager.php b/src/ORM/Connect/MySQLSchemaManager.php index f44b1c0d8..2359d9461 100644 --- a/src/ORM/Connect/MySQLSchemaManager.php +++ b/src/ORM/Connect/MySQLSchemaManager.php @@ -373,7 +373,7 @@ class MySQLSchemaManager extends DBSchemaManager public function enumValuesForField($tableName, $fieldName) { // Get the enum of all page types from the SiteTree table - $classnameinfo = $this->query("DESCRIBE \"$tableName\" \"$fieldName\"")->first(); + $classnameinfo = $this->query("DESCRIBE \"$tableName\" \"$fieldName\"")->record(); preg_match_all("/'[^,]+'/", $classnameinfo["Type"] ?? '', $matches); $classes = []; diff --git a/src/ORM/Connect/MySQLTransactionManager.php b/src/ORM/Connect/MySQLTransactionManager.php index b4d9d1a62..df189db66 100644 --- a/src/ORM/Connect/MySQLTransactionManager.php +++ b/src/ORM/Connect/MySQLTransactionManager.php @@ -2,8 +2,6 @@ namespace SilverStripe\ORM\Connect; -use SilverStripe\Dev\Deprecation; - /** * TransactionManager that executes MySQL-compatible transaction control queries */ diff --git a/src/ORM/Connect/NullDatabase.php b/src/ORM/Connect/NullDatabase.php index 0a78c3e67..70e5d1277 100644 --- a/src/ORM/Connect/NullDatabase.php +++ b/src/ORM/Connect/NullDatabase.php @@ -264,9 +264,9 @@ class NullDatabase extends Database // no-op } - public function transactionEnd($chain = false) + public function transactionEnd(): bool|null { - // no-op + return false; } public function transactionDepth() diff --git a/src/ORM/Connect/Query.php b/src/ORM/Connect/Query.php index afcf6d4f8..c4c4a4dbf 100644 --- a/src/ORM/Connect/Query.php +++ b/src/ORM/Connect/Query.php @@ -95,15 +95,6 @@ abstract class Query implements \IteratorAggregate return $this->getIterator()->current(); } - /** - * @deprecated Use record() instead - * @return array - */ - public function first() - { - return $this->record(); - } - /** * Returns the first column of the first record. * diff --git a/src/ORM/DB.php b/src/ORM/DB.php index ed38b65c4..c184ddcc3 100644 --- a/src/ORM/DB.php +++ b/src/ORM/DB.php @@ -2,7 +2,6 @@ namespace SilverStripe\ORM; -use BadMethodCallException; use InvalidArgumentException; use SilverStripe\Control\Director; use SilverStripe\Control\HTTPRequest; @@ -10,7 +9,6 @@ use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; use SilverStripe\Core\Environment; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\Connect\Database; use SilverStripe\ORM\Connect\DBConnector; use SilverStripe\ORM\Connect\DBSchemaManager; @@ -111,16 +109,6 @@ class DB return null; } - /** - * @deprecated 4.0.1 Use DB::get_conn() instead - * @todo PSR-2 standardisation will probably un-deprecate this - */ - public static function getConn($name = 'default') - { - Deprecation::notice('4.0.1', 'Use DB::get_conn() instead'); - return self::get_conn($name); - } - /** * Retrieves the schema manager for the current database * diff --git a/src/ORM/DataExtension.php b/src/ORM/DataExtension.php index 273f24c59..d4548d246 100644 --- a/src/ORM/DataExtension.php +++ b/src/ORM/DataExtension.php @@ -2,7 +2,6 @@ namespace SilverStripe\ORM; -use SilverStripe\Dev\Deprecation; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Extension; use SilverStripe\Forms\FieldList; @@ -19,15 +18,6 @@ use Exception; abstract class DataExtension extends Extension { - /** - * @deprecated 4.7.0 Will be removed without equivalent functionality - */ - public static function unload_extra_statics($class, $extension) - { - Deprecation::notice('4.7.0', 'Will be removed without equivalent functionality'); - throw new Exception('unload_extra_statics gone'); - } - /** * Hook for extension-specific validation. * diff --git a/src/ORM/DataObject.php b/src/ORM/DataObject.php index 22fb633c0..f66dc252a 100644 --- a/src/ORM/DataObject.php +++ b/src/ORM/DataObject.php @@ -11,7 +11,6 @@ use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Resettable; use SilverStripe\Dev\Debug; -use SilverStripe\Dev\Deprecation; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FormField; use SilverStripe\Forms\FormScaffolder; @@ -30,7 +29,6 @@ use SilverStripe\ORM\Queries\SQLDelete; use SilverStripe\ORM\Search\SearchContext; use SilverStripe\ORM\RelatedData\RelatedDataService; use SilverStripe\ORM\UniqueKey\UniqueKeyInterface; -use SilverStripe\ORM\UniqueKey\UniqueKeyService; use SilverStripe\Security\Member; use SilverStripe\Security\Permission; use SilverStripe\Security\Security; @@ -143,12 +141,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity */ private static $default_classname = null; - /** - * @deprecated 4.0.0:5.0.0 - * @var bool - */ - public $destroyed = false; - /** * Data stored in this objects database record. An array indexed by fieldname. * @@ -504,26 +496,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity /** * Create a duplicate of this node. Can duplicate many_many relations * - * @param bool $doWrite Perform a write() operation before returning the object. - * If this is true, it will create the duplicate in the database. - * @param array|null|false $relations List of relations to duplicate. * Will default to `cascade_duplicates` if null. * Set to 'false' to force none. * Set to specific array of names to duplicate to override these. * Note: If using versioned, this will additionally failover to `owns` config. - * @return static A duplicate of this node. The exact type will be the type of this node. */ - public function duplicate($doWrite = true, $relations = null) + public function duplicate(bool $doWrite = true, array|null $relations = null): static { - // Handle legacy behaviour - if (is_string($relations) || $relations === true) { - if ($relations === true) { - $relations = 'many_many'; - } - Deprecation::notice('5.0', 'Use cascade_duplicates config instead of providing a string to duplicate()'); - $relations = array_keys($this->config()->get($relations) ?? []) ?: []; - } - // Get duplicates if ($relations === null) { $relations = $this->config()->get('cascade_duplicates'); @@ -597,31 +576,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity } } - /** - * Copies the many_many and belongs_many_many relations from one object to another instance of the name of object. - * - * @deprecated 4.1.0 Use duplicateRelations() instead - * @param DataObject $sourceObject the source object to duplicate from - * @param DataObject $destinationObject the destination object to populate with the duplicated relations - * @param bool|string $filter - */ - protected function duplicateManyManyRelations($sourceObject, $destinationObject, $filter) - { - Deprecation::notice('4.1.0', 'Use duplicateRelations() instead'); - - // Get list of relations to duplicate - if ($filter === 'many_many' || $filter === 'belongs_many_many') { - $relations = $sourceObject->config()->get($filter); - } elseif ($filter === true) { - $relations = $sourceObject->manyMany(); - } else { - throw new InvalidArgumentException("Invalid many_many duplication filter"); - } - foreach ($relations as $manyManyName => $type) { - $this->duplicateManyManyRelation($sourceObject, $destinationObject, $manyManyName); - } - } - /** * Duplicates a single many_many relation from one object to another. * @@ -1262,18 +1216,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity return $result; } - /** - * Public accessor for {@see DataObject::validate()} - * - * @return ValidationResult - * @deprecated 4.12.0 Use validate() instead - */ - public function doValidate() - { - Deprecation::notice('4.12.0', 'Use validate() instead'); - return $this->validate(); - } - /** * Event handler called before writing to the database. * You can overload this to clean up or otherwise process data before writing it to the diff --git a/src/ORM/DataQuery.php b/src/ORM/DataQuery.php index 801f112a3..ba225d111 100644 --- a/src/ORM/DataQuery.php +++ b/src/ORM/DataQuery.php @@ -485,7 +485,7 @@ class DataQuery // Wrap the whole thing in an "EXISTS" $sql = 'SELECT CASE WHEN EXISTS(' . $statement->sql($params) . ') THEN 1 ELSE 0 END'; $result = DB::prepared_query($sql, $params); - $row = $result->first(); + $row = $result->record(); $result = reset($row); // Checking for 't' supports PostgreSQL before silverstripe/postgresql@2.2 diff --git a/src/ORM/DatabaseAdmin.php b/src/ORM/DatabaseAdmin.php index b5b0e7dfa..07bbce20c 100644 --- a/src/ORM/DatabaseAdmin.php +++ b/src/ORM/DatabaseAdmin.php @@ -10,7 +10,6 @@ use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Environment; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Manifest\ClassLoader; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\DevelopmentAdmin; use SilverStripe\ORM\Connect\DatabaseException; use SilverStripe\ORM\Connect\TableBuilder; @@ -368,22 +367,6 @@ class DatabaseAdmin extends Controller $this->extend('onAfterBuild', $quiet, $populate, $testMode); } - /** - * Given a base data class, a field name and an old and new class name (value), look for obsolete ($oldClassName) - * values in the $dataClass's $fieldName column and replace it with $newClassName. - * - * @param string $dataClass The data class to look up - * @param string $fieldName The field name to look in for obsolete class names - * @param string $oldClassName The old class name - * @param string $newClassName The new class name - * @deprecated 4.12.0 Use updateLegacyClassNameField() instead - */ - protected function updateLegacyClassNames($dataClass, $fieldName, $oldClassName, $newClassName) - { - Deprecation::notice('4.12.0', 'Use updateLegacyClassNameField() instead'); - $this->updateLegacyClassNameField($dataClass, $fieldName, [$oldClassName => $newClassName]); - } - /** * Given a base data class, a field name and a mapping of class replacements, look for obsolete * values in the $dataClass's $fieldName column and replace it with $mapping diff --git a/src/ORM/FieldType/DBClassName.php b/src/ORM/FieldType/DBClassName.php index 0b5943593..572234848 100644 --- a/src/ORM/FieldType/DBClassName.php +++ b/src/ORM/FieldType/DBClassName.php @@ -4,7 +4,6 @@ namespace SilverStripe\ORM\FieldType; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DB; @@ -32,17 +31,6 @@ class DBClassName extends DBEnum private static $index = true; - /** - * Clear all cached classname specs. It's necessary to clear all cached subclassed names - * for any classes if a new class manifest is generated. - * @deprecated 4.3.0 Use DBEnum::flushCache() instead - */ - public static function clear_classname_cache() - { - Deprecation::notice('4.3.0', 'Use DBEnum::flushCache() instead'); - DBEnum::flushCache(); - } - /** * Create a new DBClassName field * diff --git a/src/ORM/ManyManyThroughQueryManipulator.php b/src/ORM/ManyManyThroughQueryManipulator.php index 06a422f12..38bb95332 100644 --- a/src/ORM/ManyManyThroughQueryManipulator.php +++ b/src/ORM/ManyManyThroughQueryManipulator.php @@ -5,7 +5,6 @@ namespace SilverStripe\ORM; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\Queries\SQLSelect; /** @@ -54,27 +53,17 @@ class ManyManyThroughQueryManipulator implements DataQueryManipulator /** * Build query manipulator for a given join table. Additional parameters (foreign key, etc) * will be inferred at evaluation from query parameters set via the ManyManyThroughList - * - * @param string $joinClass Class name of the joined dataobject record - * @param string $localKey The key in the join table that maps to the dataClass' PK. - * @param string $foreignKey The key in the join table that maps to joined class' PK. - * @param string $foreignClass the 'from' class name - * @param string $parentClass Name of parent class. Subclass of $foreignClass */ - public function __construct($joinClass, $localKey, $foreignKey, $foreignClass = null, $parentClass = null) + public function __construct(string $joinClass, string $localKey, string $foreignKey, string $foreignClass, string $parentClass) { $this->setJoinClass($joinClass); $this->setLocalKey($localKey); $this->setForeignKey($foreignKey); if ($foreignClass) { $this->setForeignClass($foreignClass); - } else { - Deprecation::notice('5.0', 'Arg $foreignClass will be mandatory in 5.x'); } if ($parentClass) { $this->setParentClass($parentClass); - } else { - Deprecation::notice('5.0', 'Arg $parentClass will be mandatory in 5.x'); } } diff --git a/src/ORM/Queries/SQLConditionalExpression.php b/src/ORM/Queries/SQLConditionalExpression.php index dc551d879..55d6ae5c2 100644 --- a/src/ORM/Queries/SQLConditionalExpression.php +++ b/src/ORM/Queries/SQLConditionalExpression.php @@ -2,8 +2,6 @@ namespace SilverStripe\ORM\Queries; -use SilverStripe\Dev\Deprecation; - /** * Represents a SQL query for an expression which interacts with existing rows * (SELECT / DELETE / UPDATE) with a WHERE clause @@ -265,14 +263,6 @@ abstract class SQLConditionalExpression extends SQLExpression */ public function getJoins(&$parameters = []) { - if (func_num_args() == 0) { - Deprecation::notice( - '4.0', - 'SQLConditionalExpression::getJoins() now may produce parameters which are necessary to - execute this query' - ); - } - // Sort the joins $parameters = []; $joins = $this->getOrderedJoins($this->from); diff --git a/src/ORM/Queries/SQLSelect.php b/src/ORM/Queries/SQLSelect.php index 574841d5a..9b2f3c440 100644 --- a/src/ORM/Queries/SQLSelect.php +++ b/src/ORM/Queries/SQLSelect.php @@ -3,7 +3,6 @@ namespace SilverStripe\ORM\Queries; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\DB; use InvalidArgumentException; @@ -250,14 +249,6 @@ class SQLSelect extends SQLConditionalExpression throw new InvalidArgumentException("SQLSelect::setLimit() only takes positive values"); } - if ($limit === 0) { - Deprecation::notice( - '4.3', - "setLimit(0) is deprecated in SS4. To clear limit, call setLimit(null). " . - "In SS5 a limit of 0 will instead return no records." - ); - } - if (is_numeric($limit) && ($limit || $offset)) { $this->limit = [ 'start' => (int)$offset, diff --git a/src/ORM/Search/SearchContext.php b/src/ORM/Search/SearchContext.php index e4ad3bd6d..ca374ff69 100644 --- a/src/ORM/Search/SearchContext.php +++ b/src/ORM/Search/SearchContext.php @@ -75,13 +75,6 @@ class SearchContext */ protected $searchParams = []; - /** - * The logical connective used to join WHERE clauses. Must be "AND". - * @deprecated 5.0 - * @var string - */ - public $connective = 'AND'; - /** * A key value pair of values that should be searched for. * The keys should match the field names specified in {@link self::$fields}. @@ -147,9 +140,6 @@ class SearchContext */ public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null) { - if ($this->connective != "AND") { - throw new Exception("SearchContext connective '$this->connective' not supported after ORM-rewrite."); - } $this->setSearchParams($searchParams); $query = $this->prepareQuery($sort, $limit, $existingQuery); return $this->search($query); diff --git a/src/ORM/ValidationResult.php b/src/ORM/ValidationResult.php index 3ffe74bc2..6d45996d5 100644 --- a/src/ORM/ValidationResult.php +++ b/src/ORM/ValidationResult.php @@ -3,10 +3,7 @@ namespace SilverStripe\ORM; use InvalidArgumentException; -use Serializable; -use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injectable; -use SilverStripe\Dev\Deprecation; /** * A class that combined as a boolean result with an optional list of error messages. @@ -15,7 +12,7 @@ use SilverStripe\Dev\Deprecation; * Each message can have a code or field which will uniquely identify that message. However, * messages can be stored without a field or message as an "overall" message. */ -class ValidationResult implements Serializable +class ValidationResult { use Injectable; @@ -64,22 +61,6 @@ class ValidationResult implements Serializable */ protected $messages = []; - /** - * Create a new ValidationResult. - * By default, it is a successful result. Call $this->error() to record errors. - */ - public function __construct() - { - if (func_num_args() > 0) { - Deprecation::notice('3.2', '$valid parameter is deprecated please addError to mark the result as invalid', false); - $this->isValid = func_get_arg(0); - } - if (func_num_args() > 1) { - Deprecation::notice('3.2', '$message parameter is deprecated please use addMessage or addError instead', false); - $this->addError(func_get_arg(1)); - } - } - /** * Record an error against this validation result, * @@ -227,30 +208,4 @@ class ValidationResult implements Serializable $this->messages = $data['messages']; $this->isValid = $data['isValid']; } - - /** - * The __serialize() magic method will be automatically used instead of this - * - * @return string - * @deprecated 4.12.0 Use __serialize() instead - */ - public function serialize() - { - Deprecation::notice('4.12.0', 'Use __serialize() instead'); - return json_encode([$this->messages, $this->isValid]); - } - - /** - * The __unserialize() magic method will be automatically used instead of this almost all the time - * This method will be automatically used if existing serialized data was not saved as an associative array - * and the PHP version used in less than PHP 9.0 - * - * @param string $serialized - * @deprecated 4.12.0 Use __unserialize() instead - */ - public function unserialize($serialized) - { - Deprecation::notice('4.12.0', 'Use __unserialize() instead'); - list($this->messages, $this->isValid) = json_decode($serialized ?? '', true); - } } diff --git a/src/Security/LoginAttempt.php b/src/Security/LoginAttempt.php index dbcc1d63d..851cff825 100644 --- a/src/Security/LoginAttempt.php +++ b/src/Security/LoginAttempt.php @@ -15,13 +15,12 @@ use SilverStripe\ORM\DataObject; * complies with your privacy standards. We're logging * username and IP. * - * @property string $Email Email address used for login attempt. @deprecated 3.0.0:5.0.0 * @property string $EmailHashed sha1 hashed Email address used for login attempt * @property string $Status Status of the login attempt, either 'Success' or 'Failure' * @property string $IP IP address of user attempting to login - * @property int $MemberID ID of the Member, only if Member with Email exists + * @property int $MemberID ID of the Member * - * @method Member Member() Member object of the user trying to log in, only if Member with Email exists + * @method Member Member() Member object of the user trying to log in */ class LoginAttempt extends DataObject { @@ -36,7 +35,6 @@ class LoginAttempt extends DataObject const FAILURE = 'Failure'; private static $db = [ - 'Email' => 'Varchar(255)', // Remove in 5.0 'EmailHashed' => 'Varchar(255)', 'Status' => "Enum('Success,Failure')", 'IP' => 'Varchar(255)', @@ -60,7 +58,6 @@ class LoginAttempt extends DataObject public function fieldLabels($includerelations = true) { $labels = parent::fieldLabels($includerelations); - $labels['Email'] = _t(__CLASS__ . '.Email', 'Email Address'); $labels['EmailHashed'] = _t(__CLASS__ . '.EmailHashed', 'Email Address (hashed)'); $labels['Status'] = _t(__CLASS__ . '.Status', 'Status'); $labels['IP'] = _t(__CLASS__ . '.IP', 'IP Address'); diff --git a/src/Security/LoginForm.php b/src/Security/LoginForm.php index a927915a9..248b80851 100644 --- a/src/Security/LoginForm.php +++ b/src/Security/LoginForm.php @@ -15,12 +15,6 @@ use SilverStripe\Forms\Form; */ abstract class LoginForm extends Form { - /** - * @deprecated 4.4.0:5.0.0 Use getAuthenticatorClass() or setAuthenticatorClass() instead - * @var string - */ - protected $authenticator_class; - /** * Authenticator class to use with this login form * @@ -61,8 +55,7 @@ abstract class LoginForm extends Form */ public function getAuthenticatorClass() { - // B/C for deprecated authenticator_class property - return $this->authenticator_class ?: $this->authenticatorClass; + return $this->authenticatorClass; } /** diff --git a/src/Security/Member.php b/src/Security/Member.php index f54ea2152..48356031b 100644 --- a/src/Security/Member.php +++ b/src/Security/Member.php @@ -6,14 +6,12 @@ use IntlDateFormatter; use InvalidArgumentException; use SilverStripe\Admin\LeftAndMain; use SilverStripe\CMS\Controllers\CMSMain; -use SilverStripe\Control\Controller; use SilverStripe\Control\Director; use SilverStripe\Control\Email\Email; use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\TestMailer; use SilverStripe\Forms\ConfirmedPasswordField; use SilverStripe\Forms\DropdownField; @@ -162,7 +160,7 @@ class Member extends DataObject /** * @config - * @var array See {@link set_title_columns()} + * @var array */ private static $title_format = null; @@ -279,42 +277,6 @@ class Member extends DataObject $service->findOrCreateDefaultAdmin(); } - /** - * Get the default admin record if it exists, or creates it otherwise if enabled - * - * @deprecated 4.0.1 Use DefaultAdminService::findOrCreateDefaultAdmin() instead - * @return Member - */ - public static function default_admin() - { - Deprecation::notice('4.0.1', 'Use DefaultAdminService::findOrCreateDefaultAdmin() instead'); - return DefaultAdminService::singleton()->findOrCreateDefaultAdmin(); - } - - /** - * Check if the passed password matches the stored one (if the member is not locked out). - * - * @deprecated 4.0.1 Use Authenticator::checkPassword() instead - * - * @param string $password - * @return ValidationResult - */ - public function checkPassword($password) - { - Deprecation::notice('4.0.1', 'Use Authenticator::checkPassword() instead'); - - // With a valid user and password, check the password is correct - $result = ValidationResult::create(); - $authenticators = Security::singleton()->getApplicableAuthenticators(Authenticator::CHECK_PASSWORD); - foreach ($authenticators as $authenticator) { - $authenticator->checkPassword($this, $password, $result); - if (!$result->isValid()) { - break; - } - } - return $result; - } - /** * Check if this user is the currently configured default admin * @@ -447,16 +409,6 @@ class Member extends DataObject return strtotime(date('Y-m-d')) >= strtotime($this->PasswordExpiry ?? ''); } - /** - * @deprecated 4.12.0 Use Security::setCurrentUser() or IdentityStore::logIn() instead - * - */ - public function logIn() - { - Deprecation::notice('4.12.0', 'Use Security::setCurrentUser() or IdentityStore::logIn() instead'); - Security::setCurrentUser($this); - } - /** * Called before a member is logged in via session/cookie/etc */ @@ -501,39 +453,6 @@ class Member extends DataObject $this->write(); } - /** - * Check if the member ID logged in session actually - * has a database record of the same ID. If there is - * no logged in user, FALSE is returned anyway. - * - * @deprecated 4.12.0 Use Security::getCurrentUser() instead - * - * @return boolean TRUE record found FALSE no record found - */ - public static function logged_in_session_exists() - { - Deprecation::notice('4.12.0', 'Use Security::getCurrentUser() instead'); - - $member = Security::getCurrentUser(); - if ($member && $member->exists()) { - return true; - } - - return false; - } - - /** - * Logs this member out. - * - * @deprecated 4.12.0 Use Security::setCurrentUser(null) or an IdentityStore instead - */ - public function logOut() - { - Deprecation::notice('4.12.0', 'Use Security::setCurrentUser(null) or an IdentityStore instead'); - - Injector::inst()->get(IdentityStore::class)->logOut(Controller::curr()->getRequest()); - } - /** * Audit logging hook, called before a member is logged out * @@ -582,24 +501,12 @@ class Member extends DataObject /** * Generate an auto login token which can be used to reset the password, * at the same time hashing it and storing in the database. - * - * @param int|null $lifetime DEPRECATED: The lifetime of the auto login hash in days. Overrides - * the Member.auto_login_token_lifetime config value + * * @return string Token that should be passed to the client (but NOT persisted). */ - public function generateAutologinTokenAndStoreHash($lifetime = null) + public function generateAutologinTokenAndStoreHash() { - if ($lifetime !== null) { - Deprecation::notice( - '5.0', - 'Passing a $lifetime to Member::generateAutologinTokenAndStoreHash() is deprecated, - use the Member.auto_login_token_lifetime config setting instead', - Deprecation::SCOPE_GLOBAL - ); - $lifetime = (86400 * $lifetime); // Method argument is days, convert to seconds - } else { - $lifetime = $this->config()->auto_login_token_lifetime; - } + $lifetime = $this->config()->auto_login_token_lifetime; do { $generator = new RandomGenerator(); @@ -758,27 +665,13 @@ class Member extends DataObject } - /** - * Returns the current logged in user - * - * @deprecated 4.12.0 Use Security::getCurrentUser() instead - * - * @return Member - */ - public static function currentUser() - { - Deprecation::notice('4.12.0', 'Use Security::getCurrentUser() instead'); - - return Security::getCurrentUser(); - } - /** * Temporarily act as the specified user, limited to a $callback, but * without logging in as that user. * * E.g. * - * Member::actAs(Security::findAnAdministrator(), function() { + * Member::actAs(DefaultAdminService::findOrCreateDefaultAdmin(), function() { * $record->write(); * }); * @@ -805,56 +698,6 @@ class Member extends DataObject } } - /** - * Get the ID of the current logged in user - * - * @deprecated 4.12.0 Use Security::getCurrentUser() instead - * - * @return int Returns the ID of the current logged in user or 0. - */ - public static function currentUserID() - { - Deprecation::notice('4.12.0', 'Use Security::getCurrentUser() instead'); - - $member = Security::getCurrentUser(); - if ($member) { - return $member->ID; - } - return 0; - } - - /** - * Generate a random password, with randomiser to kick in if there's no words file on the - * filesystem. - * - * @return string Returns a random password. - * - * @deprecated 4.12.0 Will be removed without equivalent functionality to replace it - */ - public static function create_new_password() - { - Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it'); - $words = Security::config()->uninherited('word_list'); - - if ($words && file_exists($words ?? '')) { - $words = file($words ?? ''); - - list($usec, $sec) = explode(' ', microtime() ?? ''); - mt_srand($sec + ((float)$usec * 100000)); - - $word = trim($words[random_int(0, count($words) - 1)] ?? ''); - $number = random_int(10, 999); - - return $word . $number; - } else { - $random = mt_rand(); - $string = md5($random ?? ''); - $output = substr($string ?? '', 0, 8); - - return $output; - } - } - /** * Event handler called before writing to the database. */ @@ -1103,26 +946,6 @@ class Member extends DataObject } } - /** - * @param array $columns Column names on the Member record to show in {@link getTitle()}. - * @param string $sep Separator - * @deprecated 4.12.0 Use Member.title_format config instead - */ - public static function set_title_columns($columns, $sep = ' ') - { - Deprecation::notice('4.12.0', 'Use Member.title_format config instead'); - if (!is_array($columns)) { - $columns = [$columns]; - } - self::config()->set( - 'title_format', - [ - 'columns' => $columns, - 'sep' => $sep - ] - ); - } - //------------------- HELPER METHODS -----------------------------------// /** diff --git a/src/Security/MemberAuthenticator/MemberAuthenticator.php b/src/Security/MemberAuthenticator/MemberAuthenticator.php index bda474820..a1b7ef8d7 100644 --- a/src/Security/MemberAuthenticator/MemberAuthenticator.php +++ b/src/Security/MemberAuthenticator/MemberAuthenticator.php @@ -68,7 +68,7 @@ class MemberAuthenticator implements Authenticator $email = !empty($data['Email']) ? $data['Email'] : null; $result = $result ?: ValidationResult::create(); - // Check default login (see Security::setDefaultAdmin()) + // Check default login $asDefaultAdmin = DefaultAdminService::isDefaultAdmin($email); if ($asDefaultAdmin) { // If logging is as default admin, ensure record is setup correctly diff --git a/src/Security/MemberPassword.php b/src/Security/MemberPassword.php index 845110446..751fcd858 100644 --- a/src/Security/MemberPassword.php +++ b/src/Security/MemberPassword.php @@ -45,7 +45,6 @@ class MemberPassword extends DataObject /** * Check if the given password is the same as the one stored in this record. - * See {@link Member->checkPassword()}. * * @param string $password Cleartext password * @return bool diff --git a/src/Security/PasswordValidator.php b/src/Security/PasswordValidator.php index d6fad7fba..776709aaa 100644 --- a/src/Security/PasswordValidator.php +++ b/src/Security/PasswordValidator.php @@ -5,7 +5,6 @@ namespace SilverStripe\Security; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Extensible; use SilverStripe\Core\Injector\Injectable; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\ValidationResult; /** @@ -13,9 +12,10 @@ use SilverStripe\ORM\ValidationResult; * * * $pwdVal = new PasswordValidator(); - * $pwdValidator->minLength(7); + * $pwdValidator->setMinLength(7); * $pwdValidator->checkHistoricalPasswords(6); - * $pwdValidator->characterStrength(3, array("lowercase", "uppercase", "digits", "punctuation")); + * $pwdValidator->setMinTestScore(3); + * $pwdValidator->setTestNames(array("lowercase", "uppercase", "digits", "punctuation")); * * Member::set_password_validator($pwdValidator); * @@ -75,52 +75,6 @@ class PasswordValidator */ protected $historicalPasswordCount = null; - /** - * Minimum password length - * - * @param int $minLength - * @return $this - * @deprecated 4.5.0 Use setMinLength() instead - */ - public function minLength($minLength) - { - Deprecation::notice('4.5.0', 'Use setMinLength() instead'); - return $this->setMinLength($minLength); - } - - /** - * Check the character strength of the password. - * - * Eg: $this->characterStrength(3, array("lowercase", "uppercase", "digits", "punctuation")) - * - * @param int $minScore The minimum number of character tests that must pass - * @param string[] $testNames The names of the tests to perform - * @return $this - * @deprecated 4.5.0 Use setMinTestScore($score) and setTestNames($names) instead - */ - public function characterStrength($minScore, $testNames = null) - { - Deprecation::notice('4.5.0', 'Use setMinTestScore($score) and setTestNames($names) instead'); - $this->setMinTestScore($minScore); - if ($testNames) { - $this->setTestNames($testNames); - } - return $this; - } - - /** - * Check a number of previous passwords that the user has used, and don't let them change to that. - * - * @param int $count - * @return $this - * @deprecated 4.5.0 Use setHistoricCount($value) instead - */ - public function checkHistoricalPasswords($count) - { - Deprecation::notice('4.5.0', 'Use setHistoricCount($value) instead'); - return $this->setHistoricCount($count); - } - /** * @return int */ diff --git a/src/Security/Permission.php b/src/Security/Permission.php index 1e5ac0376..91e21303f 100644 --- a/src/Security/Permission.php +++ b/src/Security/Permission.php @@ -2,7 +2,6 @@ namespace SilverStripe\Security; -use SilverStripe\Dev\Deprecation; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Resettable; use SilverStripe\Dev\TestOnly; @@ -66,23 +65,6 @@ class Permission extends DataObject implements TemplateGlobalProvider, Resettabl const INHERIT_PERMISSION = 0; - /** - * Method to globally disable "strict" checking, which means a permission - * will be granted if the key does not exist at all. - * - * @deprecated 4.4.0 - * @var array - */ - private static $declared_permissions = null; - - /** - * Linear list of declared permissions in the system. - * - * @deprecated 4.4.0 - * @var array - */ - private static $declared_permissions_list = null; - /** * @config * @var $strict_checking Boolean Method to globally disable "strict" checking, @@ -657,73 +639,6 @@ class Permission extends DataObject implements TemplateGlobalProvider, Resettabl } } - /** - * Get a linear list of the permissions in the system. - * - * @return array Linear list of declared permissions in the system. - * @deprecated 4.4.0 Will be removed without equivalent functionality - */ - public static function get_declared_permissions_list() - { - Deprecation::notice('4.4.0', 'Will be removed without equivalent functionality'); - if (!self::$declared_permissions) { - return null; - } - - if (self::$declared_permissions_list) { - return self::$declared_permissions_list; - } - - self::$declared_permissions_list = []; - - self::traverse_declared_permissions(self::$declared_permissions, self::$declared_permissions_list); - - return self::$declared_permissions_list; - } - - /** - * Look up the human-readable title for the permission as defined by Permission::declare_permissions - * - * @param string $perm Permission code - * @return string Label for the given permission, or the permission itself if the label doesn't exist - * @deprecated 4.4.0 Will be removed without equivalent functionality - */ - public static function get_label_for_permission($perm) - { - Deprecation::notice('4.4.0', 'Will be removed without equivalent functionality'); - $list = self::get_declared_permissions_list(); - if (array_key_exists($perm, $list ?? [])) { - return $list[$perm]; - } - return $perm; - } - - /** - * Recursively traverse the nested list of declared permissions and create - * a linear list. - * - * @param array $declared Nested structure of permissions. - * @param array $list List of permissions in the structure. The result will be - * written to this array. - * @deprecated 4.4.0 Will be removed without equivalent functionality - */ - protected static function traverse_declared_permissions($declared, &$list) - { - Deprecation::notice('4.4.0', 'Will be removed without equivalent functionality'); - if (!is_array($declared)) { - return; - } - - foreach ($declared as $perm => $value) { - if ($value instanceof Permission_Group) { - $list[] = $value->getName(); - self::traverse_declared_permissions($value->getPermissions(), $list); - } else { - $list[$perm] = $value; - } - } - } - public function onBeforeWrite() { parent::onBeforeWrite(); diff --git a/src/Security/RandomGenerator.php b/src/Security/RandomGenerator.php index 4134b787f..1895c9ff8 100644 --- a/src/Security/RandomGenerator.php +++ b/src/Security/RandomGenerator.php @@ -2,37 +2,12 @@ namespace SilverStripe\Security; -use Error; use Exception; -use SilverStripe\Dev\Deprecation; - /** * Convenience class for generating cryptographically secure pseudo-random strings/tokens */ class RandomGenerator { - /** - * @return string A 128-character, randomly generated ASCII string - * @throws Exception If no suitable CSPRNG is installed - * @deprecated 4.4.0 Use native php function random_bytes() instead - */ - public function generateEntropy() - { - Deprecation::notice('4.4.0', 'Use native php function random_bytes() instead'); - - try { - return bin2hex(random_bytes(64)); - } catch (Error $e) { - throw $e; // This is required so that Error exceptions in PHP 5 aren't caught below - } catch (Exception $e) { - throw new Exception( - 'It appears there is no suitable CSPRNG (random number generator) installed. ' - . 'Please review the server requirements documentation: ' - . 'https://docs.silverstripe.org/en/getting_started/server_requirements/' - ); - } - } - /** * Generates a random token that can be used for session IDs, CSRF tokens etc., based on * hash algorithms. diff --git a/src/Security/Security.php b/src/Security/Security.php index 73d85d61f..fd7a64ecf 100644 --- a/src/Security/Security.php +++ b/src/Security/Security.php @@ -16,7 +16,6 @@ use SilverStripe\Control\RequestHandler; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\TestOnly; use SilverStripe\Forms\Form; use SilverStripe\ORM\ArrayList; @@ -83,16 +82,6 @@ class Security extends Controller implements TemplateGlobalProvider */ private static $remember_username = true; - /** - * Location of word list to use for generating passwords - * - * @config - * @var string - * - * @deprecated 4.12 Will be removed without equivalent functionality to replace it - */ - private static $word_list = './wordlist.txt'; - /** * @config * @var string @@ -462,30 +451,6 @@ class Security extends Controller implements TemplateGlobalProvider return self::$currentUser; } - /** - * Get the login forms for all available authentication methods - * - * @deprecated 4.12.0 Use delegateToMultipleHandlers() instead - * - * @return array Returns an array of available login forms (array of Form - * objects). - * - */ - public function getLoginForms() - { - Deprecation::notice('4.12.0', 'Use delegateToMultipleHandlers() instead'); - - return array_map( - function (Authenticator $authenticator) { - return [ - $authenticator->getLoginHandler($this->Link())->loginForm() - ]; - }, - $this->getApplicableAuthenticators() ?? [] - ); - } - - /** * Get a link to a security action * @@ -1061,119 +1026,6 @@ class Security extends Controller implements TemplateGlobalProvider ); } - /** - * Return an existing member with administrator privileges, or create one of necessary. - * - * Will create a default 'Administrators' group if no group is found - * with an ADMIN permission. Will create a new 'Admin' member with administrative permissions - * if no existing Member with these permissions is found. - * - * Important: Any newly created administrator accounts will NOT have valid - * login credentials (Email/Password properties), which means they can't be used for login - * purposes outside of any default credentials set through {@link Security::setDefaultAdmin()}. - * - * @return Member - * - * @deprecated 4.0.1 Use DefaultAdminService::findOrCreateDefaultAdmin() - */ - public static function findAnAdministrator() - { - Deprecation::notice('4.0.1', 'Use DefaultAdminService::findOrCreateDefaultAdmin()'); - - $service = DefaultAdminService::singleton(); - return $service->findOrCreateDefaultAdmin(); - } - - /** - * Flush the default admin credentials - * - * @deprecated 4.0.1 Use DefaultAdminService::clearDefaultAdmin() - */ - public static function clear_default_admin() - { - Deprecation::notice('4.0.1', 'Use DefaultAdminService::clearDefaultAdmin()'); - - DefaultAdminService::clearDefaultAdmin(); - } - - /** - * Set a default admin in dev-mode - * - * This will set a static default-admin which is not existing - * as a database-record. By this workaround we can test pages in dev-mode - * with a unified login. Submitted login-credentials are first checked - * against this static information in {@link Security::authenticate()}. - * - * @param string $username The user name - * @param string $password The password (in cleartext) - * @return bool True if successfully set - * - * @deprecated 4.0.1 Use DefaultAdminService::setDefaultAdmin($username, $password) - */ - public static function setDefaultAdmin($username, $password) - { - Deprecation::notice('4.0.1', 'Use DefaultAdminService::setDefaultAdmin($username, $password)'); - - DefaultAdminService::setDefaultAdmin($username, $password); - return true; - } - - /** - * Checks if the passed credentials are matching the default-admin. - * Compares cleartext-password set through Security::setDefaultAdmin(). - * - * @param string $username - * @param string $password - * @return bool - * - * @deprecated 4.0.1 Use DefaultAdminService::isDefaultAdminCredentials() instead - */ - public static function check_default_admin($username, $password) - { - Deprecation::notice('4.0.1', 'Use DefaultAdminService::isDefaultAdminCredentials() instead'); - - /** @var DefaultAdminService $service */ - return DefaultAdminService::isDefaultAdminCredentials($username, $password); - } - - /** - * Check that the default admin account has been set. - * - * @deprecated 4.0.1 Use DefaultAdminService::hasDefaultAdmin() instead - */ - public static function has_default_admin() - { - Deprecation::notice('4.0.1', 'Use DefaultAdminService::hasDefaultAdmin() instead'); - - return DefaultAdminService::hasDefaultAdmin(); - } - - /** - * Get default admin username - * - * @deprecated 4.0.1 Use DefaultAdminService::getDefaultAdminUsername() instead - * @return string - */ - public static function default_admin_username() - { - Deprecation::notice('4.0.1', 'Use DefaultAdminService::getDefaultAdminUsername() instead'); - - return DefaultAdminService::getDefaultAdminUsername(); - } - - /** - * Get default admin password - * - * @deprecated 4.0.1 Use DefaultAdminService::getDefaultAdminPassword() instead - * @return string - */ - public static function default_admin_password() - { - Deprecation::notice('4.0.1', 'Use DefaultAdminService::getDefaultAdminPassword() instead'); - - return DefaultAdminService::getDefaultAdminPassword(); - } - /** * Encrypt a password according to the current password encryption settings. * If the settings are so that passwords shouldn't be encrypted, the diff --git a/src/View/Embed/EmbedResource.php b/src/View/Embed/EmbedResource.php deleted file mode 100644 index f2682bfbc..000000000 --- a/src/View/Embed/EmbedResource.php +++ /dev/null @@ -1,153 +0,0 @@ -url = $url; - } - - public function getWidth() - { - return $this->getEmbed()->getWidth() ?: 100; - } - - public function getHeight() - { - return $this->getEmbed()->getHeight() ?: 100; - } - - public function getPreviewURL() - { - // Use thumbnail url - if ($this->getEmbed()->image) { - return $this->getEmbed()->image; - } - - // Use direct image type - if ($this->getType() === 'photo' && !empty($this->getEmbed()->url)) { - return $this->getEmbed()->url; - } - - // Default media - return ModuleResourceLoader::resourceURL( - 'silverstripe/asset-admin:client/dist/images/icon_file.png' - ); - } - - /** - * Get human readable name for this resource - * - * @return string - */ - public function getName() - { - if ($this->getEmbed()->title) { - return $this->getEmbed()->title; - } - - return preg_replace('/\?.*/', '', basename($this->getEmbed()->getUrl() ?? '')); - } - - public function getType() - { - return $this->getEmbed()->type; - } - - public function validate() - { - return !empty($this->getEmbed()->code); - } - - /** - * @param array $options - * @return $this - */ - public function setOptions(array $options) - { - $this->options = $options; - return $this; - } - - /** - * @return array - */ - public function getOptions() - { - return $this->options; - } - - /** - * @param DispatcherInterface $dispatcher - * @return $this - */ - public function setDispatcher(DispatcherInterface $dispatcher) - { - $this->dispatcher = $dispatcher; - return $this; - } - - /** - * @return DispatcherInterface - */ - public function getDispatcher() - { - return $this->dispatcher; - } - - /** - * Returns a bootstrapped Embed object - * - * @return Adapter - */ - public function getEmbed() - { - if (!$this->embed) { - $this->embed = Embed::create($this->url, $this->getOptions(), $this->getDispatcher()); - } - return $this->embed; - } -} diff --git a/src/View/Requirements.php b/src/View/Requirements.php index bd7723a5c..58e30c0a2 100644 --- a/src/View/Requirements.php +++ b/src/View/Requirements.php @@ -6,7 +6,6 @@ use InvalidArgumentException; use SilverStripe\Control\HTTPResponse; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Flushable; -use SilverStripe\Dev\Deprecation; /** * Requirements tracker for JavaScript and CSS. @@ -303,14 +302,6 @@ class Requirements implements Flushable */ public static function includeInHTML($content) { - if (func_num_args() > 1) { - Deprecation::notice( - '5.0', - '$templateFile argument is deprecated. includeInHTML takes a sole $content parameter now.' - ); - $content = func_get_arg(1); - } - return self::backend()->includeInHTML($content); } @@ -334,11 +325,10 @@ class Requirements implements Flushable * 'framework/javascript/lang' * @param bool $return Return all relative file paths rather than including them in * requirements - * @param bool $langOnly @deprecated 4.1.0:5.0.0 as i18n.js should be included manually in your project - * + * * @return array */ - public static function add_i18n_javascript($langDir, $return = false, $langOnly = false) + public static function add_i18n_javascript($langDir, $return = false) { return self::backend()->add_i18n_javascript($langDir, $return); } diff --git a/src/View/Requirements_Backend.php b/src/View/Requirements_Backend.php index 3052d7b0a..48619c57a 100644 --- a/src/View/Requirements_Backend.php +++ b/src/View/Requirements_Backend.php @@ -16,7 +16,6 @@ use SilverStripe\Core\Manifest\ModuleResourceLoader; use SilverStripe\Core\Manifest\ResourceURLGenerator; use SilverStripe\Core\Path; use SilverStripe\Dev\Debug; -use SilverStripe\Dev\Deprecation; use SilverStripe\i18n\i18n; use SilverStripe\ORM\FieldType\DBField; use Symfony\Component\Filesystem\Path as FilesystemPath; @@ -139,13 +138,6 @@ class Requirements_Backend */ protected $combinedFiles = []; - /** - * Use the injected minification service to minify any javascript file passed to {@link combine_files()}. - * - * @var bool - */ - protected $minifyCombinedFiles = false; - /** * Whether or not file headers should be written when combining files * @@ -210,11 +202,6 @@ class Requirements_Backend */ protected $assetHandler = null; - /** - * @var Requirements_Minifier - */ - protected $minifier = null; - /** * Gets the backend storage for generated files * @@ -235,28 +222,6 @@ class Requirements_Backend $this->assetHandler = $handler; } - /** - * Gets the minification service for this backend - * - * @return Requirements_Minifier - * @deprecated 4.0.1 Will be removed without equivalent functionality - */ - public function getMinifier() - { - Deprecation::notice('4.0.1', 'Will be removed without equivalent functionality'); - return $this->minifier; - } - - /** - * Set a new minification service for this backend - * - * @param Requirements_Minifier $minifier - */ - public function setMinifier(Requirements_Minifier $minifier = null) - { - $this->minifier = $minifier; - } - /** * Enable or disable the combination of CSS and JavaScript files * @@ -385,28 +350,6 @@ class Requirements_Backend return $this->forceJSToBottom; } - /** - * Check if minify files should be combined - * - * @return bool - */ - public function getMinifyCombinedFiles() - { - return $this->minifyCombinedFiles; - } - - /** - * Set if combined files should be minified - * - * @param bool $minify - * @return $this - */ - public function setMinifyCombinedFiles($minify) - { - $this->minifyCombinedFiles = $minify; - return $this; - } - /** * Register the given JavaScript file as required. * @@ -812,14 +755,6 @@ class Requirements_Backend */ public function includeInHTML($content) { - if (func_num_args() > 1) { - Deprecation::notice( - '5.0', - '$templateFile argument is deprecated. includeInHTML takes a sole $content parameter now.' - ); - $content = func_get_arg(1); - } - // Skip if content isn't injectable, or there is nothing to inject $tagsAvailable = preg_match('#css || $this->javascript || $this->customCSS || $this->customScript || $this->customHeadTags; @@ -1154,10 +1089,6 @@ class Requirements_Backend */ public function combineFiles($combinedFileName, $files, $options = []) { - if (is_string($options)) { - Deprecation::notice('4.0', 'Parameter media is deprecated. Use options array instead.'); - $options = ['media' => $options]; - } // Skip this combined files if already included if (isset($this->combinedFiles[$combinedFileName])) { return; @@ -1381,28 +1312,11 @@ class Requirements_Backend $combinedFileID = File::join_paths($this->getCombinedFilesFolder(), $combinedFile); // Send file combination request to the backend, with an optional callback to perform regeneration - $minify = $this->getMinifyCombinedFiles(); - if ($minify && !$this->minifier) { - throw new Exception( - sprintf( - <<getAssetHandler() ->getContentURL( $combinedFileID, - function () use ($fileList, $minify, $type) { + function () use ($fileList, $type) { // Physically combine all file content $combinedData = ''; foreach ($fileList as $file) { @@ -1415,11 +1329,6 @@ MESSAGE // resolve relative paths for css files $fileContent = $this->resolveCSSReferences($fileContent, $file); } - // Use configured minifier - if ($minify) { - $fileContent = $this->minifier->minify($fileContent, $type, $file); - } - if ($this->writeHeaderComment) { // Write a header comment for each file for easier identification and debugging. $combinedData .= "/****** FILE: $file *****/\n"; diff --git a/src/View/Requirements_Minifier.php b/src/View/Requirements_Minifier.php deleted file mode 100644 index cf93df033..000000000 --- a/src/View/Requirements_Minifier.php +++ /dev/null @@ -1,22 +0,0 @@ -uninherited('theme'); - }); - if ($theme) { - return [self::PUBLIC_THEME, $theme, self::DEFAULT_THEME]; - } - return $default; } - /** - * @param string $theme The "base theme" name (without underscores). - * @deprecated 4.0.1 Use SSViewer::set_themes() instead - */ - public static function set_theme($theme) - { - Deprecation::notice('4.0.1', 'Use SSViewer::set_themes() instead'); - self::set_themes([$theme, self::DEFAULT_THEME]); - } - /** * Traverses the given the given class context looking for candidate template names * which match each item in the class hierarchy. The resulting list of template candidates diff --git a/src/View/SSViewer_BasicIteratorSupport.php b/src/View/SSViewer_BasicIteratorSupport.php index 34b09b8bd..04dcaa8e8 100644 --- a/src/View/SSViewer_BasicIteratorSupport.php +++ b/src/View/SSViewer_BasicIteratorSupport.php @@ -2,8 +2,6 @@ namespace SilverStripe\View; -use SilverStripe\Dev\Deprecation; - /** * Defines an extra set of basic methods that can be used in templates * that are not defined on sub-classes of {@link ViewableData}. @@ -66,16 +64,6 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider return $this->iteratorPos == 0; } - /** - * @deprecated 4.12.0 Use IsFirst() instead - * @return bool - */ - public function First() - { - Deprecation::notice('4.12.0', 'Use IsFirst() instead'); - return $this->IsFirst(); - } - /** * Returns true if this object is the last in a set. * @@ -86,16 +74,6 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider return $this->iteratorPos == $this->iteratorTotalItems - 1; } - /** - * @deprecated 4.12.0 Use IsLast() instead - * @return bool - */ - public function Last() - { - Deprecation::notice('4.12.0', 'Use IsLast() instead'); - return $this->IsLast(); - } - /** * Returns 'first' or 'last' if this is the first or last object in the set. * diff --git a/src/View/Shortcodes/EmbedShortcodeProvider.php b/src/View/Shortcodes/EmbedShortcodeProvider.php index 7b844ba60..73f074297 100644 --- a/src/View/Shortcodes/EmbedShortcodeProvider.php +++ b/src/View/Shortcodes/EmbedShortcodeProvider.php @@ -16,7 +16,6 @@ use SilverStripe\View\HTML; use SilverStripe\View\Parsers\ShortcodeHandler; use SilverStripe\View\Parsers\ShortcodeParser; use SilverStripe\Control\Director; -use SilverStripe\Dev\Deprecation; use SilverStripe\View\Embed\EmbedContainer; /** @@ -156,32 +155,6 @@ class EmbedShortcodeProvider implements ShortcodeHandler return ''; } - /** - * @param Adapter $embed - * @param array $arguments Additional shortcode params - * @return string - * @deprecated 4.11.0 Use embeddableToHtml() instead - */ - public static function embedForTemplate($embed, $arguments) - { - Deprecation::notice('4.11.0', 'Use embeddableToHtml() instead'); - switch ($embed->getType()) { - case 'video': - case 'rich': - // Attempt to inherit width (but leave height auto) - if (empty($arguments['width']) && $embed->getWidth()) { - $arguments['width'] = $embed->getWidth(); - } - return static::videoEmbed($arguments, $embed->getCode()); - case 'link': - return static::linkEmbed($arguments, $embed->getUrl(), $embed->getTitle()); - case 'photo': - return static::photoEmbed($arguments, $embed->getUrl()); - default: - return null; - } - } - /** * Build video embed tag * diff --git a/src/View/ViewableData.php b/src/View/ViewableData.php index 19e27fa67..2440a5cac 100644 --- a/src/View/ViewableData.php +++ b/src/View/ViewableData.php @@ -14,9 +14,7 @@ use SilverStripe\Core\Convert; use SilverStripe\Core\Extensible; use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Core\Manifest\ModuleResourceLoader; use SilverStripe\Dev\Debug; -use SilverStripe\Dev\Deprecation; use SilverStripe\ORM\ArrayLib; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBHTMLText; @@ -609,35 +607,6 @@ class ViewableData implements IteratorAggregate return $this; } - /** - * Return the directory if the current active theme (relative to the site root). - * - * This method is useful for things such as accessing theme images from your template without hardcoding the theme - * page - e.g. . - * - * This method should only be used when a theme is currently active. However, it will fall over to the current - * project directory. - * - * @return string URL to the current theme - * @deprecated 4.0.1 Use ModuleResourceLoader::resourcePath() or ModuleResourceLoader::resourceURL() instead - */ - public function ThemeDir() - { - Deprecation::notice('4.0.1', 'Use ModuleResourceLoader::resourcePath() or ModuleResourceLoader::resourceURL() instead'); - $themes = SSViewer::get_themes(); - foreach ($themes as $theme) { - // Skip theme sets - if (strpos($theme ?? '', '$') === 0) { - continue; - } - // Map theme path to url - $themePath = ThemeResourceLoader::inst()->getPath($theme); - return ModuleResourceLoader::resourceURL($themePath); - } - - return project(); - } - /** * Get part of the current classes ancestry to be used as a CSS class. * diff --git a/src/conf/ConfigureFromEnv.php b/src/conf/ConfigureFromEnv.php deleted file mode 100644 index 6258c4e9b..000000000 --- a/src/conf/ConfigureFromEnv.php +++ /dev/null @@ -1,10 +0,0 @@ -uninherited('module_priority'); $sortedModules = []; - if ($i18nOrder) { - Deprecation::notice('5.0', sprintf( - '%s.module_priority is deprecated. Use %s.module_priority instead.', - __CLASS__, - ModuleManifest::class - )); - } - + foreach (ModuleLoader::inst()->getManifest()->getModules() as $module) { $sortedModules[$module->getName()] = $module->getPath(); }; diff --git a/src/i18n/Messages/Symfony/FlushInvalidatedResource.php b/src/i18n/Messages/Symfony/FlushInvalidatedResource.php index ebeeadf01..8ffa478f4 100644 --- a/src/i18n/Messages/Symfony/FlushInvalidatedResource.php +++ b/src/i18n/Messages/Symfony/FlushInvalidatedResource.php @@ -2,9 +2,7 @@ namespace SilverStripe\i18n\Messages\Symfony; -use SilverStripe\Dev\Deprecation; use SilverStripe\Core\Flushable; -use Symfony\Component\Config\Resource\DirectoryResource; use Symfony\Component\Config\Resource\SelfCheckingResourceInterface; /** @@ -14,7 +12,7 @@ use Symfony\Component\Config\Resource\SelfCheckingResourceInterface; * @link https://media.giphy.com/media/fRRD3T37DeY6Y/giphy.gif for use case * @see DirectoryResource */ -class FlushInvalidatedResource implements SelfCheckingResourceInterface, \Serializable, Flushable +class FlushInvalidatedResource implements SelfCheckingResourceInterface, Flushable { public function __toString() @@ -51,32 +49,6 @@ class FlushInvalidatedResource implements SelfCheckingResourceInterface, \Serial // no-op } - /** - * The __serialize() magic method will be automatically used instead of this - * - * @return string - * @deprecated 4.12.0 Use __serialize() instead - */ - public function serialize() - { - Deprecation::notice('4.12.0', 'Use __serialize() instead'); - return ''; - } - - /** - * The __unserialize() magic method will be automatically used instead of this almost all the time - * This method will be automatically used if existing serialized data was not saved as an associative array - * and the PHP version used in less than PHP 9.0 - * - * @param string $serialized - * @deprecated 4.12.0 Use __unserialize() instead - */ - public function unserialize($serialized) - { - Deprecation::notice('4.12.0', 'Use __unserialize() instead'); - // no-op - } - public static function flush() { // Mark canary as dirty diff --git a/src/i18n/TextCollection/i18nTextCollector.php b/src/i18n/TextCollection/i18nTextCollector.php index e7d5e95fb..34965546a 100644 --- a/src/i18n/TextCollection/i18nTextCollector.php +++ b/src/i18n/TextCollection/i18nTextCollector.php @@ -2,6 +2,7 @@ namespace SilverStripe\i18n\TextCollection; +use Exception; use LogicException; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Injector\Injectable; @@ -11,7 +12,6 @@ use SilverStripe\Core\Manifest\ModuleLoader; use SilverStripe\Dev\Debug; use SilverStripe\Control\Director; use ReflectionClass; -use SilverStripe\Dev\Deprecation; use SilverStripe\i18n\i18n; use SilverStripe\i18n\i18nEntityProvider; use SilverStripe\i18n\Messages\Reader; @@ -828,23 +828,10 @@ class i18nTextCollector /** @var i18nEntityProvider $obj */ $obj = singleton($class); $provided = $obj->provideI18nEntities(); - // Handle deprecated return syntax foreach ($provided as $key => $value) { // Detect non-associative result for any key - if (is_array($value) && $value === array_values($value ?? [])) { - Deprecation::notice('5.0', 'Non-associative translations from providei18nEntities is deprecated'); - $entity = array_filter([ - 'default' => $value[0], - 'comment' => isset($value[1]) ? $value[1] : null, - 'module' => isset($value[2]) ? $value[2] : null, - ]); - if (count($entity ?? []) === 1) { - $provided[$key] = $value[0]; - } elseif ($entity) { - $provided[$key] = $entity; - } else { - unset($provided[$key]); - } + if (is_array($value) && $value === array_values($value)) { + throw new Exception('Translations from provideI18nEntities() must be an associative array for key $key'); } } $entities = array_merge($entities, $provided); diff --git a/src/i18n/i18n.php b/src/i18n/i18n.php index b7357b802..8413abce2 100644 --- a/src/i18n/i18n.php +++ b/src/i18n/i18n.php @@ -2,9 +2,9 @@ namespace SilverStripe\i18n; +use Exception; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Dev\Deprecation; use SilverStripe\i18n\Data\Locales; use SilverStripe\i18n\Data\Sources; use SilverStripe\i18n\Messages\MessageProvider; @@ -205,23 +205,16 @@ class i18n implements TemplateGlobalProvider $result = static::getMessageProvider()->translate($entity, $default, $injection); } - // Sometimes default is omitted, so we don't know we have %s injection format until after translation if (!$default && !preg_match('/\{[\w\d]*\}/i', $result ?? '') && preg_match('/%[s,d]/', $result ?? '')) { - Deprecation::notice('5.0', 'sprintf style localisation is deprecated'); - if ($injection) { - $sprintfArgs = array_values($injection ?? []); - } - } elseif ($failUnlessSprintf) { + throw new Exception('sprintf style localisation cannot be used in translations - detected in $result'); + } + + if ($failUnlessSprintf) { // Note: After removing deprecated code, you can move this error up into the is-associative check // Neither default nor translated strings were %s substituted, and our array isn't associative throw new InvalidArgumentException('Injection must be an associative array'); } - // @deprecated (see above) - if ($sprintfArgs) { - return vsprintf($result ?? '', $sprintfArgs ?? []); - } - return $result; } diff --git a/tests/behat/src/CmsUiContext.php b/tests/behat/src/CmsUiContext.php index 62504e63b..beea59cdd 100644 --- a/tests/behat/src/CmsUiContext.php +++ b/tests/behat/src/CmsUiContext.php @@ -76,15 +76,6 @@ class CmsUiContext implements Context Assert::assertNotNull($cms_element, 'CMS not found'); } - /** - * @Then /^I should see a "([^"]*)" notice$/ - * @deprecated 4.7.0 Use `iShouldSeeAToast` instead - */ - public function iShouldSeeANotice($notice) - { - $this->getMainContext()->assertElementContains('.toast, .notice-wrap', $notice); - } - /** * @Then /^I should see a "(.+)" (\w+) toast$/ */ diff --git a/tests/php/Control/DirectorTest.php b/tests/php/Control/DirectorTest.php index 44c9e1980..85a0979b1 100644 --- a/tests/php/Control/DirectorTest.php +++ b/tests/php/Control/DirectorTest.php @@ -10,13 +10,11 @@ use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\Middleware\CanonicalURLMiddleware; use SilverStripe\Control\Middleware\RequestHandlerMiddlewareAdapter; use SilverStripe\Control\Middleware\TrustedProxyMiddleware; -use SilverStripe\Control\RequestProcessor; use SilverStripe\Control\Tests\DirectorTest\TestController; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Environment; use SilverStripe\Core\Kernel; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; /** @@ -855,46 +853,6 @@ class DirectorTest extends SapphireTest $this->assertEquals($request->getURL(true), $url); } - public function testRequestFilterInDirectorTest() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $filter = new DirectorTest\TestRequestFilter; - - $processor = new RequestProcessor([$filter]); - - $middlewares = Director::singleton()->getMiddlewares(); - $middlewares['RequestProcessorMiddleware'] = $processor; - Director::singleton()->setMiddlewares($middlewares); - - $response = Director::test('some-dummy-url'); - $this->assertEquals(404, $response->getStatusCode()); - - $this->assertEquals(1, $filter->preCalls); - $this->assertEquals(1, $filter->postCalls); - - $filter->failPost = true; - - $response = Director::test('some-dummy-url'); - $this->assertEquals(500, $response->getStatusCode()); - $this->assertEquals(_t(Director::class . '.REQUEST_ABORTED', 'Request aborted'), $response->getBody()); - - $this->assertEquals(2, $filter->preCalls); - $this->assertEquals(2, $filter->postCalls); - - $filter->failPre = true; - - $response = Director::test('some-dummy-url'); - $this->assertEquals(400, $response->getStatusCode()); - $this->assertEquals(_t(Director::class . '.INVALID_REQUEST', 'Invalid request'), $response->getBody()); - - $this->assertEquals(3, $filter->preCalls); - - // preCall 'true' will trigger an exception and prevent post call execution - $this->assertEquals(2, $filter->postCalls); - } - public function testGlobalMiddleware() { $middleware = new DirectorTest\TestMiddleware; diff --git a/tests/php/Control/DirectorTest/TestRequestFilter.php b/tests/php/Control/DirectorTest/TestRequestFilter.php index 01bff2e52..47e9115d2 100644 --- a/tests/php/Control/DirectorTest/TestRequestFilter.php +++ b/tests/php/Control/DirectorTest/TestRequestFilter.php @@ -4,10 +4,9 @@ namespace SilverStripe\Control\Tests\DirectorTest; use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPResponse; -use SilverStripe\Control\RequestFilter; use SilverStripe\Dev\TestOnly; -class TestRequestFilter implements RequestFilter, TestOnly +class TestRequestFilter implements TestOnly { public $preCalls = 0; public $postCalls = 0; diff --git a/tests/php/Control/Email/MailerSubscriberTest.php b/tests/php/Control/Email/MailerSubscriberTest.php index a3960a2a6..16c576700 100644 --- a/tests/php/Control/Email/MailerSubscriberTest.php +++ b/tests/php/Control/Email/MailerSubscriberTest.php @@ -44,7 +44,7 @@ class MailerSubscriberTest extends SapphireTest public function testSendAllEmailsTo(): void { - Email::config()->update('send_all_emails_to', 'to@example.com'); + Email::config()->merge('send_all_emails_to', ['to@example.com']); $email = $this->getEmail(); $email->send(); @@ -61,7 +61,7 @@ class MailerSubscriberTest extends SapphireTest public function testSendAllEmailsFrom(): void { - Email::config()->update('send_all_emails_from', 'from@example.com'); + Email::config()->merge('send_all_emails_from', ['from@example.com']); $email = $this->getEmail(); $email->send(); @@ -78,7 +78,7 @@ class MailerSubscriberTest extends SapphireTest public function testCCAllEmailsTo(): void { - Email::config()->update('cc_all_emails_to', 'cc@example.com'); + Email::config()->merge('cc_all_emails_to', ['cc@example.com']); $email = $this->getEmail(); $email->send(); @@ -89,7 +89,7 @@ class MailerSubscriberTest extends SapphireTest public function testBCCAllEmailsTo(): void { - Email::config()->update('bcc_all_emails_to', 'bcc@example.com'); + Email::config()->merge('bcc_all_emails_to', ['bcc@example.com']); $email = $this->getEmail(); $email->send(); diff --git a/tests/php/Control/HTTPRequestTest.php b/tests/php/Control/HTTPRequestTest.php index 8f39efbc2..93391c12c 100644 --- a/tests/php/Control/HTTPRequestTest.php +++ b/tests/php/Control/HTTPRequestTest.php @@ -6,7 +6,6 @@ use ReflectionMethod; use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\Middleware\TrustedProxyMiddleware; use SilverStripe\Control\Session; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; class HTTPRequestTest extends SapphireTest @@ -151,27 +150,6 @@ class HTTPRequestTest extends SapphireTest ]; } - /** - * @dataProvider detectMethodDataProvider - */ - public function testDetectMethod($realMethod, $post, $expected) - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $actual = HTTPRequest::detect_method($realMethod, $post); - $this->assertEquals($expected, $actual); - } - - public function testBadDetectMethod() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $this->expectException(\InvalidArgumentException::class); - HTTPRequest::detect_method('POST', ['_method' => 'Boom']); - } - public function setHttpMethodDataProvider() { return [ diff --git a/tests/php/Control/HTTPTest.php b/tests/php/Control/HTTPTest.php index b7ea02e9d..5f748771c 100644 --- a/tests/php/Control/HTTPTest.php +++ b/tests/php/Control/HTTPTest.php @@ -11,7 +11,6 @@ use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware; use SilverStripe\Control\Session; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\FunctionalTest; -use SilverStripe\Dev\Deprecation; /** * Tests the {@link HTTP} class @@ -114,89 +113,6 @@ class HTTPTest extends FunctionalTest $this->assertEmpty($v); } - public function testDeprecatedVaryHandling() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - /** @var Config */ - Config::modify()->set( - HTTP::class, - 'vary', - 'X-Foo' - ); - $response = new HTTPResponse('', 200); - $this->addCacheHeaders($response); - $header = $response->getHeader('Vary'); - $this->assertStringContainsString('X-Foo', $header); - } - - public function testDeprecatedCacheControlHandling() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - HTTPCacheControlMiddleware::singleton()->publicCache(); - - /** @var Config */ - Config::modify()->set( - HTTP::class, - 'cache_control', - [ - 'no-store' => true, - 'no-cache' => true, - ] - ); - $response = new HTTPResponse('', 200); - $this->addCacheHeaders($response); - $header = $response->getHeader('Cache-Control'); - $this->assertStringContainsString('no-store', $header); - $this->assertStringContainsString('no-cache', $header); - } - - public function testDeprecatedCacheControlHandlingOnMaxAge() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - HTTPCacheControlMiddleware::singleton()->publicCache(); - - /** @var Config */ - Config::modify()->set( - HTTP::class, - 'cache_control', - [ - // Needs to be separate from no-cache and no-store, - // since that would unset max-age - 'max-age' => 99, - ] - ); - $response = new HTTPResponse('', 200); - $this->addCacheHeaders($response); - $header = $response->getHeader('Cache-Control'); - $this->assertStringContainsString('max-age=99', $header); - } - - public function testDeprecatedCacheControlHandlingThrowsWithUnknownDirectives() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $this->expectException(\LogicException::class); - $this->expectExceptionMessageMatches('/Found unsupported legacy directives in HTTP\.cache_control: unknown/'); - /** @var Config */ - Config::modify()->set( - HTTP::class, - 'cache_control', - [ - 'no-store' => true, - 'unknown' => true, - ] - ); - $response = new HTTPResponse('', 200); - $this->addCacheHeaders($response); - } - /** * Tests {@link HTTP::getLinksIn()} */ diff --git a/tests/php/Core/Config/ConfigTest.php b/tests/php/Core/Config/ConfigTest.php index d55d7fd8e..8731fcae9 100644 --- a/tests/php/Core/Config/ConfigTest.php +++ b/tests/php/Core/Config/ConfigTest.php @@ -22,8 +22,8 @@ class ConfigTest extends SapphireTest $this->assertEquals(5, Config::inst()->get(ConfigTest\TestNest::class, 'bar')); // Test nested data can be updated - Config::modify()->merge(ConfigTest\TestNest::class, 'foo', 4); - $this->assertEquals(4, Config::inst()->get(ConfigTest\TestNest::class, 'foo')); + Config::modify()->merge(ConfigTest\TestNest::class, 'foo', [4]); + $this->assertEquals(4, Config::inst()->get(ConfigTest\TestNest::class, 'foo')[0]); $this->assertEquals(5, Config::inst()->get(ConfigTest\TestNest::class, 'bar')); // Test unnest restores data @@ -171,31 +171,31 @@ class ConfigTest extends SapphireTest { // Booleans $this->assertTrue(Config::inst()->get(ConfigTest\First::class, 'bool')); - Config::modify()->merge(ConfigTest\First::class, 'bool', false); - $this->assertFalse(Config::inst()->get(ConfigTest\First::class, 'bool')); - Config::modify()->merge(ConfigTest\First::class, 'bool', true); - $this->assertTrue(Config::inst()->get(ConfigTest\First::class, 'bool')); + Config::modify()->merge(ConfigTest\First::class, 'bool', [false]); + $this->assertFalse(Config::inst()->get(ConfigTest\First::class, 'bool')[0]); + Config::modify()->merge(ConfigTest\First::class, 'bool', [true]); + $this->assertTrue(Config::inst()->get(ConfigTest\First::class, 'bool')[1]); // Integers $this->assertEquals(42, Config::inst()->get(ConfigTest\First::class, 'int')); - Config::modify()->merge(ConfigTest\First::class, 'int', 0); - $this->assertEquals(0, Config::inst()->get(ConfigTest\First::class, 'int')); - Config::modify()->merge(ConfigTest\First::class, 'int', 42); - $this->assertEquals(42, Config::inst()->get(ConfigTest\First::class, 'int')); + Config::modify()->merge(ConfigTest\First::class, 'int', [0]); + $this->assertEquals(0, Config::inst()->get(ConfigTest\First::class, 'int')[0]); + Config::modify()->merge(ConfigTest\First::class, 'int', [42]); + $this->assertEquals(42, Config::inst()->get(ConfigTest\First::class, 'int')[1]); // Strings $this->assertEquals('value', Config::inst()->get(ConfigTest\First::class, 'string')); - Config::modify()->merge(ConfigTest\First::class, 'string', ''); - $this->assertEquals('', Config::inst()->get(ConfigTest\First::class, 'string')); - Config::modify()->merge(ConfigTest\First::class, 'string', 'value'); - $this->assertEquals('value', Config::inst()->get(ConfigTest\First::class, 'string')); + Config::modify()->merge(ConfigTest\First::class, 'string', ['']); + $this->assertEquals('', Config::inst()->get(ConfigTest\First::class, 'string')[0]); + Config::modify()->merge(ConfigTest\First::class, 'string', ['value']); + $this->assertEquals('value', Config::inst()->get(ConfigTest\First::class, 'string')[1]); // Nulls $this->assertEquals('value', Config::inst()->get(ConfigTest\First::class, 'nullable')); - Config::modify()->merge(ConfigTest\First::class, 'nullable', null); - $this->assertNull(Config::inst()->get(ConfigTest\First::class, 'nullable')); - Config::modify()->merge(ConfigTest\First::class, 'nullable', 'value'); - $this->assertEquals('value', Config::inst()->get(ConfigTest\First::class, 'nullable')); + Config::modify()->merge(ConfigTest\First::class, 'nullable', [null]); + $this->assertNull(Config::inst()->get(ConfigTest\First::class, 'nullable')[0]); + Config::modify()->merge(ConfigTest\First::class, 'nullable', ['value']); + $this->assertEquals('value', Config::inst()->get(ConfigTest\First::class, 'nullable')[1]); } public function testSetsFalsyDefaults() diff --git a/tests/php/Core/ConvertTest.php b/tests/php/Core/ConvertTest.php index 1c846f974..243694bee 100644 --- a/tests/php/Core/ConvertTest.php +++ b/tests/php/Core/ConvertTest.php @@ -5,7 +5,6 @@ namespace SilverStripe\Core\Tests; use Exception; use InvalidArgumentException; use SilverStripe\Core\Convert; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; use SilverStripe\View\Parsers\URLSegmentFilter; use stdClass; @@ -213,60 +212,6 @@ PHP $this->assertEquals('This is some normal text.', Convert::xml2raw($val2), 'Normal text is not escaped'); } - /** - * Tests {@link Convert::xml2raw()} - */ - public function testArray2JSON() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $val = [ - 'Joe' => 'Bloggs', - 'Tom' => 'Jones', - 'My' => [ - 'Complicated' => 'Structure' - ] - ]; - $encoded = Convert::array2json($val); - $this->assertEquals( - '{"Joe":"Bloggs","Tom":"Jones","My":{"Complicated":"Structure"}}', - $encoded, - 'Array is encoded in JSON' - ); - } - - /** - * Tests {@link Convert::json2array()} - */ - public function testJSON2Array() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $val = '{"Joe":"Bloggs","Tom":"Jones","My":{"Complicated":"Structure"}}'; - $decoded = Convert::json2array($val); - $this->assertEquals(3, count($decoded ?? []), '3 items in the decoded array'); - $this->assertContains('Bloggs', $decoded, 'Contains "Bloggs" value in decoded array'); - $this->assertContains('Jones', $decoded, 'Contains "Jones" value in decoded array'); - $this->assertStringContainsString('Structure', $decoded['My']['Complicated']); - } - - /** - * Tests {@link Convert::testJSON2Obj()} - */ - public function testJSON2Obj() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $val = '{"Joe":"Bloggs","Tom":"Jones","My":{"Complicated":"Structure"}}'; - $obj = Convert::json2obj($val); - $this->assertEquals('Bloggs', $obj->Joe); - $this->assertEquals('Jones', $obj->Tom); - $this->assertEquals('Structure', $obj->My->Complicated); - } - /** * Tests {@link Convert::testRaw2URL()} * @@ -364,143 +309,6 @@ PHP ); } - /** - * Tests {@link Convert::raw2json()} - */ - public function testRaw2JSON() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - - // Test object - $input = new stdClass(); - $input->Title = 'My Object'; - $input->Content = '

Data

'; - $this->assertEquals( - '{"Title":"My Object","Content":"

Data<\/p>"}', - Convert::raw2json($input) - ); - - // Array - $array = ['One' => 'Apple', 'Two' => 'Banana']; - $this->assertEquals( - '{"One":"Apple","Two":"Banana"}', - Convert::raw2json($array) - ); - - // String value with already encoded data. Result should be quoted. - $value = '{"Left": "Value"}'; - $this->assertEquals( - '"{\\"Left\\": \\"Value\\"}"', - Convert::raw2json($value) - ); - } - - /** - * Test that a context bitmask can be passed through to the json_encode method in {@link Convert::raw2json()} - * and in {@link Convert::array2json()} - */ - public function testRaw2JsonWithContext() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $data = ['foo' => 'b"ar']; - $expected = '{"foo":"b\u0022ar"}'; - $result = Convert::raw2json($data, JSON_HEX_QUOT); - $this->assertSame($expected, $result); - $wrapperResult = Convert::array2json($data, JSON_HEX_QUOT); - $this->assertSame($expected, $wrapperResult); - } - - /** - * Tests {@link Convert::xml2array()} - */ - public function testXML2Array() - { - - $inputXML = << - -]> - - My para - Ampersand & is retained and not double encoded - -XML - ; - $expected = [ - 'result' => [ - 'My para', - 'Ampersand & is retained and not double encoded' - ] - ]; - $actual = Convert::xml2array($inputXML, false); - $this->assertEquals($expected, $actual); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('XML Doctype parsing disabled'); - Convert::xml2array($inputXML, true); - } - - /** - * Tests {@link Convert::xml2array()} if an exception the contains a reference to a removed - */ - public function testXML2ArrayEntityException() - { - $inputXML = << - - ]> - - Now include &long; lots of times to expand the in-memory size of this XML structure - &long;&long;&long; - - XML; - $this->expectException(Exception::class); - $this->expectExceptionMessage('String could not be parsed as XML'); - Convert::xml2array($inputXML); - } - - /** - * Tests {@link Convert::xml2array()} if an exception the contains a reference to a multiple removed - */ - public function testXML2ArrayMultipleEntitiesException() - { - $inputXML = << - ]> - - Now include &long; and &short; lots of times - &long;&long;&long;&short;&short;&short; - - XML; - $this->expectException(Exception::class); - $this->expectExceptionMessage('String could not be parsed as XML'); - Convert::xml2array($inputXML); - } - - /** - * Tests {@link Convert::xml2array()} if there is a malicious present - */ - public function testXML2ArrayMaliciousEntityException() - { - $inputXML = << - ENTITY ext SYSTEM "http://evil.com"> - ]> - - Evil document - - XML; - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Malicious XML entity detected'); - Convert::xml2array($inputXML); - } - /** * Tests {@link Convert::base64url_encode()} and {@link Convert::base64url_decode()} */ diff --git a/tests/php/Core/Injector/InjectorTest.php b/tests/php/Core/Injector/InjectorTest.php index 85aa7a3ff..00ef77333 100644 --- a/tests/php/Core/Injector/InjectorTest.php +++ b/tests/php/Core/Injector/InjectorTest.php @@ -759,7 +759,7 @@ class InjectorTest extends SapphireTest 'locator' => SilverStripeServiceConfigurationLocator::class ] ); - Config::modify()->merge( + Config::modify()->set( Injector::class, MyChildClass::class, '%$' . MyParentClass::class diff --git a/tests/php/Core/ObjectTest.php b/tests/php/Core/ObjectTest.php index 66562315a..5882eb0c1 100644 --- a/tests/php/Core/ObjectTest.php +++ b/tests/php/Core/ObjectTest.php @@ -19,7 +19,6 @@ use SilverStripe\Core\Tests\ObjectTest\ExtensionTest3; use SilverStripe\Core\Tests\ObjectTest\MyObject; use SilverStripe\Core\Tests\ObjectTest\MySubObject; use SilverStripe\Core\Tests\ObjectTest\TestExtension; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; use SilverStripe\Versioned\Versioned; @@ -109,62 +108,6 @@ class ObjectTest extends SapphireTest ); } - public function testStaticGetterMethod() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $obj = singleton(MyObject::class); - $this->assertEquals( - 'MyObject', - $obj->stat('mystaticProperty'), - 'Uninherited statics through stat() on a singleton behave the same as built-in PHP statics' - ); - } - - public function testStaticInheritanceGetters() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $subObj = singleton(MyObject::class); - $this->assertEquals( - $subObj->stat('mystaticProperty'), - 'MyObject', - 'Statics defined on a parent class are available through stat() on a subclass' - ); - } - - public function testStaticSettingOnSingletons() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $singleton1 = singleton(MyObject::class); - $singleton2 = singleton(MyObject::class); - $singleton1->set_stat('mystaticProperty', 'changed'); - $this->assertEquals( - $singleton2->stat('mystaticProperty'), - 'changed', - 'Statics setting is populated throughout singletons without explicitly clearing cache' - ); - } - - public function testStaticSettingOnInstances() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $instance1 = new ObjectTest\MyObject(); - $instance2 = new ObjectTest\MyObject(); - $instance1->set_stat('mystaticProperty', 'changed'); - $this->assertEquals( - $instance2->stat('mystaticProperty'), - 'changed', - 'Statics setting through set_stat() is populated throughout instances without explicitly clearing cache' - ); - } - /** * Tests that {@link Object::create()} correctly passes all arguments to the new object */ diff --git a/tests/php/Dev/CSVParserTest.php b/tests/php/Dev/CSVParserTest.php deleted file mode 100644 index 1ff17fe16..000000000 --- a/tests/php/Dev/CSVParserTest.php +++ /dev/null @@ -1,159 +0,0 @@ -csvPath = __DIR__ . '/CsvBulkLoaderTest/csv/'; - } - - public function testParsingWithHeaders() - { - /* By default, a CSV file will be interpreted as having headers */ - $csv = new CSVParser($this->csvPath . 'PlayersWithHeader.csv'); - - $firstNames = $birthdays = $biographies = $registered = []; - foreach ($csv as $record) { - /* Each row in the CSV file will be keyed with the header row */ - $this->assertEquals( - ['FirstName','Biography','Birthday','IsRegistered'], - array_keys($record ?? []) - ); - $firstNames[] = $record['FirstName']; - $biographies[] = $record['Biography']; - $birthdays[] = $record['Birthday']; - $registered[] = $record['IsRegistered']; - } - - $this->assertEquals( - ['John','Jane','Jamie','Järg','Jacob'], - $firstNames - ); - - $this->assertEquals( - [ - "He's a good guy", - "She is awesome." - . PHP_EOL - . "So awesome that she gets multiple rows and \"escaped\" strings in her biography", - "Pretty old, with an escaped comma", - "Unicode FTW", - "Likes leading tabs in his biography", - ], - $biographies - ); - $this->assertEquals([ - "1988-01-31", - "1982-01-31", - "1882-01-31", - "1982-06-30", - "2000-04-30", - ], $birthdays); - $this->assertEquals( - ['1', '0', '1', '1', '0'], - $registered - ); - } - - public function testParsingWithHeadersAndColumnMap() - { - /* By default, a CSV file will be interpreted as having headers */ - $csv = new CSVParser($this->csvPath . 'PlayersWithHeader.csv'); - - /* We can set up column remapping. The keys are case-insensitive. */ - $csv->mapColumns([ - 'FirstName' => '__fn', - 'bIoGrApHy' => '__BG', - ]); - - $firstNames = $birthdays = $biographies = $registered = []; - foreach ($csv as $record) { - /* Each row in the CSV file will be keyed with the renamed columns. Any unmapped column names will be - * left as-is. */ - $this->assertEquals(['__fn','__BG','Birthday','IsRegistered'], array_keys($record ?? [])); - $firstNames[] = $record['__fn']; - $biographies[] = $record['__BG']; - $birthdays[] = $record['Birthday']; - $registered[] = $record['IsRegistered']; - } - - $this->assertEquals(['John','Jane','Jamie','Järg','Jacob'], $firstNames); - $this->assertEquals( - [ - "He's a good guy", - "She is awesome." - . PHP_EOL - . "So awesome that she gets multiple rows and \"escaped\" strings in her biography", - "Pretty old, with an escaped comma", - "Unicode FTW", - "Likes leading tabs in his biography", - ], - $biographies - ); - $this->assertEquals([ - "1988-01-31", - "1982-01-31", - "1882-01-31", - "1982-06-30", - "2000-04-30", - ], $birthdays); - $this->assertEquals(['1', '0', '1', '1', '0'], $registered); - } - - public function testParsingWithExplicitHeaderRow() - { - /* If your CSV file doesn't have a header row */ - $csv = new CSVParser($this->csvPath . 'PlayersWithHeader.csv'); - - $csv->provideHeaderRow(['__fn','__bio','__bd','__reg']); - - $firstNames = $birthdays = $biographies = $registered = []; - foreach ($csv as $record) { - /* Each row in the CSV file will be keyed with the header row that you gave */ - $this->assertEquals(['__fn','__bio','__bd','__reg'], array_keys($record ?? [])); - $firstNames[] = $record['__fn']; - $biographies[] = $record['__bio']; - $birthdays[] = $record['__bd']; - $registered[] = $record['__reg']; - } - - /* And the first row will be returned in the data */ - $this->assertEquals(['FirstName','John','Jane','Jamie','Järg','Jacob'], $firstNames); - $this->assertEquals( - [ - 'Biography', - "He's a good guy", - "She is awesome." - . PHP_EOL - . "So awesome that she gets multiple rows and \"escaped\" strings in her biography", - "Pretty old, with an escaped comma", - "Unicode FTW", - "Likes leading tabs in his biography" - ], - $biographies - ); - $this->assertEquals([ - "Birthday", - "1988-01-31", - "1982-01-31", - "1882-01-31", - "1982-06-30", - "2000-04-30", - ], $birthdays); - $this->assertEquals(['IsRegistered', '1', '0', '1', '1', '0'], $registered); - } -} diff --git a/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php b/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php index db70ddddb..357c9d765 100644 --- a/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php +++ b/tests/php/Forms/GridField/GridFieldFilterHeaderTest.php @@ -73,18 +73,6 @@ class GridFieldFilterHeaderTest extends SapphireTest // Check that the output is the new search field $this->assertStringContainsString('

assertStringContainsString('Open search and filter', $htmlFragment['buttons-before-right']); - - $this->gridField->getConfig()->removeComponentsByType(GridFieldFilterHeader::class); - $this->gridField->getConfig()->addComponent(new GridFieldFilterHeader(true)); - $this->component = $this->gridField->getConfig()->getComponentByType(GridFieldFilterHeader::class); - $htmlFragment = $this->component->getHTMLFragments($this->gridField); - - // Check that the output is the legacy filter header - $this->assertStringContainsString( - '', - $htmlFragment['header'] - ); - $this->assertFalse(array_key_exists('buttons-before-right', $htmlFragment ?? [])); } public function testSearchFieldSchema() diff --git a/tests/php/Logging/MonologErrorHandlerTest.php b/tests/php/Logging/MonologErrorHandlerTest.php index b31251e91..a3a13d1c6 100644 --- a/tests/php/Logging/MonologErrorHandlerTest.php +++ b/tests/php/Logging/MonologErrorHandlerTest.php @@ -4,7 +4,6 @@ namespace SilverStripe\Logging\Tests; use InvalidArgumentException; use Psr\Log\LoggerInterface; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; use SilverStripe\Logging\MonologErrorHandler; @@ -27,11 +26,6 @@ class MonologErrorHandlerTest extends SapphireTest $handler->pushLogger($logger)->pushLogger($logger); $this->assertCount(2, $handler->getLoggers(), 'Loggers are pushed to the stack'); - if (!Deprecation::isEnabled()) { - $handler->setLogger($logger); - $this->assertCount(1, $handler->getLoggers(), 'setLogger resets stack and pushes'); - } - $handler->setLoggers([]); $this->assertCount(0, $handler->getLoggers(), 'setLoggers overwrites all configured loggers'); } diff --git a/tests/php/ORM/ArrayListTest.php b/tests/php/ORM/ArrayListTest.php index 9cb606030..0a8040c19 100644 --- a/tests/php/ORM/ArrayListTest.php +++ b/tests/php/ORM/ArrayListTest.php @@ -2,7 +2,6 @@ namespace SilverStripe\ORM\Tests; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataObject; diff --git a/tests/php/ORM/DatabaseTest.php b/tests/php/ORM/DatabaseTest.php index 706d25db3..6c527bace 100644 --- a/tests/php/ORM/DatabaseTest.php +++ b/tests/php/ORM/DatabaseTest.php @@ -270,7 +270,7 @@ class DatabaseTest extends SapphireTest $this->assertIsString($record['Created'], 'DBDatetime fields should be string (non-prepared)'); // Booleans selected directly are ints - $result = DB::query('SELECT TRUE')->first(); + $result = DB::query('SELECT TRUE')->record(); $this->assertIsInt(reset($result)); } diff --git a/tests/php/Security/BasicAuthTest/ControllerNotSecured.php b/tests/php/Security/BasicAuthTest/ControllerNotSecured.php index a4f1bb39b..41c6e6ba2 100644 --- a/tests/php/Security/BasicAuthTest/ControllerNotSecured.php +++ b/tests/php/Security/BasicAuthTest/ControllerNotSecured.php @@ -12,14 +12,6 @@ class ControllerNotSecured extends Controller implements TestOnly { protected $template = 'BlankPage'; - /** - * Disable legacy global-enable - * - * @deprecated 4.0.0:5.0.0 - * @var bool - */ - protected $basicAuthEnabled = false; - public function Link($action = null) { return Controller::join_links('BasicAuthTest_ControllerNotSecured', $action, '/'); diff --git a/tests/php/Security/RandomGeneratorTest.php b/tests/php/Security/RandomGeneratorTest.php index 6f7d2dea1..1f98105f2 100644 --- a/tests/php/Security/RandomGeneratorTest.php +++ b/tests/php/Security/RandomGeneratorTest.php @@ -3,7 +3,6 @@ namespace SilverStripe\Security\Tests; use SilverStripe\Security\RandomGenerator; -use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; /** @@ -12,16 +11,6 @@ use SilverStripe\Dev\SapphireTest; class RandomGeneratorTest extends SapphireTest { - public function testGenerateEntropy() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $r = new RandomGenerator(); - $this->assertNotNull($r->generateEntropy()); - $this->assertNotEquals($r->generateEntropy(), $r->generateEntropy()); - } - public function testGenerateHash() { $r = new RandomGenerator(); diff --git a/tests/php/View/RequirementsTest.php b/tests/php/View/RequirementsTest.php index ae9d19558..be8c02de0 100644 --- a/tests/php/View/RequirementsTest.php +++ b/tests/php/View/RequirementsTest.php @@ -302,7 +302,6 @@ class RequirementsTest extends SapphireTest $backend->clear(); $backend->clearCombinedFiles(); $backend->setCombinedFilesFolder('_combinedfiles'); - $backend->setMinifyCombinedFiles(false); $backend->setCombinedFilesEnabled(true); Requirements::flush(); } diff --git a/tests/php/View/SSViewerTest.php b/tests/php/View/SSViewerTest.php index fd0cc0056..1eca6e36e 100644 --- a/tests/php/View/SSViewerTest.php +++ b/tests/php/View/SSViewerTest.php @@ -25,7 +25,6 @@ use SilverStripe\Security\SecurityToken; use SilverStripe\View\ArrayData; use SilverStripe\View\Requirements; use SilverStripe\View\Requirements_Backend; -use SilverStripe\View\Requirements_Minifier; use SilverStripe\View\SSTemplateParseException; use SilverStripe\View\SSTemplateParser; use SilverStripe\View\SSViewer; @@ -34,7 +33,6 @@ use SilverStripe\View\Tests\SSViewerTest\SSViewerTestModel; use SilverStripe\View\Tests\SSViewerTest\SSViewerTestModelController; use SilverStripe\View\Tests\SSViewerTest\TestViewableData; use SilverStripe\View\ViewableData; -use SilverStripe\Dev\Deprecation; /** * @skipUpgrade @@ -69,24 +67,6 @@ class SSViewerTest extends SapphireTest parent::tearDown(); } - /** - * Tests for {@link Config::inst()->get('SSViewer', 'theme')} for different behaviour - * of user defined themes via {@link SiteConfig} and default theme - * when no user themes are defined. - */ - public function testCurrentTheme() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - SSViewer::config()->set('theme', 'mytheme'); - $this->assertEquals( - 'mytheme', - SSViewer::config()->uninherited('theme'), - 'Current theme is the default - user has not defined one' - ); - } - /** * Tests for themes helper functions, ensuring they behave as defined in the RFC at * https://github.com/silverstripe/silverstripe-framework/issues/5604 @@ -277,47 +257,6 @@ class SSViewerTest extends SapphireTest $this->assertStringContainsString($jsFileContents, $combinedTestFileContents); } - public function testRequirementsMinification() - { - /** @var Requirements_Backend $testBackend */ - $testBackend = Injector::inst()->create(Requirements_Backend::class); - $testBackend->setSuffixRequirements(false); - $testBackend->setMinifyCombinedFiles(true); - $testBackend->setCombinedFilesEnabled(true); - - $testFile = $this->getCurrentRelativePath() . '/SSViewerTest/javascript/RequirementsTest_a.js'; - $testFileContent = file_get_contents($testFile ?? ''); - - $mockMinifier = $this->getMockBuilder(Requirements_Minifier::class) - ->setMethods(['minify']) - ->getMock(); - - $mockMinifier->expects($this->once()) - ->method('minify') - ->with( - $testFileContent, - 'js', - $testFile - ); - $testBackend->setMinifier($mockMinifier); - $testBackend->combineFiles('testRequirementsMinified.js', [$testFile]); - $testBackend->processCombinedFiles(); - - $testBackend->setMinifyCombinedFiles(false); - $mockMinifier->expects($this->never()) - ->method('minify'); - $testBackend->processCombinedFiles(); - - $this->expectException(Exception::class); - $this->expectExceptionMessageMatches('/^Cannot minify files without a minification service defined./'); - - $testBackend->setMinifyCombinedFiles(true); - $testBackend->setMinifier(null); - $testBackend->processCombinedFiles(); - } - - - public function testComments() { $input = <<testCastingHelpers()} for more tests related to casting and ViewableData behaviour, @@ -206,22 +205,4 @@ class ViewableDataTest extends SapphireTest $this->assertSame($failover, $container->getFailover(), 'getFailover() returned a different object'); $this->assertFalse($container->hasMethod('testMethod'), 'testMethod() incorrectly reported as existing'); } - - public function testThemeDir() - { - if (Deprecation::isEnabled()) { - $this->markTestSkipped('Test calls deprecated code'); - } - $themes = [ - "silverstripe/framework:/tests/php/View/ViewableDataTest/testtheme", - SSViewer::DEFAULT_THEME - ]; - SSViewer::set_themes($themes); - - $data = new ViewableData(); - $this->assertStringContainsString( - 'tests/php/View/ViewableDataTest/testtheme', - $data->ThemeDir() - ); - } }