Skip to content

Commit

Permalink
Merge pull request #10275 from creative-commoners/pulls/4/p81fix
Browse files Browse the repository at this point in the history
ENH Various fixes for PHP 8.1 compatibility
  • Loading branch information
GuySartorelli authored Apr 13, 2022
2 parents 6639fed + f167878 commit 7143861
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
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)));

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

0 comments on commit 7143861

Please sign in to comment.