ENH Fix deprecation issues for PHP 8.1 compatibility

This commit is contained in:
Steve Boyd 2022-04-06 11:34:34 +12:00
parent cb05e52b0f
commit 814c5b2fd0
13 changed files with 21 additions and 31 deletions

View File

@ -56,7 +56,7 @@ class GeocodableDataObject implements ModelTypePlugin
);
// only apply the plugin to geocodable DataObjects
if (!Extensible::has_extension($class, Geocodable::class)) {
if (!ViewableData::has_extension($class, Geocodable::class)) {
return;
}
@ -85,7 +85,7 @@ class GeocodableQuery implements ModelQueryPlugin
{
$class = $query->getModel()->getSourceClass();
// Only apply to geocodable objects
if (!Extensible::has_extension($class, Geocodable::class)) {
if (!ViewableData::has_extension($class, Geocodable::class)) {
return;
}
@ -177,7 +177,7 @@ public function apply(ModelQuery $query, Schema $schema, array $config = []): vo
{
$class = $query->getModel()->getSourceClass();
// Only apply to geocodable objects
if (!Extensible::has_extension($class, Geocodable::class)) {
if (!ViewableData::has_extension($class, Geocodable::class)) {
return;
}

View File

@ -259,7 +259,7 @@ class HTTP
$path = (isset($parts['path']) && $parts['path'] != '') ? $parts['path'] : '';
// handle URL params which are existing / new
$params = ($params) ? '?' . http_build_query($params, null, $separator) : '';
$params = ($params) ? '?' . http_build_query($params, '', $separator) : '';
// keep fragments (anchors) intact.
$fragment = (isset($parts['fragment']) && $parts['fragment'] != '') ? '#' . $parts['fragment'] : '';

View File

@ -49,7 +49,7 @@ class HTTPResponse_Exception extends Exception
$this->setResponse($response);
}
parent::__construct($this->getResponse()->getBody(), $this->getResponse()->getStatusCode());
parent::__construct((string) $this->getResponse()->getBody(), $this->getResponse()->getStatusCode());
}
/**

View File

@ -10,6 +10,7 @@ use SilverStripe\Core\Manifest\ClassLoader;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\View\ViewableData;
/**
* Provides introspection information about the class tree.
@ -597,7 +598,7 @@ class ClassInfo
// only keep classes with the Extension applied
$classes = array_filter($classes, function ($class) use ($extensionClass) {
return Extensible::has_extension($class, $extensionClass);
return ViewableData::has_extension($class, $extensionClass);
});
return $classes;

View File

@ -168,7 +168,6 @@ class CSVParser implements Iterator
*/
protected function openFile()
{
ini_set('auto_detect_line_endings', 1);
$this->fileHandle = fopen($this->filename, 'r');
if ($this->providedHeaderRow) {

View File

@ -68,9 +68,6 @@ class CsvBulkLoader extends BulkLoader
*/
protected function processAll($filepath, $preview = false)
{
$previousDetectLE = ini_get('auto_detect_line_endings');
ini_set('auto_detect_line_endings', true);
$this->extend('onBeforeProcessAll', $filepath, $preview);
$result = BulkLoader_Result::create();
@ -144,8 +141,6 @@ class CsvBulkLoader extends BulkLoader
$failedMessage = sprintf($failedMessage . " because %s", $e->getMessage());
}
print $failedMessage . PHP_EOL;
} finally {
ini_set('auto_detect_line_endings', $previousDetectLE);
}
$this->extend('onAfterProcessAll', $result, $preview);
@ -182,9 +177,6 @@ class CsvBulkLoader extends BulkLoader
protected function splitFile($path, $lines = null)
{
Deprecation::notice('5.0', 'splitFile is deprecated, please process files using a stream');
$previous = ini_get('auto_detect_line_endings');
ini_set('auto_detect_line_endings', true);
if (!is_int($lines)) {
$lines = $this->config()->get("lines");
@ -230,11 +222,8 @@ class CsvBulkLoader extends BulkLoader
$count = 0;
}
}
fclose($to);
ini_set('auto_detect_line_endings', $previous);
return $files;
}

View File

@ -126,7 +126,7 @@ class DBDecimal extends DBField
return 0;
}
if (ctype_digit($value)) {
if (ctype_digit((string) $value)) {
return (int)$value;
}

View File

@ -5,7 +5,6 @@ namespace SilverStripe\ORM\Hierarchy;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Control\Controller;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Extensible;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\ValidationResult;
@ -17,6 +16,7 @@ use SilverStripe\Versioned\Versioned;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use Exception;
use SilverStripe\View\ViewableData;
/**
* DataObjects that use the Hierarchy extension can be be organised as a hierarchy, with children and parents. The most
@ -418,7 +418,7 @@ class Hierarchy extends DataExtension
{
$ancestry = ClassInfo::ancestry($this->owner);
$ancestorClass = array_shift($ancestry);
while ($ancestorClass && !Extensible::has_extension($ancestorClass, self::class)) {
while ($ancestorClass && !ViewableData::has_extension($ancestorClass, self::class)) {
$ancestorClass = array_shift($ancestry);
}

View File

@ -146,7 +146,7 @@ abstract class HTMLValue extends ViewableData
{
$doc = $this->getDocument();
if (method_exists($doc, $method)) {
if ($doc && method_exists($doc, $method)) {
return call_user_func_array([$doc, $method], $arguments);
} else {
return parent::__call($method, $arguments);

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Forms\Tests;
use IntlDateFormatter;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\DatetimeField;
@ -256,12 +257,12 @@ class DatetimeFieldTest extends SapphireTest
{
$f = new DatetimeField('Datetime');
$f->setMinDatetime('-7 days');
$f->setValue(strftime('%Y-%m-%d %T', strtotime('-8 days', DBDatetime::now()->getTimestamp())));
$f->setValue(date('Y-m-d H:i:s', strtotime('-8 days', DBDatetime::now()->getTimestamp())));
$this->assertFalse($f->validate(new RequiredFields()), 'Date below min datetime, with strtotime');
$f = new DatetimeField('Datetime');
$f->setMinDatetime('-7 days');
$f->setValue(strftime('%Y-%m-%d %T', strtotime('-7 days', DBDatetime::now()->getTimestamp())));
$f->setValue(date('Y-m-d H:i:s', strtotime('-7 days', DBDatetime::now()->getTimestamp())));
$this->assertTrue($f->validate(new RequiredFields()), 'Date matching min datetime, with strtotime');
}
@ -269,12 +270,12 @@ class DatetimeFieldTest extends SapphireTest
{
$f = new DatetimeField('Datetime');
$f->setMaxDatetime('7 days');
$f->setValue(strftime('%Y-%m-%d %T', strtotime('8 days', DBDatetime::now()->getTimestamp())));
$f->setValue(date('Y-m-d H:i:s', strtotime('8 days', DBDatetime::now()->getTimestamp())));
$this->assertFalse($f->validate(new RequiredFields()), 'Date above max date, with strtotime');
$f = new DatetimeField('Datetime');
$f->setMaxDatetime('7 days');
$f->setValue(strftime('%Y-%m-%d %T', strtotime('7 days', DBDatetime::now()->getTimestamp())));
$f->setValue(date('Y-m-d H:i:s', strtotime('7 days', DBDatetime::now()->getTimestamp())));
$this->assertTrue($f->validate(new RequiredFields()), 'Date matching max date, with strtotime');
}

View File

@ -1143,8 +1143,8 @@ class FormTest extends FunctionalTest
{
return str_replace(
[
html_entity_decode(' ', null, 'UTF-8'),
html_entity_decode(' ', null, 'UTF-8'), // narrow non-breaking space
html_entity_decode(' ', 0, 'UTF-8'),
html_entity_decode(' ', 0, 'UTF-8'), // narrow non-breaking space
],
' ',
trim($input)

View File

@ -24,8 +24,8 @@ class NumericFieldTest extends SapphireTest
{
return str_replace(
[
html_entity_decode(' ', null, 'UTF-8'),
html_entity_decode(' ', null, 'UTF-8'), // narrow non-breaking space
html_entity_decode(' ', 0, 'UTF-8'),
html_entity_decode(' ', 0, 'UTF-8'), // narrow non-breaking space
],
' ',
trim($input)

View File

@ -350,7 +350,7 @@ class DBMoneyTest extends SapphireTest
*/
protected function clean($input)
{
$nbsp = html_entity_decode(' ', null, 'UTF-8');
$nbsp = html_entity_decode(' ', 0, 'UTF-8');
return str_replace(' ', $nbsp, trim($input));
}
}