From 4e9c74243dd9ac11510e77628f59c0135a2a7ddb Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 7 Feb 2023 11:56:04 +1300 Subject: [PATCH 01/11] API Deprecate code --- src/Control/Director.php | 2 + src/Control/Email/Email.php | 18 +++++-- src/Control/HTTP.php | 2 + src/Core/BaseKernel.php | 6 ++- src/Core/CustomMethods.php | 10 +++- src/Core/Extensible.php | 5 +- src/Dev/Tasks/MigrateFileTask.php | 8 ++- src/Dev/TestMailer.php | 8 ++- src/ORM/Connect/MySQLQuery.php | 30 ++++++++--- src/ORM/Connect/MySQLStatement.php | 25 ++++++--- src/ORM/Connect/PDOConnector.php | 13 +++++ src/ORM/Connect/PDOQuery.php | 12 ++++- src/ORM/Connect/PDOStatementHandle.php | 10 ++++ src/ORM/Connect/Query.php | 72 ++++++++++++++++++-------- src/ORM/DataList.php | 5 ++ src/ORM/Map_Iterator.php | 10 ++++ 16 files changed, 190 insertions(+), 46 deletions(-) diff --git a/src/Control/Director.php b/src/Control/Director.php index 880561253..ca26754d9 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -73,6 +73,7 @@ class Director implements TemplateGlobalProvider /** * @config * @var string + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ private static $alternate_base_folder; @@ -82,6 +83,7 @@ class Director implements TemplateGlobalProvider * * @config * @var bool|null + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ private static $alternate_public_dir = null; diff --git a/src/Control/Email/Email.php b/src/Control/Email/Email.php index 766bf8f7c..6866331b3 100644 --- a/src/Control/Email/Email.php +++ b/src/Control/Email/Email.php @@ -115,7 +115,9 @@ class Email extends ViewableData */ public static function getSendAllEmailsTo() { - return static::mergeConfiguredEmails('send_all_emails_to', 'SS_SEND_ALL_EMAILS_TO'); + return Deprecation::withNoReplacement(function () { + return static::mergeConfiguredEmails('send_all_emails_to', 'SS_SEND_ALL_EMAILS_TO'); + }); } /** @@ -125,7 +127,9 @@ class Email extends ViewableData */ public static function getCCAllEmailsTo() { - return static::mergeConfiguredEmails('cc_all_emails_to', 'SS_CC_ALL_EMAILS_TO'); + return Deprecation::withNoReplacement(function () { + return static::mergeConfiguredEmails('cc_all_emails_to', 'SS_CC_ALL_EMAILS_TO'); + }); } /** @@ -135,7 +139,9 @@ class Email extends ViewableData */ public static function getBCCAllEmailsTo() { - return static::mergeConfiguredEmails('bcc_all_emails_to', 'SS_BCC_ALL_EMAILS_TO'); + return Deprecation::withNoReplacement(function () { + return static::mergeConfiguredEmails('bcc_all_emails_to', 'SS_BCC_ALL_EMAILS_TO'); + }); } /** @@ -145,7 +151,9 @@ class Email extends ViewableData */ public static function getSendAllEmailsFrom() { - return static::mergeConfiguredEmails('send_all_emails_from', 'SS_SEND_ALL_EMAILS_FROM'); + return Deprecation::withNoReplacement(function () { + return static::mergeConfiguredEmails('send_all_emails_from', 'SS_SEND_ALL_EMAILS_FROM'); + }); } /** @@ -154,9 +162,11 @@ class Email extends ViewableData * @param string $config Config key * @param string $env Env variable key * @return array Array of email addresses + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ protected static function mergeConfiguredEmails($config, $env) { + Deprecation::notice('4.13.0', 'Will be removed without equivalent functionality to replace it'); // Normalise config list $normalised = []; $source = (array)static::config()->get($config); diff --git a/src/Control/HTTP.php b/src/Control/HTTP.php index cce77aec4..ca07fc57f 100644 --- a/src/Control/HTTP.php +++ b/src/Control/HTTP.php @@ -576,9 +576,11 @@ class HTTP * Return static variable cache_age in second * * @return int + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ public static function get_cache_age() { + Deprecation::notice('4.13.0', 'Will be removed without equivalent functionality to replace it'); return self::$cache_age; } } diff --git a/src/Core/BaseKernel.php b/src/Core/BaseKernel.php index 3706f94d6..fd256b0a0 100644 --- a/src/Core/BaseKernel.php +++ b/src/Core/BaseKernel.php @@ -276,7 +276,9 @@ abstract class BaseKernel implements Kernel } // Check saved session - $env = $this->sessionEnvironment(); + $env = Deprecation::withNoReplacement(function () { + return $this->sessionEnvironment(); + }); if ($env) { return $env; } @@ -293,9 +295,11 @@ abstract class BaseKernel implements Kernel * Check or update any temporary environment specified in the session. * * @return null|string + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ protected function sessionEnvironment() { + Deprecation::notice('4.13.0', 'Will be removed without equivalent functionality to replace it.'); if (!$this->booted) { // session is not initialyzed yet, neither is manifest return null; diff --git a/src/Core/CustomMethods.php b/src/Core/CustomMethods.php index ee6ea63ef..9f9c4c9ee 100644 --- a/src/Core/CustomMethods.php +++ b/src/Core/CustomMethods.php @@ -193,9 +193,11 @@ trait CustomMethods /** * @param object $extension * @return array + * @deprecated 4.13.0 Will be replaced by findMethodsFrom() in CMS 5 */ protected function findMethodsFromExtension($extension) { + Deprecation::notice('4.13.0', 'Will be replaced by findMethodsFrom() in CMS 5'); if (method_exists($extension, 'allMethodNames')) { if ($extension instanceof Extension) { try { @@ -236,7 +238,9 @@ trait CustomMethods ); } - $methods = $this->findMethodsFromExtension($extension); + $methods = Deprecation::withNoReplacement(function () use ($extension) { + return $this->findMethodsFromExtension($extension); + }); if ($methods) { if ($extension instanceof Extension) { Deprecation::notice( @@ -279,7 +283,9 @@ trait CustomMethods ); } - $methods = $this->findMethodsFromExtension($extension); + $methods = Deprecation::withNoReplacement(function () use ($extension) { + return $this->findMethodsFromExtension($extension); + }); if ($methods) { foreach ($methods as $method) { if (!isset(self::$extra_methods[$class][$method])) { diff --git a/src/Core/Extensible.php b/src/Core/Extensible.php index f041caf4a..3cd80b9e8 100644 --- a/src/Core/Extensible.php +++ b/src/Core/Extensible.php @@ -131,7 +131,10 @@ trait Extensible { $extensions = $this->getExtensionInstances(); foreach ($extensions as $extensionClass => $extensionInstance) { - foreach ($this->findMethodsFromExtension($extensionInstance) as $method) { + $methods = Deprecation::withNoReplacement(function () use ($extensionInstance) { + return $this->findMethodsFromExtension($extensionInstance); + }); + foreach ($methods as $method) { $this->addCallbackMethod($method, function ($inst, $args) use ($method, $extensionClass) { /** @var Extensible $inst */ $extension = $inst->getExtensionInstance($extensionClass); diff --git a/src/Dev/Tasks/MigrateFileTask.php b/src/Dev/Tasks/MigrateFileTask.php index 797e58ec3..be579245d 100644 --- a/src/Dev/Tasks/MigrateFileTask.php +++ b/src/Dev/Tasks/MigrateFileTask.php @@ -57,7 +57,13 @@ class MigrateFileTask extends BuildTask public function __construct() { - Deprecation::notice('4.12.0', 'Will be removed without equivalent functionality to replace it', Deprecation::SCOPE_CLASS); + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '4.13.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + }); parent::__construct(); } diff --git a/src/Dev/TestMailer.php b/src/Dev/TestMailer.php index 44627e62c..e9363121a 100644 --- a/src/Dev/TestMailer.php +++ b/src/Dev/TestMailer.php @@ -4,11 +4,13 @@ namespace SilverStripe\Dev; use SilverStripe\Control\Email\Mailer; use Swift_Attachment; +use SilverStripe\Dev\Deprecation; class TestMailer implements Mailer { /** * @var array + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ protected $emailsSent = []; @@ -58,7 +60,9 @@ class TestMailer implements Mailer $serialised['HtmlContent'] = $htmlContent; } - $this->saveEmail($serialised); + Deprecation::withNoReplacement(function () use ($serialised) { + $this->saveEmail($serialised); + }); return true; } @@ -67,9 +71,11 @@ class TestMailer implements Mailer * Save a single email to the log * * @param array $data A map of information about the email + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ protected function saveEmail($data) { + Deprecation::notice('4.13.0', 'Will be removed without equivalent functionality to replace it'); $this->emailsSent[] = $data; } diff --git a/src/ORM/Connect/MySQLQuery.php b/src/ORM/Connect/MySQLQuery.php index c81138643..fece476aa 100644 --- a/src/ORM/Connect/MySQLQuery.php +++ b/src/ORM/Connect/MySQLQuery.php @@ -2,6 +2,8 @@ namespace SilverStripe\ORM\Connect; +use SilverStripe\Dev\Deprecation; + /** * A result-set from a MySQL database (using MySQLiConnector) * Note that this class is only used for the results of non-prepared statements @@ -45,16 +47,22 @@ class MySQLQuery extends Query } } + /** + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 + */ public function seek($row) { - if (is_object($this->handle)) { - // Fix for https://github.com/silverstripe/silverstripe-framework/issues/9097 without breaking the seek() API - $this->handle->data_seek($row); - $result = $this->nextRecord(); - $this->handle->data_seek($row); - return $result; - } - return null; + return Deprecation::withNoReplacement(function () use ($row) { + Deprecation::notice('4.13.0', 'Will be replaced by getIterator() in CMS 5'); + if (is_object($this->handle)) { + // Fix for https://github.com/silverstripe/silverstripe-framework/issues/9097 without breaking the seek() API + $this->handle->data_seek($row); + $result = $this->nextRecord(); + $this->handle->data_seek($row); + return $result; + } + return null; + }); } public function numRecords() @@ -65,8 +73,14 @@ class MySQLQuery extends Query return null; } + /** + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 + */ public function nextRecord() { + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.13.0', 'Will be replaced by getIterator() in CMS 5'); + }); $floatTypes = [MYSQLI_TYPE_FLOAT, MYSQLI_TYPE_DOUBLE, MYSQLI_TYPE_DECIMAL, MYSQLI_TYPE_NEWDECIMAL]; if (is_object($this->handle) && ($row = $this->handle->fetch_array(MYSQLI_NUM))) { diff --git a/src/ORM/Connect/MySQLStatement.php b/src/ORM/Connect/MySQLStatement.php index 7bc54765f..06c76b7d1 100644 --- a/src/ORM/Connect/MySQLStatement.php +++ b/src/ORM/Connect/MySQLStatement.php @@ -4,6 +4,7 @@ namespace SilverStripe\ORM\Connect; use mysqli_result; use mysqli_stmt; +use SilverStripe\Dev\Deprecation; /** * Provides a record-view for mysqli prepared statements @@ -102,15 +103,21 @@ class MySQLStatement extends Query $this->currentRecord = false; } + /** + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 + */ public function seek($row) { - $this->rowNum = $row - 1; + return Deprecation::withNoReplacement(function () use ($row) { + Deprecation::notice('4.13.0', 'Will be replaced by getIterator() in CMS 5'); + $this->rowNum = $row - 1; - // Fix for https://github.com/silverstripe/silverstripe-framework/issues/9097 without breaking the seek() API - $this->statement->data_seek($row); - $result = $this->next(); - $this->statement->data_seek($row); - return $result; + // Fix for https://github.com/silverstripe/silverstripe-framework/issues/9097 without breaking the seek() API + $this->statement->data_seek($row); + $result = $this->next(); + $this->statement->data_seek($row); + return $result; + }); } public function numRecords() @@ -118,8 +125,14 @@ class MySQLStatement extends Query return $this->statement->num_rows(); } + /** + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 + */ public function nextRecord() { + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.13.0', 'Will be replaced by getIterator() in CMS 5'); + }); // Skip data if out of data if (!$this->statement->fetch()) { return false; diff --git a/src/ORM/Connect/PDOConnector.php b/src/ORM/Connect/PDOConnector.php index c275d5d4f..cd40ea6c3 100644 --- a/src/ORM/Connect/PDOConnector.php +++ b/src/ORM/Connect/PDOConnector.php @@ -11,6 +11,8 @@ use PDOException; /** * PDO driver database connector + * + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ class PDOConnector extends DBConnector implements TransactionManager { @@ -87,6 +89,17 @@ class PDOConnector extends DBConnector implements TransactionManager */ protected $inTransaction = false; + public function __construct() + { + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '4.13.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + }); + } + /** * Flush all prepared statements */ diff --git a/src/ORM/Connect/PDOQuery.php b/src/ORM/Connect/PDOQuery.php index 7180de28d..fe3e144ab 100644 --- a/src/ORM/Connect/PDOQuery.php +++ b/src/ORM/Connect/PDOQuery.php @@ -2,8 +2,12 @@ namespace SilverStripe\ORM\Connect; +use SilverStripe\Dev\Deprecation; + /** * A result-set from a PDO database. + * + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ class PDOQuery extends Query { @@ -18,10 +22,16 @@ class PDOQuery extends Query */ public function __construct(PDOStatementHandle $statement) { + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '4.13.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + }); // Since no more than one PDOStatement for any one connection can be safely // traversed, each statement simply requests all rows at once for safety. // This could be re-engineered to call fetchAll on an as-needed basis - $this->results = $statement->typeCorrectedFetchAll(); $statement->closeCursor(); } diff --git a/src/ORM/Connect/PDOStatementHandle.php b/src/ORM/Connect/PDOStatementHandle.php index b2ad1971f..850d32cca 100644 --- a/src/ORM/Connect/PDOStatementHandle.php +++ b/src/ORM/Connect/PDOStatementHandle.php @@ -4,6 +4,7 @@ namespace SilverStripe\ORM\Connect; use PDO; use PDOStatement; +use SilverStripe\Dev\Deprecation; /** * A handle to a PDOStatement, with cached column metadata, and type conversion @@ -11,6 +12,8 @@ use PDOStatement; * Column metadata can't be fetched from a native PDOStatement after multiple calls in some DB backends, * so we wrap in this handle object, which also takes care of tidying up content types to keep in line * with the SilverStripe 4.4+ type expectations. + * + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ class PDOStatementHandle { @@ -36,6 +39,13 @@ class PDOStatementHandle */ public function __construct(PDOStatement $statement) { + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '4.13.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + }); $this->statement = $statement; } diff --git a/src/ORM/Connect/Query.php b/src/ORM/Connect/Query.php index af9e0c3a5..5aeb673f7 100644 --- a/src/ORM/Connect/Query.php +++ b/src/ORM/Connect/Query.php @@ -4,6 +4,7 @@ namespace SilverStripe\ORM\Connect; use SilverStripe\Core\Convert; use Iterator; +use SilverStripe\Dev\Deprecation; /** * Abstract query-result class. A query result provides an iterator that returns a map for each record of a query @@ -34,6 +35,7 @@ abstract class Query implements Iterator * The current record in the iterator. * * @var array + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ protected $currentRecord = null; @@ -41,6 +43,7 @@ abstract class Query implements Iterator * The number of the current row in the iterator. * * @var int + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ protected $rowNum = -1; @@ -48,6 +51,7 @@ abstract class Query implements Iterator * Flag to keep track of whether iteration has begun, to prevent unnecessary seeks * * @var bool + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ protected $queryHasBegun = false; @@ -169,52 +173,68 @@ abstract class Query implements Iterator * Makes use of {@link seek()} and {@link numRecords()}, takes care of the plumbing. * * @return void + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ #[\ReturnTypeWillChange] public function rewind() { - if ($this->queryHasBegun && $this->numRecords() > 0) { - $this->queryHasBegun = false; - $this->currentRecord = null; - $this->seek(0); - } + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.13.0', 'Will be replaced by getIterator() in CMS 5'); + if ($this->queryHasBegun && $this->numRecords() > 0) { + $this->queryHasBegun = false; + $this->currentRecord = null; + $this->seek(0); + } + }); } /** * Iterator function implementation. Return the current item of the iterator. * * @return array + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ #[\ReturnTypeWillChange] public function current() { - if (!$this->currentRecord) { - return $this->next(); - } else { - return $this->currentRecord; - } + return Deprecation::withNoReplacement(function () { + Deprecation::notice('4.13.0', 'Will be replaced by getIterator() in CMS 5'); + if (!$this->currentRecord) { + return $this->next(); + } else { + return $this->currentRecord; + } + }); } /** * Iterator function implementation. Return the first item of this iterator. * * @return array + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ public function first() { - $this->rewind(); - return $this->current(); + return Deprecation::withNoReplacement(function () { + Deprecation::notice('4.13.0', 'Will be replaced by getIterator() in CMS 5'); + $this->rewind(); + return $this->current(); + }); } /** * Iterator function implementation. Return the row number of the current item. * * @return int + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ #[\ReturnTypeWillChange] public function key() { - return $this->rowNum; + return Deprecation::withNoReplacement(function () { + Deprecation::notice('4.13.0', 'Will be replaced by getIterator() in CMS 5'); + return $this->rowNum; + }); } /** @@ -222,34 +242,43 @@ abstract class Query implements Iterator * Makes use of {@link nextRecord()}, takes care of the plumbing. * * @return array + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ #[\ReturnTypeWillChange] public function next() { - $this->queryHasBegun = true; - $this->currentRecord = $this->nextRecord(); - $this->rowNum++; - return $this->currentRecord; + return Deprecation::withNoReplacement(function () { + Deprecation::notice('4.13.0', 'Will be replaced by getIterator() in CMS 5'); + $this->queryHasBegun = true; + $this->currentRecord = $this->nextRecord(); + $this->rowNum++; + return $this->currentRecord; + }); } /** * Iterator function implementation. Check if the iterator is pointing to a valid item. * * @return bool + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ #[\ReturnTypeWillChange] public function valid() { - if (!$this->queryHasBegun) { - $this->next(); - } - return $this->currentRecord !== false; + return Deprecation::withNoReplacement(function () { + Deprecation::notice('4.13.0', 'Will be removed without equivalent functionality to replace it.'); + if (!$this->queryHasBegun) { + $this->next(); + } + return $this->currentRecord !== false; + }); } /** * Return the next record in the query result. * * @return array + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ abstract public function nextRecord(); @@ -265,6 +294,7 @@ abstract class Query implements Iterator * * @param int $rowNum Row number to go to. * @return array + * @deprecated 4.13.0 Will be replaced by getIterator() in CMS 5 */ abstract public function seek($rowNum); } diff --git a/src/ORM/DataList.php b/src/ORM/DataList.php index 72dfaf02e..93c48fb7b 100644 --- a/src/ORM/DataList.php +++ b/src/ORM/DataList.php @@ -11,6 +11,7 @@ use ArrayIterator; use Exception; use InvalidArgumentException; use LogicException; +use SilverStripe\Dev\Deprecation; /** * Implements a "lazy loading" DataObjectSet. @@ -785,9 +786,13 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li * Returns a generator for this DataList * * @return \Generator&DataObject[] + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ public function getGenerator() { + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.13.0', 'Will be removed without equivalent functionality to replace it'); + }); $query = $this->dataQuery->query()->execute(); while ($row = $query->record()) { diff --git a/src/ORM/Map_Iterator.php b/src/ORM/Map_Iterator.php index d645ca07d..68627639c 100644 --- a/src/ORM/Map_Iterator.php +++ b/src/ORM/Map_Iterator.php @@ -3,9 +3,12 @@ namespace SilverStripe\ORM; use Iterator; +use SilverStripe\Dev\Deprecation; /** * Builds a map iterator around an Iterator. Called by Map + * + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ class Map_Iterator implements Iterator { @@ -35,6 +38,13 @@ class Map_Iterator implements Iterator */ public function __construct(Iterator $items, $keyField, $titleField, $firstItems = null, $lastItems = null) { + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '4.13.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + }); $this->items = $items; $this->keyField = $keyField; $this->titleField = $titleField; From 3a14aafc7f10de60adabf72b9788515255168aa3 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 2 Feb 2023 14:04:34 +1300 Subject: [PATCH 02/11] API Deprecate Diff in favour of CMS5's HtmlDiff --- src/View/Parsers/Diff.php | 23 +++++++++++++++++++++++ tests/php/View/Parsers/DiffTest.php | 25 ++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/View/Parsers/Diff.php b/src/View/Parsers/Diff.php index 3521fa43c..1e8060656 100644 --- a/src/View/Parsers/Diff.php +++ b/src/View/Parsers/Diff.php @@ -5,16 +5,28 @@ namespace SilverStripe\View\Parsers; use InvalidArgumentException; use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; +use SilverStripe\Dev\Deprecation; require_once 'difflib/difflib.php'; /** * Class representing a 'diff' between two sequences of strings. + * + * @deprecated 4.13.0 Will be replaced with SilverStripe\View\Parsers\HtmlDiff */ class Diff extends \Diff { public static $html_cleaner_class = null; + /** + * @inheritDoc + */ + public function __construct($from_lines, $to_lines) + { + Deprecation::notice('4.13.0', 'Will be replaced with SilverStripe\View\Parsers\HtmlDiff', Deprecation::SCOPE_CLASS); + parent::__construct($from_lines, $to_lines); + } + /** * Attempt to clean invalid HTML, which messes up diffs. * This cleans code if possible, using an instance of HTMLCleaner @@ -26,9 +38,12 @@ class Diff extends \Diff * @param HTMLCleaner $cleaner Optional instance of a HTMLCleaner class to * use, overriding self::$html_cleaner_class * @return mixed|string + * + * @deprecated 4.13.0 Will be removed without equivalent functionality */ public static function cleanHTML($content, $cleaner = null) { + Deprecation::notice('4.13.0', 'Will be removed without equivalent functionality'); if (!$cleaner) { if (self::$html_cleaner_class && class_exists(self::$html_cleaner_class)) { $cleaner = Injector::inst()->create(self::$html_cleaner_class); @@ -57,9 +72,13 @@ class Diff extends \Diff * @param string $to * @param bool $escape * @return string + * + * @deprecated 4.13.0 Will be replaced with SilverStripe\View\Parsers\HtmlDiff::compareHTML() */ public static function compareHTML($from, $to, $escape = false) { + Deprecation::notice('4.13.0', 'Will be replaced with SilverStripe\View\Parsers\HtmlDiff::compareHTML()'); + // First split up the content into words and tags $set1 = self::getHTMLChunks($from); $set2 = self::getHTMLChunks($to); @@ -163,9 +182,13 @@ class Diff extends \Diff /** * @param string|bool|array $content If passed as an array, values will be concatenated with a comma. * @return array + * + * @deprecated 4.13.0 Will be removed without equivalent functionality */ public static function getHTMLChunks($content) { + Deprecation::notice('4.13.0', 'Will be removed without equivalent functionality'); + if ($content && !is_string($content) && !is_array($content) && !is_numeric($content) && !is_bool($content)) { throw new InvalidArgumentException('$content parameter needs to be a string or array'); } diff --git a/tests/php/View/Parsers/DiffTest.php b/tests/php/View/Parsers/DiffTest.php index 3eab9c66c..ce8998bc9 100644 --- a/tests/php/View/Parsers/DiffTest.php +++ b/tests/php/View/Parsers/DiffTest.php @@ -2,6 +2,7 @@ namespace SilverStripe\View\Tests\Parsers; +use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; use SilverStripe\View\Parsers\Diff; @@ -13,6 +14,10 @@ class DiffTest extends SapphireTest */ public function testTableDiff() { + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } + if (!class_exists('DOMDocument')) { $this->markTestSkipped('"DOMDocument" required'); return; @@ -47,7 +52,9 @@ class DiffTest extends SapphireTest "; $expected = "" . $to . "" . "" . $from . ""; - $compare = Diff::compareHTML($from, $to); + $compare = Deprecation::withNoReplacement(function () use ($from, $to) { + return Diff::compareHTML($from, $to); + }); // Very hard to debug this way, wouldn't need to do this if PHP had an *actual* DOM parsing lib, // and not just the poor excuse that is DOMDocument @@ -62,6 +69,10 @@ class DiffTest extends SapphireTest */ public function testLegacyEachStatement() { + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } + $sentenceOne = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; $sentenceTwo = @@ -73,17 +84,25 @@ class DiffTest extends SapphireTest // We're cheating our test a little bit here, because depending on what HTML cleaner you have, you'll get // spaces added or not added around the tags. $expected = "/^ *$sentenceOne<\/del> *$sentenceTwo *$sentenceOne<\/ins> *$/"; - $actual = Diff::compareHTML($from, $to); + $actual = Deprecation::withNoReplacement(function () use ($from, $to) { + return Diff::compareHTML($from, $to); + }); $this->assertMatchesRegularExpression($expected, $actual); } public function testDiffArray() { + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } + $from = ['Lorem', ['array here please ignore'], 'ipsum dolor']; $to = 'Lorem,ipsum'; $expected = "/^Lorem,ipsum *dolor<\/del> *$/"; - $actual = Diff::compareHTML($from, $to); + $actual = Deprecation::withNoReplacement(function () use ($from, $to) { + return Diff::compareHTML($from, $to); + }); $this->assertMatchesRegularExpression($expected, $actual); } From 54fc4ee9d2bf812d166e225cab3777916c72f6dc Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Thu, 9 Feb 2023 17:09:48 +1100 Subject: [PATCH 03/11] fix directory separator in i18nTextCollector on Windows (#10681) * fix directory separator in i18nTextCollector for Windows * fix typo --- src/i18n/TextCollection/i18nTextCollector.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/i18n/TextCollection/i18nTextCollector.php b/src/i18n/TextCollection/i18nTextCollector.php index e7d5e95fb..284c3baa0 100644 --- a/src/i18n/TextCollection/i18nTextCollector.php +++ b/src/i18n/TextCollection/i18nTextCollector.php @@ -457,7 +457,7 @@ class i18nTextCollector $this->getWriter()->write( $entities, $this->defaultLocale, - $this->baseSavePath . '/' . $module->getRelativePath() + $this->baseSavePath . DIRECTORY_SEPARATOR . $module->getRelativePath() ); return $this; } @@ -511,25 +511,25 @@ class i18nTextCollector $modulePath = $module->getPath(); // Search all .ss files in themes - if (stripos($module->getRelativePath() ?? '', 'themes/') === 0) { + if (stripos($module->getRelativePath() ?? '', 'themes' . DIRECTORY_SEPARATOR) === 0) { return $this->getFilesRecursive($modulePath, null, 'ss'); } // If non-standard module structure, search all root files - if (!is_dir("{$modulePath}/code") && !is_dir("{$modulePath}/src")) { + if (!is_dir($modulePath . DIRECTORY_SEPARATOR . 'code') && !is_dir($modulePath . DIRECTORY_SEPARATOR . 'src')) { return $this->getFilesRecursive($modulePath); } // Get code files - if (is_dir("{$modulePath}/src")) { - $files = $this->getFilesRecursive("{$modulePath}/src", null, 'php'); + if (is_dir($modulePath . DIRECTORY_SEPARATOR . 'src')) { + $files = $this->getFilesRecursive($modulePath . DIRECTORY_SEPARATOR . 'src', null, 'php'); } else { - $files = $this->getFilesRecursive("{$modulePath}/code", null, 'php'); + $files = $this->getFilesRecursive($modulePath . DIRECTORY_SEPARATOR . 'code', null, 'php'); } // Search for templates in this module - if (is_dir("{$modulePath}/templates")) { - $templateFiles = $this->getFilesRecursive("{$modulePath}/templates", null, 'ss'); + if (is_dir($modulePath . DIRECTORY_SEPARATOR . 'templates')) { + $templateFiles = $this->getFilesRecursive($modulePath . DIRECTORY_SEPARATOR . 'templates', null, 'ss'); } else { $templateFiles = $this->getFilesRecursive($modulePath, null, 'ss'); } @@ -904,7 +904,7 @@ class i18nTextCollector $fileList = []; } // Skip ignored folders - if (is_file("{$folder}/_manifest_exclude") || preg_match($folderExclude ?? '', $folder ?? '')) { + if (is_file($folder . DIRECTORY_SEPARATOR . '_manifest_exclude') || preg_match($folderExclude ?? '', $folder ?? '')) { return $fileList; } From ab566b0a156376020dc25e6754c9d07ca12c2d56 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Wed, 15 Feb 2023 13:26:36 +1300 Subject: [PATCH 04/11] API Add new deprecation notices. (#10691) These are removed in CMS 5. --- src/Core/Manifest/Module.php | 3 +++ src/Dev/CSVParser.php | 3 ++- src/Dev/CsvBulkLoader.php | 10 +++++----- src/Dev/TestSession_STResponseWrapper.php | 8 ++++++++ tests/php/Dev/CSVParserTest.php | 4 ++++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Core/Manifest/Module.php b/src/Core/Manifest/Module.php index 77dd61ed2..7f4ff1580 100644 --- a/src/Core/Manifest/Module.php +++ b/src/Core/Manifest/Module.php @@ -23,16 +23,19 @@ class Module implements Serializable /** * Return value of getCIConfig() when module uses PHPUNit 9 + * @deprecated 4.13.0 Will be removed without equivalent functionality */ const CI_PHPUNIT_NINE = 'CI_PHPUNIT_NINE'; /** * Return value of getCIConfig() when module uses PHPUNit 5 + * @deprecated 4.13.0 Will be removed without equivalent functionality */ const CI_PHPUNIT_FIVE = 'CI_PHPUNIT_FIVE'; /** * Return value of getCIConfig() when module does not use any CI + * @deprecated 4.13.0 Will be removed without equivalent functionality */ const CI_UNKNOWN = 'CI_UNKNOWN'; diff --git a/src/Dev/CSVParser.php b/src/Dev/CSVParser.php index fda09190c..51ffe7f0c 100644 --- a/src/Dev/CSVParser.php +++ b/src/Dev/CSVParser.php @@ -31,6 +31,7 @@ use SilverStripe\Control\Director; * $obj->write(); * } * + * @deprecated 4.13.0 Use League\Csv\Reader instead */ class CSVParser implements Iterator { @@ -115,7 +116,7 @@ class CSVParser implements Iterator */ public function __construct($filename, $delimiter = ",", $enclosure = '"') { - Deprecation::notice('5.0', __CLASS__ . ' is deprecated, use ' . Reader::class . ' instead'); + Deprecation::notice('4.13.0', 'Use ' . Reader::class . ' instead', Deprecation::SCOPE_CLASS); $filename = Director::getAbsFile($filename); $this->filename = $filename; $this->delimiter = $delimiter; diff --git a/src/Dev/CsvBulkLoader.php b/src/Dev/CsvBulkLoader.php index a4384078b..2c82a03bd 100644 --- a/src/Dev/CsvBulkLoader.php +++ b/src/Dev/CsvBulkLoader.php @@ -254,11 +254,11 @@ class CsvBulkLoader extends BulkLoader Deprecation::notice('4.12.0', 'Process rows individually instead'); $results = BulkLoader_Result::create(); - $csv = new CSVParser( - $filepath, - $this->delimiter, - $this->enclosure - ); + $delimiter = $this->delimiter; + $enclosure = $this->enclosure; + $csv = Deprecation::withNoReplacement(function () use ($filepath, $delimiter, $enclosure) { + return new CSVParser($filepath, $delimiter, $enclosure); + }); // ColumnMap has two uses, depending on whether hasHeaderRow is set if ($this->columnMap) { diff --git a/src/Dev/TestSession_STResponseWrapper.php b/src/Dev/TestSession_STResponseWrapper.php index 402080e84..6a3407314 100644 --- a/src/Dev/TestSession_STResponseWrapper.php +++ b/src/Dev/TestSession_STResponseWrapper.php @@ -6,6 +6,7 @@ use SilverStripe\Control\HTTPResponse; /** * Wrapper around HTTPResponse to make it look like a SimpleHTTPResposne + * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ class TestSession_STResponseWrapper { @@ -17,6 +18,13 @@ class TestSession_STResponseWrapper public function __construct(HTTPResponse $response) { + Deprecation::withNoReplacement(function () { + Deprecation::notice( + '4.13.0', + 'Will be removed without equivalent functionality to replace it', + Deprecation::SCOPE_CLASS + ); + }); $this->response = $response; } diff --git a/tests/php/Dev/CSVParserTest.php b/tests/php/Dev/CSVParserTest.php index 1ff17fe16..921f9be52 100644 --- a/tests/php/Dev/CSVParserTest.php +++ b/tests/php/Dev/CSVParserTest.php @@ -3,6 +3,7 @@ namespace SilverStripe\Dev\Tests; use SilverStripe\Dev\CSVParser; +use SilverStripe\Dev\Deprecation; use SilverStripe\Dev\SapphireTest; class CSVParserTest extends SapphireTest @@ -19,6 +20,9 @@ class CSVParserTest extends SapphireTest { parent::setUp(); $this->csvPath = __DIR__ . '/CsvBulkLoaderTest/csv/'; + if (Deprecation::isEnabled()) { + $this->markTestSkipped('Test calls deprecated code'); + } } public function testParsingWithHeaders() From 652281507f2f0c17126806f8aa30f180a0fa6a95 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Mon, 27 Feb 2023 15:25:27 +1300 Subject: [PATCH 05/11] FIX Correctly identify deprecated API in withNoReplacement (#10706) --- src/Dev/Deprecation.php | 12 +++++++++--- tests/php/Dev/DeprecationTest.php | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Dev/Deprecation.php b/src/Dev/Deprecation.php index fff3e8971..871aa0834 100644 --- a/src/Dev/Deprecation.php +++ b/src/Dev/Deprecation.php @@ -177,6 +177,12 @@ class Deprecation $level = 1; } $newLevel = $level; + // handle closures inside withNoReplacement() + if (self::$insideWithNoReplacement + && substr($backtrace[$newLevel]['function'], -strlen('{closure}')) === '{closure}' + ) { + $newLevel = $newLevel + 2; + } // handle call_user_func if ($level === 4 && strpos($backtrace[2]['function'] ?? '', 'call_user_func') !== false) { $newLevel = 5; @@ -277,10 +283,10 @@ class Deprecation // Do not add to self::$userErrorMessageBuffer, as the backtrace is too expensive return; } - + // Getting a backtrace is slow, so we only do it if we need it $backtrace = null; - + // Get the calling scope if ($scope == Deprecation::SCOPE_METHOD) { $backtrace = debug_backtrace(0); @@ -291,7 +297,7 @@ class Deprecation } else { $caller = false; } - + if (substr($string, -1) != '.') { $string .= "."; } diff --git a/tests/php/Dev/DeprecationTest.php b/tests/php/Dev/DeprecationTest.php index fac1ad726..8b0cf8184 100644 --- a/tests/php/Dev/DeprecationTest.php +++ b/tests/php/Dev/DeprecationTest.php @@ -151,6 +151,22 @@ class DeprecationTest extends SapphireTest Deprecation::outputNotices(); } + public function testNoticeWithNoReplacementTrue() + { + $message = implode(' ', [ + 'SilverStripe\Dev\Tests\DeprecationTest->testNoticeWithNoReplacementTrue is deprecated.', + 'My message.', + 'Called from PHPUnit\Framework\TestCase->runTest.' + ]); + $this->expectDeprecation(); + $this->expectDeprecationMessage($message); + Deprecation::enable(true); + Deprecation::withNoReplacement(function () { + Deprecation::notice('123', 'My message.'); + }); + Deprecation::outputNotices(); + } + public function testClassWithNoReplacement() { $message = implode(' ', [ From 6669d54f5928d22ee94e966747069b61aa06d14e Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Mon, 27 Feb 2023 18:13:31 +1300 Subject: [PATCH 06/11] FIX Wrap deprecated config with no replacement (#10704) --- src/Control/Director.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Control/Director.php b/src/Control/Director.php index ca26754d9..fe5c3e379 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -704,7 +704,9 @@ class Director implements TemplateGlobalProvider */ public static function publicDir() { - $alternate = self::config()->uninherited('alternate_public_dir'); + $alternate = Deprecation::withNoReplacement(function () { + return self::config()->uninherited('alternate_public_dir'); + }); if (isset($alternate)) { return $alternate; } From 5295ba6c168b6d7c1a23913e2c99fbe87aba6781 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Wed, 1 Mar 2023 11:36:08 +1300 Subject: [PATCH 07/11] API Throw deprecation warnings for bad configuration (#10702) --- src/Control/Director.php | 1 - src/Control/HTTPApplication.php | 51 +++++++++++++++++++ src/Dev/Deprecation.php | 12 ++--- .../swiftmailer/Swift/MailTransport.php | 7 +++ .../Swift/Transport/MailInvoker.php | 1 + .../Swift/Transport/MailTransport.php | 7 ++- .../Swift/Transport/SimpleMailInvoker.php | 10 ++++ 7 files changed, 78 insertions(+), 11 deletions(-) diff --git a/src/Control/Director.php b/src/Control/Director.php index fe5c3e379..3ac23350e 100644 --- a/src/Control/Director.php +++ b/src/Control/Director.php @@ -73,7 +73,6 @@ class Director implements TemplateGlobalProvider /** * @config * @var string - * @deprecated 4.13.0 Will be removed without equivalent functionality to replace it */ private static $alternate_base_folder; diff --git a/src/Control/HTTPApplication.php b/src/Control/HTTPApplication.php index aba380796..f1f6fd493 100644 --- a/src/Control/HTTPApplication.php +++ b/src/Control/HTTPApplication.php @@ -6,12 +6,15 @@ use SilverStripe\Control\Middleware\HTTPMiddlewareAware; use SilverStripe\Core\Application; use SilverStripe\Core\Environment; use SilverStripe\Core\Kernel; +use SilverStripe\Core\Manifest\Module; use SilverStripe\Core\Startup\FlushDiscoverer; use SilverStripe\Core\Startup\CompositeFlushDiscoverer; use SilverStripe\Core\Startup\CallbackFlushDiscoverer; use SilverStripe\Core\Startup\RequestFlushDiscoverer; use SilverStripe\Core\Startup\ScheduledFlushDiscoverer; use SilverStripe\Core\Startup\DeployFlushDiscoverer; +use SilverStripe\Dev\Deprecation; +use SilverStripe\GraphQL\TypeCreator; /** * Invokes the HTTP application within an ErrorControlChain @@ -133,6 +136,10 @@ class HTTPApplication implements Application return $this->callMiddleware($request, function ($request) use ($callback, $flush) { // Pre-request boot $this->getKernel()->boot($flush); + + // This is the earliest point we can do this and guarantee it's hit exactly once per request. + $this->warnAboutDeprecatedSetups(); + return call_user_func($callback, $request); }); } catch (HTTPResponse_Exception $ex) { @@ -141,4 +148,48 @@ class HTTPApplication implements Application $this->getKernel()->shutdown(); } } + + /** + * Trigger deprecation notices for legacy configuration which is deprecated but + * doesn't have deprecation notices directly on the relevant API + * + * Don't remove this method even if it's just a no-op - we'll reuse this mechanism + * in the future as needed. + */ + private function warnAboutDeprecatedSetups() + { + // TypeCreator is a class unique to GraphQL v3 - we use it in other areas to detect + // which version is being used. + if (class_exists(TypeCreator::class)) { + Deprecation::notice( + '4.13.0', + 'silverstripe/graphql 3.x is deprecated. Upgrade to 4.x instead.' + . ' See https://docs.silverstripe.org/en/4/upgrading/upgrading_to_graphql_4/', + Deprecation::SCOPE_GLOBAL + ); + } + + // The alternate_public_dir config property is deprecated, but because it's + // always fetched it'll throw a deprecation warning whether you've set it or not. + // There are also multiple mechanisms which can result in this bad configuration. + if (PUBLIC_DIR !== 'public' || Director::publicDir() !== PUBLIC_DIR) { + Deprecation::notice( + '4.13.0', + 'Use of a public webroot other than "public" is deprecated.' + . ' See https://docs.silverstripe.org/en/4/changelogs/4.1.0#public-folder/', + Deprecation::SCOPE_GLOBAL + ); + } + + // This change of defaults has no other deprecation notice being emitted currently. + $project = new Module(BASE_PATH, BASE_PATH); + if ($project->getResourcesDir() === '') { + Deprecation::notice( + '4.13.0', + 'The RESOURCES_DIR constant will change to "_resources" by default.' + . ' See https://docs.silverstripe.org/en/5/changelogs/5.0.0/#api-general', + Deprecation::SCOPE_GLOBAL + ); + } + } } diff --git a/src/Dev/Deprecation.php b/src/Dev/Deprecation.php index 871aa0834..66b39c070 100644 --- a/src/Dev/Deprecation.php +++ b/src/Dev/Deprecation.php @@ -10,19 +10,13 @@ use SilverStripe\Core\Injector\InjectorLoader; use SilverStripe\Core\Manifest\Module; /** - * Handles raising an notice when accessing a deprecated method + * Handles raising an notice when accessing a deprecated method, class, configuration, or behaviour. * - * A pattern used in SilverStripe when deprecating a method is to add something like - * user_error('This method is deprecated', E_USER_NOTICE); - * to the method - * - * However sometimes we want to mark that a method will be deprecated in some future version and shouldn't be used in + * Sometimes we want to mark that a method will be deprecated in some future version and shouldn't be used in * new code, but not forbid in the current version - for instance when that method is still heavily used in framework * or cms. * - * This class abstracts the above pattern and adds a way to do that. - * - * Each call to notice passes a version that the notice will be valid from. + * See https://docs.silverstripe.org/en/contributing/release_process/#deprecation */ class Deprecation { diff --git a/thirdparty/swiftmailer/Swift/MailTransport.php b/thirdparty/swiftmailer/Swift/MailTransport.php index ec3b892a2..a9052972b 100644 --- a/thirdparty/swiftmailer/Swift/MailTransport.php +++ b/thirdparty/swiftmailer/Swift/MailTransport.php @@ -5,6 +5,8 @@ * It has been slightly modified to meet phpcs standards and initialise Swift_DependencyContainer */ +use SilverStripe\Dev\Deprecation; + /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn @@ -19,6 +21,7 @@ * @author Chris Corbyn * * at deprecated since 5.4.5 (to be removed in 6.0) + * @deprecated 4.12.0 Sending email using the mail() function is deprecated. Use sendmail or SMTP instead */ // @codingStandardsIgnoreStart // ignore missing namespace @@ -32,6 +35,10 @@ class Swift_MailTransport extends Swift_Transport_MailTransport */ public function __construct($extraParams = '-f%s') { + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.12.0', 'Sending email using the mail() function is deprecated. Use sendmail or SMTP instead', Deprecation::SCOPE_CLASS); + }); + call_user_func_array( [$this, 'Swift_Transport_MailTransport::__construct'], $this->getDependencies() ?? [] diff --git a/thirdparty/swiftmailer/Swift/Transport/MailInvoker.php b/thirdparty/swiftmailer/Swift/Transport/MailInvoker.php index 2a23e24d2..f36af3b85 100644 --- a/thirdparty/swiftmailer/Swift/Transport/MailInvoker.php +++ b/thirdparty/swiftmailer/Swift/Transport/MailInvoker.php @@ -17,6 +17,7 @@ * This interface intercepts calls to the mail() function. * * @author Chris Corbyn + * @deprecated 4.12.0 Will be replaced with symfony/mailer */ // @codingStandardsIgnoreStart // ignore missing namespace diff --git a/thirdparty/swiftmailer/Swift/Transport/MailTransport.php b/thirdparty/swiftmailer/Swift/Transport/MailTransport.php index 84fd03a15..5583c04be 100644 --- a/thirdparty/swiftmailer/Swift/Transport/MailTransport.php +++ b/thirdparty/swiftmailer/Swift/Transport/MailTransport.php @@ -5,6 +5,8 @@ * It has been slightly modified to meet phpcs standards and to update method signatures to match the swiftmailer v6 */ +use SilverStripe\Dev\Deprecation; + /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn @@ -26,7 +28,7 @@ * * @author Chris Corbyn * - * at deprecated since 5.4.5 (to be removed in 6.0) + * @deprecated 4.12.0 Sending email using the mail() function is deprecated. Use sendmail or SMTP instead */ // @codingStandardsIgnoreStart // ignore missing namespace @@ -50,6 +52,9 @@ class Swift_Transport_MailTransport implements Swift_Transport */ public function __construct(Swift_Transport_MailInvoker $invoker, Swift_Events_EventDispatcher $eventDispatcher) { + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.12.0', 'Sending email using the mail() function is deprecated. Use sendmail or SMTP instead', Deprecation::SCOPE_CLASS); + }); // @trigger_error(sprintf('The %s class is deprecated since version 5.4.5 and will be removed in 6.0. Use the Sendmail or SMTP transport instead.', __CLASS__), E_USER_DEPRECATED); $this->_invoker = $invoker; diff --git a/thirdparty/swiftmailer/Swift/Transport/SimpleMailInvoker.php b/thirdparty/swiftmailer/Swift/Transport/SimpleMailInvoker.php index 8094e5428..9fffa7194 100644 --- a/thirdparty/swiftmailer/Swift/Transport/SimpleMailInvoker.php +++ b/thirdparty/swiftmailer/Swift/Transport/SimpleMailInvoker.php @@ -5,6 +5,8 @@ * It has been slightly modified to meet phpcs standards */ +use SilverStripe\Dev\Deprecation; + /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn @@ -17,12 +19,20 @@ * This is the implementation class for {@link Swift_Transport_MailInvoker}. * * @author Chris Corbyn + * @deprecated 4.12.0 Sending email using the mail() function is deprecated. Use sendmail or SMTP instead */ // @codingStandardsIgnoreStart // ignore missing namespace class Swift_Transport_SimpleMailInvoker implements Swift_Transport_MailInvoker // @codingStandardsIgnoreEnd* It has been slightly modified to meet phpcs standards { + public function __construct() + { + Deprecation::withNoReplacement(function () { + Deprecation::notice('4.12.0', 'Sending email using the mail() function is deprecated. Use sendmail or SMTP instead', Deprecation::SCOPE_CLASS); + }); + } + /** * Send mail via the mail() function. * From 05674adf512006b9430f3b68efee960c8c1b529c Mon Sep 17 00:00:00 2001 From: Sabina Talipova Date: Tue, 28 Feb 2023 21:31:46 +1300 Subject: [PATCH 08/11] ENH Updated deprecation warning message --- src/ORM/Connect/MySQLDatabase.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ORM/Connect/MySQLDatabase.php b/src/ORM/Connect/MySQLDatabase.php index 9200f3a8c..6da201f0d 100644 --- a/src/ORM/Connect/MySQLDatabase.php +++ b/src/ORM/Connect/MySQLDatabase.php @@ -367,14 +367,16 @@ class MySQLDatabase extends Database implements TransactionManager public function transactionEnd($chain = false) { - $result = $this->getTransactionManager()->transactionEnd(); - if ($chain) { - Deprecation::notice('4.4', '$chain argument is deprecated'); + Deprecation::notice( + '4.4.0', + '$chain argument in ' . __METHOD__ . ' is deprecated', + Deprecation::SCOPE_GLOBAL + ); return $this->getTransactionManager()->transactionStart(); } - return $result; + return $this->getTransactionManager()->transactionEnd(); } /** From 6585d499f5aca7f03e87710aeb8a277cb7dc7e5e Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Mon, 13 Feb 2023 16:18:44 +1100 Subject: [PATCH 09/11] FIX Convert slashes in paths when getting list of classes for file/folder This is to support the mechanism working on all operating systems where Windows may produce a mix of forward and backward slashes in some paths. For working with the files it may not be a problem, but for exact string comparison the path delimiters need to be unified. --- src/Core/ClassInfo.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Core/ClassInfo.php b/src/Core/ClassInfo.php index 38542c1d3..6ac4c58d4 100644 --- a/src/Core/ClassInfo.php +++ b/src/Core/ClassInfo.php @@ -301,14 +301,14 @@ class ClassInfo */ public static function classes_for_file($filePath) { - $absFilePath = Director::getAbsFile($filePath); + $absFilePath = Convert::slashes(Director::getAbsFile($filePath)); $classManifest = ClassLoader::inst()->getManifest(); $classes = $classManifest->getClasses(); $classNames = $classManifest->getClassNames(); $matchedClasses = []; foreach ($classes as $lowerClass => $compareFilePath) { - if (strcasecmp($absFilePath ?? '', $compareFilePath ?? '') === 0) { + if (strcasecmp($absFilePath, Convert::slashes($compareFilePath ?? '')) === 0) { $matchedClasses[$lowerClass] = $classNames[$lowerClass]; } } @@ -324,14 +324,14 @@ class ClassInfo */ public static function classes_for_folder($folderPath) { - $absFolderPath = Director::getAbsFile($folderPath); + $absFolderPath = Convert::slashes(Director::getAbsFile($folderPath)); $classManifest = ClassLoader::inst()->getManifest(); $classes = $classManifest->getClasses(); $classNames = $classManifest->getClassNames(); $matchedClasses = []; foreach ($classes as $lowerClass => $compareFilePath) { - if (stripos($compareFilePath ?? '', $absFolderPath ?? '') === 0) { + if (stripos(Convert::slashes($compareFilePath ?? ''), $absFolderPath) === 0) { $matchedClasses[$lowerClass] = $classNames[$lowerClass]; } } From 403f924d22455d2ba8f927888f7ee6d88b55e034 Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Thu, 2 Mar 2023 09:56:40 +1300 Subject: [PATCH 10/11] BUG Update RelatedDataService to properly escape ClassName in Polymorphic relations (#10713) --- src/ORM/RelatedData/StandardRelatedDataService.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/ORM/RelatedData/StandardRelatedDataService.php b/src/ORM/RelatedData/StandardRelatedDataService.php index 04501fc23..c6be4632d 100644 --- a/src/ORM/RelatedData/StandardRelatedDataService.php +++ b/src/ORM/RelatedData/StandardRelatedDataService.php @@ -394,14 +394,7 @@ class StandardRelatedDataService implements RelatedDataService */ private function prepareClassNameLiteral(string $value): string { - $c = chr(92); - $escaped = str_replace($c ?? '', "{$c}{$c}", $value ?? ''); - // postgres - if (stripos(get_class(DB::get_conn()), 'postgres') !== false) { - return "E'{$escaped}'"; - } - // mysql - return "'{$escaped}'"; + return DB::get_conn()->quoteString($value); } /** From 66561ccb49e196bd652b1fc2112c5aeda062354c Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:05:35 +1300 Subject: [PATCH 11/11] FIX Correctly deprecation Sources.module_priority (#10711) This config was deprecated back in #7154 and hasn't been used since --- src/i18n/Data/Sources.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/i18n/Data/Sources.php b/src/i18n/Data/Sources.php index e7a233ab9..e02e73999 100644 --- a/src/i18n/Data/Sources.php +++ b/src/i18n/Data/Sources.php @@ -26,6 +26,7 @@ class Sources implements Resettable * * @config * @var array + * @deprecated 4.0.0 Use SilverStripe\Core\Manifest\ModuleManifest.module_priority instead */ private static $module_priority = []; @@ -36,15 +37,7 @@ class Sources implements Resettable */ public function getSortedModules() { - $i18nOrder = Sources::config()->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();