Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Various fixes for PHP 8.1 compatibility #10275

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Control/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use SilverStripe\View\ThemeResourceLoader;
use SilverStripe\View\ViewableData;
use Swift_Message;
use Swift_Mime_SimpleMessage;
use Swift_MimePart;

/**
Expand Down Expand Up @@ -260,7 +261,10 @@ public function __construct(
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;
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/FieldType/DBText.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function ContextSummary(
$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)));
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved

if ($position > 0) {
// We don't want to start mid-word
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Queries/SQLConditionalExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ protected function mergesort(&$array, $cmpFunction = 'strcmp')
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
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Forms/DateFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ public function testValidateMinDateStrtotime()
{
$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');
}

public function testValidateMaxDateStrtotime()
{
$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');
}

Expand Down