ENH Various fixes for PHP 8.1 compatibility

This commit is contained in:
Steve Boyd 2022-04-11 17:22:22 +12:00
parent 3e5a74c6b2
commit f1678781a2
4 changed files with 11 additions and 7 deletions

View File

@ -19,6 +19,7 @@ use SilverStripe\View\SSViewer;
use SilverStripe\View\ThemeResourceLoader;
use SilverStripe\View\ViewableData;
use Swift_Message;
use Swift_Mime_SimpleMessage;
use Swift_MimePart;
/**
@ -260,7 +261,10 @@ class Email extends ViewableData
public function getSwiftMessage()
{
if (!$this->swiftMessage) {
$this->setSwiftMessage(new Swift_Message(null, null, 'text/html', 'utf-8'));
$message = new Swift_Message(null, null, 'text/html', 'utf-8');
// Set priority to fix PHP 8.1 SimpleMessage::getPriority() sscanf() null parameter
$message->setPriority(Swift_Mime_SimpleMessage::PRIORITY_NORMAL);
$this->setSwiftMessage($message);
}
return $this->swiftMessage;

View File

@ -213,7 +213,7 @@ class DBText extends DBString
$position = empty($keywords) ? 0 : (int) mb_stripos($text, $keywords);
// We want to search string to be in the middle of our block to give it some context
$position = max(0, $position - ($characters / 2));
$position = floor(max(0, $position - ($characters / 2)));
if ($position > 0) {
// We don't want to start mid-word

View File

@ -384,7 +384,7 @@ abstract class SQLConditionalExpression extends SQLExpression
return;
}
// Split the array in half
$halfway = count($array) / 2;
$halfway = floor(count($array) / 2);
$array1 = array_slice($array, 0, $halfway);
$array2 = array_slice($array, $halfway);
// Recurse to sort the two halves

View File

@ -46,12 +46,12 @@ class DateFieldTest extends SapphireTest
{
$f = new DateField('Date');
$f->setMinDate('-7 days');
$f->setValue(strftime('%Y-%m-%d', strtotime('-8 days', DBDatetime::now()->getTimestamp())));
$f->setValue(date('Y-m-d', strtotime('-8 days', DBDatetime::now()->getTimestamp())));
$this->assertFalse($f->validate(new RequiredFields()), 'Date below min date, with strtotime');
$f = new DateField('Date');
$f->setMinDate('-7 days');
$f->setValue(strftime('%Y-%m-%d', strtotime('-7 days', DBDatetime::now()->getTimestamp())));
$f->setValue(date('Y-m-d', strtotime('-7 days', DBDatetime::now()->getTimestamp())));
$this->assertTrue($f->validate(new RequiredFields()), 'Date matching min date, with strtotime');
}
@ -59,12 +59,12 @@ class DateFieldTest extends SapphireTest
{
$f = new DateField('Date');
$f->setMaxDate('7 days');
$f->setValue(strftime('%Y-%m-%d', strtotime('8 days', DBDatetime::now()->getTimestamp())));
$f->setValue(date('Y-m-d', strtotime('8 days', DBDatetime::now()->getTimestamp())));
$this->assertFalse($f->validate(new RequiredFields()), 'Date above max date, with strtotime');
$f = new DateField('Date');
$f->setMaxDate('7 days');
$f->setValue(strftime('%Y-%m-%d', strtotime('7 days', DBDatetime::now()->getTimestamp())));
$f->setValue(date('Y-m-d', strtotime('7 days', DBDatetime::now()->getTimestamp())));
$this->assertTrue($f->validate(new RequiredFields()), 'Date matching max date, with strtotime');
}