Compare commits

...

2 Commits

Author SHA1 Message Date
Guy Sartorelli
bb158e4f2e
Merge pull request #2730 from creative-commoners/pulls/4/php81
ENH PHP 8.1 compatibility
2022-04-22 16:18:11 +12:00
Steve Boyd
1b0b2154b4 ENH PHP 8.1 compatibility 2022-04-13 17:07:59 +12:00
40 changed files with 203 additions and 203 deletions

View File

@ -57,6 +57,6 @@ class CMSBatchAction_Restore extends CMSBatchAction
// Get pages that exist in stage and remove them from the restore-able set // Get pages that exist in stage and remove them from the restore-able set
$stageIDs = Versioned::get_by_stage($this->managedClass, Versioned::DRAFT)->column('ID'); $stageIDs = Versioned::get_by_stage($this->managedClass, Versioned::DRAFT)->column('ID');
return array_values(array_diff($ids, $stageIDs)); return array_values(array_diff($ids ?? [], $stageIDs));
} }
} }

View File

@ -184,7 +184,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
{ {
// set reading lang // set reading lang
if (SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) { if (SiteTree::has_extension('Translatable') && !$this->getRequest()->isAjax()) {
Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages(SiteTree::class))); Translatable::choose_site_locale(array_keys(Translatable::get_existing_content_languages(SiteTree::class) ?? []));
} }
parent::init(); parent::init();
@ -454,7 +454,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
]; ];
$link = Controller::join_links( $link = Controller::join_links(
$link, $link,
array_filter(array_values($params)) ? '?' . http_build_query($params) : null array_filter(array_values($params ?? [])) ? '?' . http_build_query($params) : null
); );
$this->extend('updateLinkWithSearch', $link); $this->extend('updateLinkWithSearch', $link);
return $link; return $link;
@ -470,7 +470,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
} }
if ($placeholders) { if ($placeholders) {
$link .= (strpos($link, '?') === false ? "?$placeholders" : "&$placeholders"); $link .= (strpos($link ?? '', '?') === false ? "?$placeholders" : "&$placeholders");
} }
return $link; return $link;
@ -627,7 +627,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Get status flag classes // Get status flag classes
$flags = $node->getStatusFlags(); $flags = $node->getStatusFlags();
if ($flags) { if ($flags) {
$statuses = array_keys($flags); $statuses = array_keys($flags ?? []);
foreach ($statuses as $s) { foreach ($statuses as $s) {
$classes .= ' status-' . $s; $classes .= ' status-' . $s;
} }
@ -642,7 +642,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$classes .= ' ' . $filterClasses; $classes .= ' ' . $filterClasses;
} }
return trim($classes); return trim($classes ?? '');
} }
/** /**
@ -664,8 +664,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
); );
// Trim off the outer tag // Trim off the outer tag
$html = preg_replace('/^[\s\t\r\n]*<ul[^>]*>/', '', $html); $html = preg_replace('/^[\s\t\r\n]*<ul[^>]*>/', '', $html ?? '');
$html = preg_replace('/<\/ul[^>]*>[\s\t\r\n]*$/', '', $html); $html = preg_replace('/<\/ul[^>]*>[\s\t\r\n]*$/', '', $html ?? '');
return $html; return $html;
} }
@ -682,7 +682,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function updatetreenodes($request) public function updatetreenodes($request)
{ {
$data = []; $data = [];
$ids = explode(',', $request->getVar('ids')); $ids = explode(',', $request->getVar('ids') ?? '');
foreach ($ids as $id) { foreach ($ids as $id) {
if ($id === "") { if ($id === "") {
continue; // $id may be a blank string, which is invalid and should be skipped over continue; // $id may be a blank string, which is invalid and should be skipped over
@ -824,7 +824,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->getResponse()->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode(_t(__CLASS__.'.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.')) rawurlencode(_t(__CLASS__.'.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.') ?? '')
); );
} }
@ -852,7 +852,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->getResponse()->addHeader( $this->getResponse()->addHeader(
'X-Status', 'X-Status',
rawurlencode(_t(__CLASS__.'.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.')) rawurlencode(_t(__CLASS__.'.REORGANISATIONSUCCESSFUL', 'Reorganised the site tree successfully.') ?? '')
); );
} }
@ -923,7 +923,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$searchParams = array_combine(array_map(function ($key) { $searchParams = array_combine(array_map(function ($key) {
return 'Search__' . $key; return 'Search__' . $key;
}, array_keys($searchParams)), $searchParams); }, array_keys($searchParams ?? [])), $searchParams ?? []);
$schema = [ $schema = [
'formSchemaUrl' => $schemaUrl, 'formSchemaUrl' => $schemaUrl,
@ -1082,7 +1082,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Add all ancestors // Add all ancestors
$ancestors = $record->getAncestors(); $ancestors = $record->getAncestors();
$ancestors = new ArrayList(array_reverse($ancestors->toArray())); $ancestors = new ArrayList(array_reverse($ancestors->toArray() ?? []));
$ancestors->push($record); $ancestors->push($record);
/** @var SiteTree $ancestor */ /** @var SiteTree $ancestor */
foreach ($ancestors as $ancestor) { foreach ($ancestors as $ancestor) {
@ -1144,7 +1144,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Check if can be created at the root // Check if can be created at the root
$needsPerm = $obj->config()->get('need_permission'); $needsPerm = $obj->config()->get('need_permission');
if (!$obj->config()->get('can_be_root') if (!$obj->config()->get('can_be_root')
|| (!array_key_exists($class, $canCreate) || !$canCreate[$class]) || (!array_key_exists($class, $canCreate ?? []) || !$canCreate[$class])
|| ($needsPerm && !$this->can($needsPerm)) || ($needsPerm && !$this->can($needsPerm))
) { ) {
$def['Root']['disallowedChildren'][] = $class; $def['Root']['disallowedChildren'][] = $class;
@ -1226,7 +1226,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if ($id instanceof $treeClass) { if ($id instanceof $treeClass) {
return $id; return $id;
} }
if (substr($id, 0, 3) == 'new') { if (substr($id ?? '', 0, 3) == 'new') {
return $this->getNewItem($id); return $this->getNewItem($id);
} }
if (!is_numeric($id)) { if (!is_numeric($id)) {
@ -1459,18 +1459,18 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Count number of affected change set // Count number of affected change set
$affectedChangeSetCount = 0; $affectedChangeSetCount = 0;
if (count($inChangeSetIDs) > 0) { if (count($inChangeSetIDs ?? []) > 0) {
$affectedChangeSetCount = ChangeSet::get() $affectedChangeSetCount = ChangeSet::get()
->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN]) ->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN])
->count(); ->count();
} }
$numCampaigns = ChangeSet::singleton()->i18n_pluralise($affectedChangeSetCount); $numCampaigns = ChangeSet::singleton()->i18n_pluralise($affectedChangeSetCount);
$numCampaigns = mb_strtolower($numCampaigns); $numCampaigns = mb_strtolower($numCampaigns ?? '');
if (count($descendants) > 0 && $affectedChangeSetCount > 0) { if (count($descendants ?? []) > 0 && $affectedChangeSetCount > 0) {
$archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildrenAndCampaigns', 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]); $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithChildrenAndCampaigns', 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
} elseif (count($descendants) > 0) { } elseif (count($descendants ?? []) > 0) {
$archiveWarningMsg = $defaultMessage; $archiveWarningMsg = $defaultMessage;
} elseif ($affectedChangeSetCount > 0) { } elseif ($affectedChangeSetCount > 0) {
$archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithCampaigns', 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]); $archiveWarningMsg = _t('SilverStripe\\CMS\\Controllers\\CMSMain.ArchiveWarningWithCampaigns', 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]);
@ -1693,9 +1693,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
); );
$breadcrumbs = $item->Breadcrumbs(20, true, false, true, '/'); $breadcrumbs = $item->Breadcrumbs(20, true, false, true, '/');
// Remove item's tile // Remove item's tile
$breadcrumbs = preg_replace('/[^\/]+$/', '', trim($breadcrumbs)); $breadcrumbs = preg_replace('/[^\/]+$/', '', trim($breadcrumbs ?? ''));
// Trim spaces around delimiters // Trim spaces around delimiters
$breadcrumbs = preg_replace('/\s?\/\s?/', '/', trim($breadcrumbs)); $breadcrumbs = preg_replace('/\s?\/\s?/', '/', trim($breadcrumbs ?? ''));
return $title . sprintf('<p class="small cms-list__item-breadcrumbs">%s</p>', $breadcrumbs); return $title . sprintf('<p class="small cms-list__item-breadcrumbs">%s</p>', $breadcrumbs);
} }
]); ]);
@ -1752,7 +1752,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Existing or new record? // Existing or new record?
$id = $data['ID']; $id = $data['ID'];
if (substr($id, 0, 3) != 'new') { if (substr($id ?? '', 0, 3) != 'new') {
/** @var SiteTree $record */ /** @var SiteTree $record */
$record = DataObject::get_by_id($className, $id); $record = DataObject::get_by_id($className, $id);
// Check edit permissions // Check edit permissions
@ -1810,7 +1810,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
); );
} }
$this->getResponse()->addHeader('X-Status', rawurlencode($message)); $this->getResponse()->addHeader('X-Status', rawurlencode($message ?? ''));
return $this->getResponseNegotiator()->respond($this->getRequest()); return $this->getResponseNegotiator()->respond($this->getRequest());
} }
@ -1825,9 +1825,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function getNewItem($id, $setID = true) public function getNewItem($id, $setID = true)
{ {
$parentClass = $this->config()->get('tree_class'); $parentClass = $this->config()->get('tree_class');
list(, $className, $parentID) = array_pad(explode('-', $id), 3, null); list(, $className, $parentID) = array_pad(explode('-', $id ?? ''), 3, null);
if (!is_a($className, $parentClass, true)) { if (!is_a($className, $parentClass ?? '', true)) {
$response = Security::permissionFailure($this); $response = Security::permissionFailure($this);
if (!$response) { if (!$response) {
$response = $this->getResponse(); $response = $this->getResponse();
@ -1931,7 +1931,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
"Restored '{title}' successfully", "Restored '{title}' successfully",
'Param {title} is a title', 'Param {title} is a title',
['title' => $record->Title] ['title' => $record->Title]
)) ) ?? '')
); );
return $this->getResponseNegotiator()->respond($this->getRequest()); return $this->getResponseNegotiator()->respond($this->getRequest());
@ -1967,7 +1967,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.REMOVEDPAGEFROMDRAFT', __CLASS__ . '.REMOVEDPAGEFROMDRAFT',
"Removed '{title}' from the draft site", "Removed '{title}' from the draft site",
['title' => $record->Title] ['title' => $record->Title]
)) ) ?? '')
); );
// Even if the record has been deleted from stage and live, it can be viewed in "archive mode" // Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
@ -2003,7 +2003,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.ARCHIVEDPAGE', __CLASS__ . '.ARCHIVEDPAGE',
"Archived page '{title}'", "Archived page '{title}'",
['title' => $record->Title] ['title' => $record->Title]
)) ) ?? '')
); );
// Even if the record has been deleted from stage and live, it can be viewed in "archive mode" // Even if the record has been deleted from stage and live, it can be viewed in "archive mode"
@ -2038,7 +2038,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.REMOVEDPAGE', __CLASS__ . '.REMOVEDPAGE',
"Removed '{title}' from the published site", "Removed '{title}' from the published site",
['title' => $record->Title] ['title' => $record->Title]
)) ) ?? '')
); );
return $this->getResponseNegotiator()->respond($this->getRequest()); return $this->getResponseNegotiator()->respond($this->getRequest());
@ -2091,7 +2091,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
); );
} }
$this->getResponse()->addHeader('X-Status', rawurlencode($message)); $this->getResponse()->addHeader('X-Status', rawurlencode($message ?? ''));
// Can be used in different contexts: In normal page edit view, in which case the redirect won't have any effect. // Can be used in different contexts: In normal page edit view, in which case the redirect won't have any effect.
// Or in history view, in which case a revert causes the CMS to re-load the edit view. // Or in history view, in which case a revert causes the CMS to re-load the edit view.
@ -2242,7 +2242,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.RESTORED', __CLASS__ . '.RESTORED',
"Restored '{title}' successfully", "Restored '{title}' successfully",
['title' => $restoredPage->Title] ['title' => $restoredPage->Title]
)) ) ?? '')
); );
return $this->getResponseNegotiator()->respond($this->getRequest()); return $this->getResponseNegotiator()->respond($this->getRequest());
@ -2280,7 +2280,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.DUPLICATED', __CLASS__ . '.DUPLICATED',
"Duplicated '{title}' successfully", "Duplicated '{title}' successfully",
['title' => $newPage->Title] ['title' => $newPage->Title]
)) ) ?? '')
); );
$url = $newPage->CMSEditLink(); $url = $newPage->CMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url); $this->getResponse()->addHeader('X-ControllerURL', $url);
@ -2318,7 +2318,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
__CLASS__ . '.DUPLICATEDWITHCHILDREN', __CLASS__ . '.DUPLICATEDWITHCHILDREN',
"Duplicated '{title}' and children successfully", "Duplicated '{title}' and children successfully",
['title' => $newPage->Title] ['title' => $newPage->Title]
)) ) ?? '')
); );
$url = $newPage->CMSEditLink(); $url = $newPage->CMSEditLink();
$this->getResponse()->addHeader('X-ControllerURL', $url); $this->getResponse()->addHeader('X-ControllerURL', $url);
@ -2370,7 +2370,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$this->extend('updateHintsCacheKey', $baseKey); $this->extend('updateHintsCacheKey', $baseKey);
return md5($baseKey); return md5($baseKey ?? '');
} }
/** /**

View File

@ -112,7 +112,7 @@ class CMSPageAddController extends CMSPageEditController
"PageType", "PageType",
DBField::create_field( DBField::create_field(
'HTMLFragment', 'HTMLFragment',
sprintf($numericLabelTmpl, 2, _t('SilverStripe\\CMS\\Controllers\\CMSMain.ChoosePageType', 'Choose page type')) sprintf($numericLabelTmpl ?? '', 2, _t('SilverStripe\\CMS\\Controllers\\CMSMain.ChoosePageType', 'Choose page type'))
), ),
$pageTypes, $pageTypes,
'Page' 'Page'
@ -121,7 +121,7 @@ class CMSPageAddController extends CMSPageEditController
$parentModeField->setTitle(DBField::create_field( $parentModeField->setTitle(DBField::create_field(
'HTMLFragment', 'HTMLFragment',
sprintf($numericLabelTmpl, 1, _t('SilverStripe\\CMS\\Controllers\\CMSMain.ChoosePageParentMode', 'Choose where to create this page')) sprintf($numericLabelTmpl ?? '', 1, _t('SilverStripe\\CMS\\Controllers\\CMSMain.ChoosePageParentMode', 'Choose where to create this page'))
)); ));
$parentField->setSearchFunction(function ($sourceObject, $labelField, $search) { $parentField->setSearchFunction(function ($sourceObject, $labelField, $search) {

View File

@ -55,7 +55,7 @@ class CMSPagesController extends CMSMain
$params['ParentID'] = $page->ID; $params['ParentID'] = $page->ID;
$item = new stdClass(); $item = new stdClass();
$item->Title = $page->Title; $item->Title = $page->Title;
$item->Link = Controller::join_links($this->Link(), '?' . http_build_query($params)); $item->Link = Controller::join_links($this->Link(), '?' . http_build_query($params ?? []));
$items->push(new ArrayData($item)); $items->push(new ArrayData($item));
} }
} }

View File

@ -90,7 +90,7 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
uasort($filterMap, function ($a, $b) { uasort($filterMap, function ($a, $b) {
return ($a === CMSSiteTreeFilter_Search::title()) return ($a === CMSSiteTreeFilter_Search::title())
? -1 ? -1
: strcasecmp($a, $b); : strcasecmp($a ?? '', $b ?? '');
}); });
return $filterMap; return $filterMap;
@ -164,7 +164,7 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
while (!empty($parents)) { while (!empty($parents)) {
$q = Versioned::get_including_deleted(SiteTree::class) $q = Versioned::get_including_deleted(SiteTree::class)
->byIDs(array_keys($parents)); ->byIDs(array_keys($parents ?? []));
$list = $q->map('ID', 'ParentID'); $list = $q->map('ID', 'ParentID');
$parents = []; $parents = [];
foreach ($list as $id => $parentID) { foreach ($list as $id => $parentID) {

View File

@ -156,7 +156,7 @@ class ContentController extends Controller
$getVars = $_GET; $getVars = $_GET;
unset($getVars['url']); unset($getVars['url']);
if ($getVars) { if ($getVars) {
$url = "?" . http_build_query($getVars); $url = "?" . http_build_query($getVars ?? []);
} else { } else {
$url = ""; $url = "";
} }
@ -494,7 +494,7 @@ HTML;
// TODO Allow this to work when allow_url_fopen=0 // TODO Allow this to work when allow_url_fopen=0
if (isset($_SESSION['StatsID']) && $_SESSION['StatsID']) { if (isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
$url = 'http://ss2stat.silverstripe.com/Installation/installed?ID=' . $_SESSION['StatsID']; $url = 'http://ss2stat.silverstripe.com/Installation/installed?ID=' . $_SESSION['StatsID'];
@file_get_contents($url); @file_get_contents($url ?? '');
} }
global $project; global $project;
@ -532,11 +532,11 @@ HTML;
$unsuccessful = new ArrayList(); $unsuccessful = new ArrayList();
foreach ($installfiles as $installfile) { foreach ($installfiles as $installfile) {
$installfilepath = PUBLIC_PATH . '/' . $installfile; $installfilepath = PUBLIC_PATH . '/' . $installfile;
if (file_exists($installfilepath)) { if (file_exists($installfilepath ?? '')) {
@unlink($installfilepath); @unlink($installfilepath ?? '');
} }
if (file_exists($installfilepath)) { if (file_exists($installfilepath ?? '')) {
$unsuccessful->push(new ArrayData(['File' => $installfile])); $unsuccessful->push(new ArrayData(['File' => $installfile]));
} }
} }

View File

@ -41,8 +41,8 @@ class ModelAsController extends Controller implements NestedController
{ {
$controller = $sitetree->getControllerName(); $controller = $sitetree->getControllerName();
if ($action && class_exists($controller . '_' . ucfirst($action))) { if ($action && class_exists($controller . '_' . ucfirst($action ?? ''))) {
$controller = $controller . '_' . ucfirst($action); $controller = $controller . '_' . ucfirst($action ?? '');
} }
return Injector::inst()->create($controller, $sitetree); return Injector::inst()->create($controller, $sitetree);
@ -131,7 +131,7 @@ class ModelAsController extends Controller implements NestedController
// url encode unless it's multibyte (already pre-encoded in the database) // url encode unless it's multibyte (already pre-encoded in the database)
$filter = URLSegmentFilter::create(); $filter = URLSegmentFilter::create();
if (!$filter->getAllowMultibyte()) { if (!$filter->getAllowMultibyte()) {
$URLSegment = rawurlencode($URLSegment); $URLSegment = rawurlencode($URLSegment ?? '');
} }
// Select child page // Select child page

View File

@ -23,8 +23,8 @@ class OldPageRedirector extends Extension
public function onBeforeHTTPError404($request) public function onBeforeHTTPError404($request)
{ {
// We need to get the URL ourselves because $request->allParams() only has a max of 4 params // We need to get the URL ourselves because $request->allParams() only has a max of 4 params
$params = preg_split('|/+|', $request->getURL()); $params = preg_split('|/+|', $request->getURL() ?? '');
$cleanURL = trim(Director::makeRelative($request->getURL(false)), '/'); $cleanURL = trim(Director::makeRelative($request->getURL(false)) ?? '', '/');
$getvars = $request->getVars(); $getvars = $request->getVars();
unset($getvars['url']); unset($getvars['url']);
@ -33,7 +33,7 @@ class OldPageRedirector extends Extension
if (!$page) { if (!$page) {
$page = self::find_old_page($params); $page = self::find_old_page($params);
} }
$cleanPage = trim(Director::makeRelative($page), '/'); $cleanPage = trim(Director::makeRelative($page) ?? '', '/');
if (!$cleanPage) { if (!$cleanPage) {
$cleanPage = Director::makeRelative(RootURLController::get_homepage_link()); $cleanPage = Director::makeRelative(RootURLController::get_homepage_link());
} }
@ -64,7 +64,7 @@ class OldPageRedirector extends Extension
{ {
$parent = is_numeric($parent) && $parent > 0 ? SiteTree::get()->byID($parent) : $parent; $parent = is_numeric($parent) && $parent > 0 ? SiteTree::get()->byID($parent) : $parent;
$params = (array)$params; $params = (array)$params;
$URL = rawurlencode(array_shift($params)); $URL = rawurlencode(array_shift($params) ?? '');
if (empty($URL)) { if (empty($URL)) {
return false; return false;
} }
@ -93,7 +93,7 @@ class OldPageRedirector extends Extension
} }
if ($page && $page->canView()) { if ($page && $page->canView()) {
if (count($params)) { if (count($params ?? [])) {
// We have to go deeper! // We have to go deeper!
$ret = self::find_old_page($params, $page, $redirect); $ret = self::find_old_page($params, $page, $redirect);
if ($ret) { if ($ret) {

View File

@ -56,7 +56,7 @@ class RootURLController extends Controller implements Resettable
*/ */
public static function should_be_on_root(SiteTree $page) public static function should_be_on_root(SiteTree $page)
{ {
return (!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true), '/')); return (!self::$is_at_root && self::get_homepage_link() == trim($page->RelativeLink(true) ?? '', '/'));
} }
/** /**

View File

@ -67,7 +67,7 @@ class SilverStripeNavigator extends ViewableData
ksort($items); ksort($items);
// Drop the keys and let the ArrayList handle the numbering, so $First, $Last and others work properly. // Drop the keys and let the ArrayList handle the numbering, so $First, $Last and others work properly.
return new ArrayList(array_values($items)); return new ArrayList(array_values($items ?? []));
} }
/** /**

View File

@ -20,7 +20,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem
$linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.ARCHIVEDSITE', 'Preview version'); $linkTitle = _t('SilverStripe\\CMS\\Controllers\\ContentController.ARCHIVEDSITE', 'Preview version');
$recordLink = Convert::raw2att(Controller::join_links( $recordLink = Convert::raw2att(Controller::join_links(
$this->record->AbsoluteLink(), $this->record->AbsoluteLink(),
'?archiveDate=' . urlencode($this->record->LastEdited) '?archiveDate=' . urlencode($this->record->LastEdited ?? '')
)); ));
return "<a class=\"{$linkClass}\" href=\"$recordLink\" target=\"_blank\">$linkTitle</a>"; return "<a class=\"{$linkClass}\" href=\"$recordLink\" target=\"_blank\">$linkTitle</a>";
} }
@ -48,7 +48,7 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem
{ {
return Controller::join_links( return Controller::join_links(
$this->record->PreviewLink(), $this->record->PreviewLink(),
'?archiveDate=' . urlencode($this->record->LastEdited) '?archiveDate=' . urlencode($this->record->LastEdited ?? '')
); );
} }

View File

@ -44,7 +44,7 @@ class SiteTreeURLSegmentField extends TextField
public function Value() public function Value()
{ {
return rawurldecode($this->value); return rawurldecode($this->value ?? '');
} }
public function getAttributes() public function getAttributes()
@ -82,7 +82,7 @@ class SiteTreeURLSegmentField extends TextField
$page->URLSegment = $page->generateURLSegment($request->getVar('value')); $page->URLSegment = $page->generateURLSegment($request->getVar('value'));
$count = 2; $count = 2;
while (!$page->validURLSegment()) { while (!$page->validURLSegment()) {
$page->URLSegment = preg_replace('/-[0-9]+$/', '', $page->URLSegment) . '-' . $count; $page->URLSegment = preg_replace('/-[0-9]+$/', '', $page->URLSegment ?? '') . '-' . $count;
$count++; $count++;
} }

View File

@ -173,8 +173,8 @@ class RedirectorPage extends Page
{ {
parent::onBeforeWrite(); parent::onBeforeWrite();
if ($this->ExternalURL && substr($this->ExternalURL, 0, 2) !== '//') { if ($this->ExternalURL && substr($this->ExternalURL ?? '', 0, 2) !== '//') {
$urlParts = parse_url($this->ExternalURL); $urlParts = parse_url($this->ExternalURL ?? '');
if ($urlParts) { if ($urlParts) {
if (empty($urlParts['scheme'])) { if (empty($urlParts['scheme'])) {
// no scheme, assume http // no scheme, assume http

View File

@ -446,16 +446,16 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$urlSegmentExpr = sprintf('"%s"."URLSegment"', $tableName); $urlSegmentExpr = sprintf('"%s"."URLSegment"', $tableName);
$parentIDExpr = sprintf('"%s"."ParentID"', $tableName); $parentIDExpr = sprintf('"%s"."ParentID"', $tableName);
$link = trim(Director::makeRelative($link), '/'); $link = trim(Director::makeRelative($link) ?? '', '/');
if (!$link) { if (!$link) {
$link = RootURLController::get_homepage_link(); $link = RootURLController::get_homepage_link();
} }
$parts = preg_split('|/+|', $link); $parts = preg_split('|/+|', $link ?? '');
// Grab the initial root level page to traverse down from. // Grab the initial root level page to traverse down from.
$URLSegment = array_shift($parts); $URLSegment = array_shift($parts);
$conditions = [$urlSegmentExpr => rawurlencode($URLSegment)]; $conditions = [$urlSegmentExpr => rawurlencode($URLSegment ?? '')];
if (self::config()->get('nested_urls')) { if (self::config()->get('nested_urls')) {
$conditions[] = [$parentIDExpr => 0]; $conditions[] = [$parentIDExpr => 0];
} }
@ -490,7 +490,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
} }
// Check if we have any more URL parts to parse. // Check if we have any more URL parts to parse.
if (!self::config()->get('nested_urls') || !count($parts)) { if (!self::config()->get('nested_urls') || !count($parts ?? [])) {
return $sitetree; return $sitetree;
} }
@ -537,7 +537,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{ {
$classes = ClassInfo::getValidSubClasses(); $classes = ClassInfo::getValidSubClasses();
$baseClassIndex = array_search(self::class, $classes); $baseClassIndex = array_search(self::class, $classes ?? []);
if ($baseClassIndex !== false) { if ($baseClassIndex !== false) {
unset($classes[$baseClassIndex]); unset($classes[$baseClassIndex]);
} }
@ -558,10 +558,10 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// If any of the descendents don't want any of the elders to show up, cruelly render the elders surplus to // If any of the descendents don't want any of the elders to show up, cruelly render the elders surplus to
// requirements // requirements
if ($kill_ancestors) { if ($kill_ancestors) {
$kill_ancestors = array_unique($kill_ancestors); $kill_ancestors = array_unique($kill_ancestors ?? []);
foreach ($kill_ancestors as $mark) { foreach ($kill_ancestors as $mark) {
// unset from $classes // unset from $classes
$idx = array_search($mark, $classes, true); $idx = array_search($mark, $classes ?? [], true);
if ($idx !== false) { if ($idx !== false) {
unset($classes[$idx]); unset($classes[$idx]);
} }
@ -749,7 +749,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/ */
public function ElementName() public function ElementName()
{ {
return str_replace('/', '-', trim($this->RelativeLink(true), '/')); return str_replace('/', '-', trim($this->RelativeLink(true) ?? '', '/'));
} }
/** /**
@ -778,7 +778,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
public function isSection() public function isSection()
{ {
return $this->isCurrent() || ( return $this->isCurrent() || (
Director::get_current_page() instanceof SiteTree && in_array($this->ID, Director::get_current_page()->getAncestors()->column()) Director::get_current_page() instanceof SiteTree && in_array($this->ID, Director::get_current_page()->getAncestors()->column() ?? [])
); );
} }
@ -947,7 +947,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
while ($page while ($page
&& $page->exists() && $page->exists()
&& (!$maxDepth || count($pages) < $maxDepth) && (!$maxDepth || count($pages ?? []) < $maxDepth)
&& (!$stopAtPageType || $page->ClassName != $stopAtPageType) && (!$stopAtPageType || $page->ClassName != $stopAtPageType)
) { ) {
if ($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) { if ($showHidden || $page->ShowInMenus || ($page->ID == $this->ID)) {
@ -957,7 +957,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$page = $page->Parent(); $page = $page->Parent();
} }
return new ArrayList(array_reverse($pages)); return new ArrayList(array_reverse($pages ?? []));
} }
@ -1029,7 +1029,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$item = $item->getParent(); $item = $item->getParent();
$level--; $level--;
} }
return implode($separator, array_reverse($parts)); return implode($separator ?? '', array_reverse($parts ?? []));
} }
/** /**
@ -1059,8 +1059,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
return true; return true;
} }
if (is_string($perm) && method_exists($this, 'can' . ucfirst($perm))) { if (is_string($perm) && method_exists($this, 'can' . ucfirst($perm ?? ''))) {
$method = 'can' . ucfirst($perm); $method = 'can' . ucfirst($perm ?? '');
return $this->$method($member); return $this->$method($member);
} }
@ -1282,7 +1282,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// Block children not allowed for this parent type // Block children not allowed for this parent type
$parent = isset($context['Parent']) ? $context['Parent'] : null; $parent = isset($context['Parent']) ? $context['Parent'] : null;
$strictParentInstance = ($parent && $parent instanceof SiteTree); $strictParentInstance = ($parent && $parent instanceof SiteTree);
if ($strictParentInstance && !in_array(static::class, $parent->allowedChildren())) { if ($strictParentInstance && !in_array(static::class, $parent->allowedChildren() ?? [])) {
return false; return false;
} }
@ -1357,7 +1357,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
public function getSiteConfig() public function getSiteConfig()
{ {
$configs = $this->invokeWithExtensions('alternateSiteConfig'); $configs = $this->invokeWithExtensions('alternateSiteConfig');
foreach (array_filter($configs) as $config) { foreach (array_filter($configs ?? []) as $config) {
return $config; return $config;
} }
@ -1488,7 +1488,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/ */
private function getGenerator(): string private function getGenerator(): string
{ {
$generator = trim(Config::inst()->get(self::class, 'meta_generator')); $generator = trim(Config::inst()->get(self::class, 'meta_generator') ?? '');
if ($generator === '') { if ($generator === '') {
return ''; return '';
} }
@ -1496,7 +1496,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$version = $this->getVersionProvider()->getModuleVersion('silverstripe/framework'); $version = $this->getVersionProvider()->getModuleVersion('silverstripe/framework');
// Only include stable version numbers so as not to clutter any aggregate reports // Only include stable version numbers so as not to clutter any aggregate reports
// with non-standard versions e.g. forks // with non-standard versions e.g. forks
if (preg_match('#^([0-9]+\.[0-9]+)\.[0-9]+$#', $version, $m)) { if (preg_match('#^([0-9]+\.[0-9]+)\.[0-9]+$#', $version ?? '', $m)) {
$generator .= ' ' . $m[1]; $generator .= ' ' . $m[1];
} }
} }
@ -1533,7 +1533,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{ {
$tags = []; $tags = [];
$tagsArray = $this->MetaComponents(); $tagsArray = $this->MetaComponents();
if (!$includeTitle || strtolower($includeTitle) == 'false') { if (!$includeTitle || strtolower($includeTitle ?? '') == 'false') {
unset($tagsArray['title']); unset($tagsArray['title']);
} }
@ -1668,19 +1668,19 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// Ensure that this object has a non-conflicting URLSegment value. // Ensure that this object has a non-conflicting URLSegment value.
$count = 2; $count = 2;
while (!$this->validURLSegment()) { while (!$this->validURLSegment()) {
$this->URLSegment = preg_replace('/-[0-9]+$/', '', $this->URLSegment) . '-' . $count; $this->URLSegment = preg_replace('/-[0-9]+$/', '', $this->URLSegment ?? '') . '-' . $count;
$count++; $count++;
} }
// Check to see if we've only altered fields that shouldn't affect versioning // Check to see if we've only altered fields that shouldn't affect versioning
$fieldsIgnoredByVersioning = ['HasBrokenLink', 'Status', 'HasBrokenFile', 'ToDo', 'VersionID', 'SaveCount']; $fieldsIgnoredByVersioning = ['HasBrokenLink', 'Status', 'HasBrokenFile', 'ToDo', 'VersionID', 'SaveCount'];
$changedFields = array_keys($this->getChangedFields(true, 2)); $changedFields = array_keys($this->getChangedFields(true, 2) ?? []);
// This more rigorous check is inline with the test that write() does to decide whether or not to write to the // This more rigorous check is inline with the test that write() does to decide whether or not to write to the
// DB. We use that to avoid cluttering the system with a migrateVersion() call that doesn't get used // DB. We use that to avoid cluttering the system with a migrateVersion() call that doesn't get used
$oneChangedFields = array_keys($this->getChangedFields(true, 1)); $oneChangedFields = array_keys($this->getChangedFields(true, 1) ?? []);
if ($oneChangedFields && !array_diff($changedFields, $fieldsIgnoredByVersioning)) { if ($oneChangedFields && !array_diff($changedFields ?? [], $fieldsIgnoredByVersioning)) {
$this->setNextWriteWithoutVersion(true); $this->setNextWriteWithoutVersion(true);
} }
@ -1771,7 +1771,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$subject = ($this instanceof VirtualPage && $this->CopyContentFromID) $subject = ($this instanceof VirtualPage && $this->CopyContentFromID)
? $this->CopyContentFrom() ? $this->CopyContentFrom()
: $this; : $this;
if (!in_array($subject->ClassName, $allowed)) { if (!in_array($subject->ClassName, $allowed ?? [])) {
$result->addError( $result->addError(
_t( _t(
'SilverStripe\\CMS\\Model\\SiteTree.PageTypeNotAllowed', 'SilverStripe\\CMS\\Model\\SiteTree.PageTypeNotAllowed',
@ -1820,7 +1820,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
return false; return false;
} }
} }
} elseif (in_array(strtolower($this->URLSegment), $this->getExcludedURLSegments())) { } elseif (in_array(strtolower($this->URLSegment ?? ''), $this->getExcludedURLSegments() ?? [])) {
// Guard against url segments for the base page // Guard against url segments for the base page
// Default to '-2', onBeforeWrite takes care of further possible clashes // Default to '-2', onBeforeWrite takes care of further possible clashes
return false; return false;
@ -2292,7 +2292,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$viewerGroupsField->setDescription(_t( $viewerGroupsField->setDescription(_t(
'SilverStripe\\CMS\\Model\\SiteTree.VIEWER_GROUPS_FIELD_DESC', 'SilverStripe\\CMS\\Model\\SiteTree.VIEWER_GROUPS_FIELD_DESC',
'Groups with global view permissions: {groupList}', 'Groups with global view permissions: {groupList}',
['groupList' => implode(', ', array_values($viewAllGroupsMap))] ['groupList' => implode(', ', array_values($viewAllGroupsMap ?? []))]
)); ));
} }
@ -2300,7 +2300,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$editorGroupsField->setDescription(_t( $editorGroupsField->setDescription(_t(
'SilverStripe\\CMS\\Model\\SiteTree.EDITOR_GROUPS_FIELD_DESC', 'SilverStripe\\CMS\\Model\\SiteTree.EDITOR_GROUPS_FIELD_DESC',
'Groups with global edit permissions: {groupList}', 'Groups with global edit permissions: {groupList}',
['groupList' => implode(', ', array_values($editAllGroupsMap))] ['groupList' => implode(', ', array_values($editAllGroupsMap ?? []))]
)); ));
} }
@ -2638,7 +2638,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
return false; return false;
} }
return stripos($this->ID, 'new') === 0; return stripos($this->ID ?? '', 'new') === 0;
} }
/** /**
@ -2689,9 +2689,9 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
if ($currentClass) { if ($currentClass) {
$currentPageTypeName = $result[$currentClass]; $currentPageTypeName = $result[$currentClass];
unset($result[$currentClass]); unset($result[$currentClass]);
$result = array_reverse($result); $result = array_reverse($result ?? []);
$result[$currentClass] = $currentPageTypeName; $result[$currentClass] = $currentPageTypeName;
$result = array_reverse($result); $result = array_reverse($result ?? []);
} }
return $result; return $result;
@ -2715,7 +2715,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$candidates = Config::inst()->get($class, 'allowed_children', Config::UNINHERITED); $candidates = Config::inst()->get($class, 'allowed_children', Config::UNINHERITED);
break; break;
} }
$class = get_parent_class($class); $class = get_parent_class($class ?? '');
} }
if (!$candidates || $candidates === 'none' || $candidates === 'SiteTree_root') { if (!$candidates || $candidates === 'none' || $candidates === 'SiteTree_root') {
return []; return [];
@ -2726,8 +2726,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
foreach ((array)$candidates as $candidate) { foreach ((array)$candidates as $candidate) {
// If a classname is prefixed by "*", such as "*Page", then only that class is allowed - no subclasses. // If a classname is prefixed by "*", such as "*Page", then only that class is allowed - no subclasses.
// Otherwise, the class and all its subclasses are allowed. // Otherwise, the class and all its subclasses are allowed.
if (substr($candidate, 0, 1) == '*') { if (substr($candidate ?? '', 0, 1) == '*') {
$allowedChildren[] = substr($candidate, 1); $allowedChildren[] = substr($candidate ?? '', 1);
} elseif (($candidate !== 'SiteTree_root') } elseif (($candidate !== 'SiteTree_root')
&& ($subclasses = ClassInfo::subclassesFor($candidate)) && ($subclasses = ClassInfo::subclassesFor($candidate))
) { ) {
@ -2818,7 +2818,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$default = $this->config()->get('default_child'); $default = $this->config()->get('default_child');
$allowed = $this->allowedChildren(); $allowed = $this->allowedChildren();
if ($allowed) { if ($allowed) {
if (!$default || !in_array($default, $allowed)) { if (!$default || !in_array($default, $allowed ?? [])) {
$default = reset($allowed); $default = reset($allowed);
} }
return $default; return $default;
@ -2945,7 +2945,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
Convert::raw2htmlid(static::class), Convert::raw2htmlid(static::class),
$this->isHomePage() ? ' homepage' : '', $this->isHomePage() ? ' homepage' : '',
Convert::raw2att(json_encode($children)), Convert::raw2att(json_encode($children)),
Convert::raw2xml(str_replace(["\n","\r"], "", $this->MenuTitle)) Convert::raw2xml(str_replace(["\n","\r"], "", $this->MenuTitle ?? ''))
); );
foreach ($flags as $class => $data) { foreach ($flags as $class => $data) {
if (is_string($data)) { if (is_string($data)) {
@ -3172,7 +3172,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
if (!$icon) { if (!$icon) {
return null; return null;
} }
if (strpos($icon, 'data:image/') !== false) { if (strpos($icon ?? '', 'data:image/') !== false) {
return $icon; return $icon;
} }
@ -3313,15 +3313,15 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// Build from rules // Build from rules
foreach (Director::config()->get('rules') as $pattern => $rule) { foreach (Director::config()->get('rules') as $pattern => $rule) {
$route = explode('/', $pattern); $route = explode('/', $pattern ?? '');
if (!empty($route) && strpos($route[0], '$') === false) { if (!empty($route) && strpos($route[0] ?? '', '$') === false) {
$excludes[] = strtolower($route[0]); $excludes[] = strtolower($route[0] ?? '');
} }
} }
// Build from base folders // Build from base folders
foreach (glob(Director::publicFolder() . '/*', GLOB_ONLYDIR) as $folder) { foreach (glob(Director::publicFolder() . '/*', GLOB_ONLYDIR) as $folder) {
$excludes[] = strtolower(basename($folder)); $excludes[] = strtolower(basename($folder ?? ''));
} }
$this->extend('updateExcludedURLSegments', $excludes); $this->extend('updateExcludedURLSegments', $excludes);
@ -3335,7 +3335,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{ {
$parseSuccess = preg_match_all( $parseSuccess = preg_match_all(
"/\\s+(name|id)\\s*=\\s*([\"'])([^\\2\\s>]*?)\\2|\\s+(name|id)\\s*=\\s*([^\"']+)[\\s +>]/im", "/\\s+(name|id)\\s*=\\s*([\"'])([^\\2\\s>]*?)\\2|\\s+(name|id)\\s*=\\s*([^\"']+)[\\s +>]/im",
$this->Content, $this->Content ?? '',
$matches $matches
); );

View File

@ -41,7 +41,7 @@ class SiteTreeFolderExtension extends DataExtension
// Get all classes that aren't folder // Get all classes that aren't folder
$fileClasses = array_diff_key( $fileClasses = array_diff_key(
ClassInfo::subclassesFor(File::class), ClassInfo::subclassesFor(File::class) ?? [],
ClassInfo::subclassesFor(Folder::class) ClassInfo::subclassesFor(Folder::class)
); );
@ -58,7 +58,7 @@ class SiteTreeFolderExtension extends DataExtension
$where = []; $where = [];
$columns = []; $columns = [];
foreach ($hasOnes as $relName => $joinClass) { foreach ($hasOnes as $relName => $joinClass) {
if (in_array($joinClass, $fileClasses)) { if (in_array($joinClass, $fileClasses ?? [])) {
$column = $relName . 'ID'; $column = $relName . 'ID';
$columns[] = $column; $columns[] = $column;
$quotedColumn = $schema->sqlColumnForField($className, $column); $quotedColumn = $schema->sqlColumnForField($className, $column);

View File

@ -190,13 +190,13 @@ class SiteTreeLinkTracking extends DataExtension
protected function toggleElementClass(DOMElement $domReference, $class, $toggle) protected function toggleElementClass(DOMElement $domReference, $class, $toggle)
{ {
// Get all existing classes. // Get all existing classes.
$classes = array_filter(explode(' ', trim($domReference->getAttribute('class')))); $classes = array_filter(explode(' ', trim($domReference->getAttribute('class') ?? '')));
// Add or remove the broken class from the link, depending on the link status. // Add or remove the broken class from the link, depending on the link status.
if ($toggle) { if ($toggle) {
$classes = array_unique(array_merge($classes, [$class])); $classes = array_unique(array_merge($classes, [$class]));
} else { } else {
$classes = array_diff($classes, [$class]); $classes = array_diff($classes ?? [], [$class]);
} }
if (!empty($classes)) { if (!empty($classes)) {

View File

@ -59,7 +59,7 @@ class SiteTreeLinkTracking_Parser
// Link to a page on this site. // Link to a page on this site.
$matches = []; $matches = [];
if (preg_match('/\[sitetree_link(?:\s*|%20|,)?id=(?<id>[0-9]+)\](#(?<anchor>.*))?/i', $href, $matches)) { if (preg_match('/\[sitetree_link(?:\s*|%20|,)?id=(?<id>[0-9]+)\](#(?<anchor>.*))?/i', $href ?? '', $matches)) {
// Check if page link is broken // Check if page link is broken
/** @var SiteTree $page */ /** @var SiteTree $page */
$page = DataObject::get_by_id(SiteTree::class, $matches['id']); $page = DataObject::get_by_id(SiteTree::class, $matches['id']);
@ -68,7 +68,7 @@ class SiteTreeLinkTracking_Parser
$broken = true; $broken = true;
} elseif (!empty($matches['anchor'])) { } elseif (!empty($matches['anchor'])) {
// Ensure anchor isn't broken on target page // Ensure anchor isn't broken on target page
$broken = !in_array($matches['anchor'], $page->getAnchorsOnPage()); $broken = !in_array($matches['anchor'], $page->getAnchorsOnPage() ?? []);
} else { } else {
$broken = false; $broken = false;
} }
@ -85,14 +85,14 @@ class SiteTreeLinkTracking_Parser
} }
// Local anchor. // Local anchor.
if (preg_match('/^#(.*)/i', $href, $matches)) { if (preg_match('/^#(.*)/i', $href ?? '', $matches)) {
$anchor = preg_quote($matches[1], '#'); $anchor = preg_quote($matches[1] ?? '', '#');
$results[] = [ $results[] = [
'Type' => 'localanchor', 'Type' => 'localanchor',
'Target' => null, 'Target' => null,
'Anchor' => $matches[1], 'Anchor' => $matches[1],
'DOMReference' => $link, 'DOMReference' => $link,
'Broken' => !preg_match("#(name|id)=\"{$anchor}\"#", $htmlValue->getContent()) 'Broken' => !preg_match("#(name|id)=\"{$anchor}\"#", $htmlValue->getContent() ?? '')
]; ];
continue; continue;

View File

@ -96,9 +96,9 @@ class VirtualPage extends Page
} }
// Diff db with non-virtual fields // Diff db with non-virtual fields
$fields = array_keys(static::getSchema()->fieldSpecs($record)); $fields = array_keys(static::getSchema()->fieldSpecs($record) ?? []);
$nonVirtualFields = $this->getNonVirtualisedFields(); $nonVirtualFields = $this->getNonVirtualisedFields();
return array_diff($fields, $nonVirtualFields); return array_diff($fields ?? [], $nonVirtualFields);
} }
/** /**
@ -448,7 +448,7 @@ class VirtualPage extends Page
{ {
// Don't defer if field is non-virtualised // Don't defer if field is non-virtualised
$ignore = $this->getNonVirtualisedFields(); $ignore = $this->getNonVirtualisedFields();
if (in_array($field, $ignore)) { if (in_array($field, $ignore ?? [])) {
return false; return false;
} }
@ -474,7 +474,7 @@ class VirtualPage extends Page
if (parent::hasMethod($method)) { if (parent::hasMethod($method)) {
return parent::__call($method, $args); return parent::__call($method, $args);
} else { } else {
return call_user_func_array([$this->CopyContentFrom(), $method], $args); return call_user_func_array([$this->CopyContentFrom(), $method], $args ?? []);
} }
} }

View File

@ -29,7 +29,7 @@ class BrokenFilesReport extends Report
{ {
// Get class names for page types that are not virtual pages or redirector pages // Get class names for page types that are not virtual pages or redirector pages
$classes = array_diff( $classes = array_diff(
ClassInfo::subclassesFor(SiteTree::class), ClassInfo::subclassesFor(SiteTree::class) ?? [],
ClassInfo::subclassesFor(VirtualPage::class), ClassInfo::subclassesFor(VirtualPage::class),
ClassInfo::subclassesFor(RedirectorPage::class) ClassInfo::subclassesFor(RedirectorPage::class)
); );

View File

@ -33,7 +33,7 @@ class BrokenLinksReport extends Report
$join = ''; $join = '';
$sortBrokenReason = false; $sortBrokenReason = false;
if ($sort) { if ($sort) {
$parts = explode(' ', $sort); $parts = explode(' ', $sort ?? '');
$field = $parts[0]; $field = $parts[0];
$direction = $parts[1]; $direction = $parts[1];
@ -93,7 +93,7 @@ class BrokenLinksReport extends Report
} }
if ($reason) { if ($reason) {
if (isset($params['Reason']) && $params['Reason'] && !in_array($params['Reason'], $reasonCodes)) { if (isset($params['Reason']) && $params['Reason'] && !in_array($params['Reason'], $reasonCodes ?? [])) {
continue; continue;
} }
$record->BrokenReason = $reason; $record->BrokenReason = $reason;

View File

@ -98,14 +98,14 @@ class SearchForm extends Form
public function classesToSearch($classes) public function classesToSearch($classes)
{ {
$supportedClasses = [SiteTree::class, File::class]; $supportedClasses = [SiteTree::class, File::class];
$illegalClasses = array_diff($classes, $supportedClasses); $illegalClasses = array_diff($classes ?? [], $supportedClasses);
if ($illegalClasses) { if ($illegalClasses) {
throw new BadMethodCallException( throw new BadMethodCallException(
"SearchForm::classesToSearch() passed illegal classes '" . implode("', '", $illegalClasses) "SearchForm::classesToSearch() passed illegal classes '" . implode("', '", $illegalClasses)
. "'. At this stage, only File and SiteTree are allowed" . "'. At this stage, only File and SiteTree are allowed"
); );
} }
$legalClasses = array_intersect($classes, $supportedClasses); $legalClasses = array_intersect($classes ?? [], $supportedClasses);
$this->classesToSearch = $legalClasses; $this->classesToSearch = $legalClasses;
} }
@ -155,10 +155,10 @@ class SearchForm extends Form
return ' -' . $matches[3]; return ' -' . $matches[3];
}; };
$keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords); $keywords = preg_replace_callback('/()("[^()"]+")( and )("[^"()]+")()/i', $andProcessor, $keywords ?? '');
$keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords); $keywords = preg_replace_callback('/(^| )([^() ]+)( and )([^ ()]+)( |$)/i', $andProcessor, $keywords ?? '');
$keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords); $keywords = preg_replace_callback('/(^| )(not )("[^"()]+")/i', $notProcessor, $keywords ?? '');
$keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords); $keywords = preg_replace_callback('/(^| )(not )([^() ]+)( |$)/i', $notProcessor, $keywords ?? '');
$keywords = $this->addStarsToKeywords($keywords); $keywords = $this->addStarsToKeywords($keywords);
@ -166,10 +166,10 @@ class SearchForm extends Form
$start = max(0, (int)$request->requestVar('start')); $start = max(0, (int)$request->requestVar('start'));
$booleanSearch = $booleanSearch =
strpos($keywords, '"') !== false || strpos($keywords ?? '', '"') !== false ||
strpos($keywords, '+') !== false || strpos($keywords ?? '', '+') !== false ||
strpos($keywords, '-') !== false || strpos($keywords ?? '', '-') !== false ||
strpos($keywords, '*') !== false; strpos($keywords ?? '', '*') !== false;
$results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, "\"Relevance\" DESC", "", $booleanSearch); $results = DB::get_conn()->searchEngine($this->classesToSearch, $keywords, $start, $pageLength, "\"Relevance\" DESC", "", $booleanSearch);
// filter by permission // filter by permission
@ -197,19 +197,19 @@ class SearchForm extends Form
protected function addStarsToKeywords($keywords) protected function addStarsToKeywords($keywords)
{ {
if (!trim($keywords)) { if (!trim($keywords ?? '')) {
return ""; return "";
} }
// Add * to each keyword // Add * to each keyword
$splitWords = preg_split("/ +/", trim($keywords)); $splitWords = preg_split("/ +/", trim($keywords ?? ''));
$newWords = []; $newWords = [];
for ($i = 0; $i < count($splitWords); $i++) { for ($i = 0; $i < count($splitWords ?? []); $i++) {
$word = $splitWords[$i]; $word = $splitWords[$i];
if ($word[0] == '"') { if ($word[0] == '"') {
while (++$i < count($splitWords)) { while (++$i < count($splitWords ?? [])) {
$subword = $splitWords[$i]; $subword = $splitWords[$i];
$word .= ' ' . $subword; $word .= ' ' . $subword;
if (substr($subword, -1) == '"') { if (substr($subword ?? '', -1) == '"') {
break; break;
} }
} }

View File

@ -25,7 +25,7 @@ class LoginContext extends BehatLoginContext
$email = "{$permCode}@example.org"; $email = "{$permCode}@example.org";
$password = 'Password!456'; $password = 'Password!456';
$member = $this->generateMemberWithPermission($email, $password, $permCode); $member = $this->generateMemberWithPermission($email, $password, $permCode);
$canEdit = strstr($negative, 'not') ? false : true; $canEdit = strstr($negative ?? '', 'not') ? false : true;
if ($canEdit) { if ($canEdit) {
Assert::assertTrue($page->canEdit($member), 'The member can edit this page'); Assert::assertTrue($page->canEdit($member), 'The member can edit this page');

View File

@ -23,7 +23,7 @@ class ThemeContext implements Context
*/ */
public function stepCreateTheme($theme) public function stepCreateTheme($theme)
{ {
if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) { if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme ?? '')) {
throw new \InvalidArgumentException("Bad theme '$theme'"); throw new \InvalidArgumentException("Bad theme '$theme'");
} }
@ -42,10 +42,10 @@ class ThemeContext implements Context
*/ */
public function stepCreateTemplate($template, $theme, $content) public function stepCreateTemplate($template, $theme, $content)
{ {
if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme)) { if (!preg_match('/^[0-9a-zA-Z_-]+$/', $theme ?? '')) {
throw new \InvalidArgumentException("Bad theme '$theme'"); throw new \InvalidArgumentException("Bad theme '$theme'");
} }
if (!preg_match('/^(Layout\/)?[0-9a-zA-Z_-]+\.ss$/', $template)) { if (!preg_match('/^(Layout\/)?[0-9a-zA-Z_-]+\.ss$/', $template ?? '')) {
throw new \InvalidArgumentException("Bad template '$template'"); throw new \InvalidArgumentException("Bad template '$template'");
} }
@ -56,16 +56,16 @@ class ThemeContext implements Context
protected function requireFile($filename, $content) protected function requireFile($filename, $content)
{ {
// Already exists // Already exists
if (file_exists($filename)) { if (file_exists($filename ?? '')) {
// If the content is different, remember old content for restoration // If the content is different, remember old content for restoration
$origContent = file_get_contents($filename); $origContent = file_get_contents($filename ?? '');
if ($origContent != $content) { if ($origContent != $content) {
file_put_contents($filename, $content); file_put_contents($filename ?? '', $content);
$this->restoreFiles[$filename] = $origContent; $this->restoreFiles[$filename] = $origContent;
} }
// Doesn't exist, mark it for deletion after test // Doesn't exist, mark it for deletion after test
} else { } else {
file_put_contents($filename, $content); file_put_contents($filename ?? '', $content);
$this->restoreFiles[$filename] = null; $this->restoreFiles[$filename] = null;
} }
} }
@ -73,8 +73,8 @@ class ThemeContext implements Context
protected function requireDir($dirname) protected function requireDir($dirname)
{ {
// Directory doesn't exist, create it and mark it for deletion // Directory doesn't exist, create it and mark it for deletion
if (!file_exists($dirname)) { if (!file_exists($dirname ?? '')) {
mkdir($dirname); mkdir($dirname ?? '');
$this->restoreDirectories[] = $dirname; $this->restoreDirectories[] = $dirname;
} }
} }
@ -92,9 +92,9 @@ class ThemeContext implements Context
if ($this->restoreFiles) { if ($this->restoreFiles) {
foreach ($this->restoreFiles as $file => $origContent) { foreach ($this->restoreFiles as $file => $origContent) {
if ($origContent === null) { if ($origContent === null) {
unlink($file); unlink($file ?? '');
} else { } else {
file_put_contents($file, $origContent); file_put_contents($file ?? '', $origContent);
} }
} }
@ -104,9 +104,9 @@ class ThemeContext implements Context
// Restore any created directories: that is, delete them // Restore any created directories: that is, delete them
if ($this->restoreDirectories) { if ($this->restoreDirectories) {
// Flip the order so that nested direcotires are unlinked() first // Flip the order so that nested direcotires are unlinked() first
$this->restoreDirectories = array_reverse($this->restoreDirectories); $this->restoreDirectories = array_reverse($this->restoreDirectories ?? []);
foreach ($this->restoreDirectories as $dir) { foreach ($this->restoreDirectories as $dir) {
rmdir($dir); rmdir($dir ?? '');
} }
$this->restoreDirectories = []; $this->restoreDirectories = [];

View File

@ -6,8 +6,8 @@ if (defined('BASE_PATH')) {
} else { } else {
$projectPath = getcwd() . '/app'; $projectPath = getcwd() . '/app';
} }
if (!is_dir($projectPath)) { if (!is_dir($projectPath ?? '')) {
mkdir($projectPath, 02775); mkdir($projectPath ?? '', 02775);
mkdir($projectPath . '/code', 02775); mkdir($projectPath . '/code', 02775);
mkdir($projectPath . '/_config', 02775); mkdir($projectPath . '/_config', 02775);
copy(__DIR__ . '/fixtures/Page.php.fixture', $projectPath . '/code/Page.php'); copy(__DIR__ . '/fixtures/Page.php.fixture', $projectPath . '/code/Page.php');

View File

@ -142,7 +142,7 @@ class CMSBatchActionsTest extends SapphireTest
$this->assertEquals($archivedID, $list->first()->ParentID); $this->assertEquals($archivedID, $list->first()->ParentID);
// Run restore // Run restore
$result = json_decode($action->run($list), true); $result = json_decode($action->run($list) ?? '', true);
$this->assertEquals( $this->assertEquals(
[ [
$archivedxID => $archivedxID $archivedxID => $archivedxID
@ -162,7 +162,7 @@ class CMSBatchActionsTest extends SapphireTest
$this->assertEquals(0, $list->last()->ParentID); // archived (parent) $this->assertEquals(0, $list->last()->ParentID); // archived (parent)
// Run restore // Run restore
$result = json_decode($action->run($list), true); $result = json_decode($action->run($list) ?? '', true);
$this->assertEquals( $this->assertEquals(
[ [
// Order of archived is opposite to order items are passed in, as // Order of archived is opposite to order items are passed in, as

View File

@ -56,8 +56,8 @@ class CMSMainTest extends FunctionalTest
$rawHints = singleton(CMSMain::class)->SiteTreeHints(); $rawHints = singleton(CMSMain::class)->SiteTreeHints();
$this->assertNotNull($rawHints); $this->assertNotNull($rawHints);
$rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints)); $rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints) ?? '');
$hints = json_decode($rawHints, true); $hints = json_decode($rawHints ?? '', true);
$this->assertArrayHasKey('Root', $hints); $this->assertArrayHasKey('Root', $hints);
$this->assertArrayHasKey('Page', $hints); $this->assertArrayHasKey('Page', $hints);
@ -100,7 +100,7 @@ class CMSMainTest extends FunctionalTest
// Check query // Check query
$response = $this->get('admin/pages/childfilter?ParentID=' . $pageA->ID); $response = $this->get('admin/pages/childfilter?ParentID=' . $pageA->ID);
$children = json_decode($response->getBody()); $children = json_decode($response->getBody() ?? '');
$this->assertFalse($response->isError()); $this->assertFalse($response->isError());
// Page A can't have unrelated children // Page A can't have unrelated children
@ -137,7 +137,7 @@ class CMSMainTest extends FunctionalTest
$actions = CMSBatchActionHandler::config()->batch_actions; $actions = CMSBatchActionHandler::config()->batch_actions;
if (isset($actions['publish'])) { if (isset($actions['publish'])) {
$response = $this->get('admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', [$page1->ID, $page2->ID])); $response = $this->get('admin/pages/batchactions/publish?ajax=1&csvIDs=' . implode(',', [$page1->ID, $page2->ID]));
$responseData = json_decode($response->getBody(), true); $responseData = json_decode($response->getBody() ?? '', true);
$this->assertArrayHasKey($page1->ID, $responseData['modified']); $this->assertArrayHasKey($page1->ID, $responseData['modified']);
$this->assertArrayHasKey($page2->ID, $responseData['modified']); $this->assertArrayHasKey($page2->ID, $responseData['modified']);
} }
@ -335,7 +335,7 @@ class CMSMainTest extends FunctionalTest
] ]
); );
$this->assertFalse($response->isError()); $this->assertFalse($response->isError());
$ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL'), $matches); $ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL') ?? '', $matches);
$this->assertNotEmpty($ok); $this->assertNotEmpty($ok);
$newPageId = $matches[1]; $newPageId = $matches[1];
@ -360,7 +360,7 @@ class CMSMainTest extends FunctionalTest
// Verify that the page was created and redirected to accurately // Verify that the page was created and redirected to accurately
$newerPage = SiteTree::get()->byID($newPageId)->AllChildren()->first(); $newerPage = SiteTree::get()->byID($newPageId)->AllChildren()->first();
$this->assertNotEmpty($newerPage); $this->assertNotEmpty($newerPage);
$ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL'), $matches); $ok = preg_match('/edit\/show\/(\d*)/', $response->getHeader('X-ControllerURL') ?? '', $matches);
$this->assertNotEmpty($ok); $this->assertNotEmpty($ok);
$newerPageID = $matches[1]; $newerPageID = $matches[1];
$this->assertEquals($newerPage->ID, $newerPageID); $this->assertEquals($newerPage->ID, $newerPageID);
@ -398,7 +398,7 @@ class CMSMainTest extends FunctionalTest
$crumbs = $parser->getBySelector('.breadcrumbs-wrapper .crumb'); $crumbs = $parser->getBySelector('.breadcrumbs-wrapper .crumb');
$this->assertNotNull($crumbs); $this->assertNotNull($crumbs);
$this->assertEquals(2, count($crumbs)); $this->assertEquals(2, count($crumbs ?? []));
$this->assertEquals('Page 3', (string)$crumbs[0]); $this->assertEquals('Page 3', (string)$crumbs[0]);
$this->assertEquals('Page 3.1', (string)$crumbs[1]); $this->assertEquals('Page 3.1', (string)$crumbs[1]);

View File

@ -112,7 +112,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
$form = $this->cssParser()->getBySelector('#Form_VersionsForm'); $form = $this->cssParser()->getBySelector('#Form_VersionsForm');
$this->assertEquals(1, count($form)); $this->assertEquals(1, count($form ?? []));
// check the page ID is present // check the page ID is present
$hidden = $form[0]->xpath("fieldset/input[@type='hidden']"); $hidden = $form[0]->xpath("fieldset/input[@type='hidden']");
@ -122,7 +122,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest
// ensure that all the versions are present in the table and displayed // ensure that all the versions are present in the table and displayed
$rows = $form[0]->xpath("fieldset/table/tbody/tr"); $rows = $form[0]->xpath("fieldset/table/tbody/tr");
$this->assertEquals(4, count($rows)); $this->assertEquals(4, count($rows ?? []));
} }
public function testVersionsFormTableContainsInformation() public function testVersionsFormTableContainsInformation()

View File

@ -40,7 +40,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
$this->assertTrue($f->isPageIncluded($page1)); $this->assertTrue($f->isPageIncluded($page1));
$this->assertFalse($f->isPageIncluded($page2)); $this->assertFalse($f->isPageIncluded($page2));
$this->assertEquals(1, count($results)); $this->assertEquals(1, count($results ?? []));
$this->assertEquals( $this->assertEquals(
['ID' => $page1->ID, 'ParentID' => 0], ['ID' => $page1->ID, 'ParentID' => 0],
$results[0] $results[0]
@ -68,7 +68,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
$this->assertTrue($f->isPageIncluded($parent)); $this->assertTrue($f->isPageIncluded($parent));
$this->assertTrue($f->isPageIncluded($child)); $this->assertTrue($f->isPageIncluded($child));
$this->assertEquals(1, count($results)); $this->assertEquals(1, count($results ?? []));
$this->assertEquals( $this->assertEquals(
['ID' => $child->ID, 'ParentID' => $parent->ID], ['ID' => $child->ID, 'ParentID' => $parent->ID],
$results[0] $results[0]
@ -95,7 +95,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
$this->assertTrue($f->isPageIncluded($changedPage)); $this->assertTrue($f->isPageIncluded($changedPage));
$this->assertFalse($f->isPageIncluded($unchangedPage)); $this->assertFalse($f->isPageIncluded($unchangedPage));
$this->assertEquals(1, count($results)); $this->assertEquals(1, count($results ?? []));
$this->assertEquals( $this->assertEquals(
['ID' => $changedPage->ID, 'ParentID' => 0], ['ID' => $changedPage->ID, 'ParentID' => 0],
$results[0] $results[0]
@ -104,7 +104,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
// Check that only changed pages are returned // Check that only changed pages are returned
$f = new CMSSiteTreeFilter_ChangedPages(['Term' => 'No Matches']); $f = new CMSSiteTreeFilter_ChangedPages(['Term' => 'No Matches']);
$results = $f->pagesIncluded(); $results = $f->pagesIncluded();
$this->assertEquals(0, count($results)); $this->assertEquals(0, count($results ?? []));
// If we roll back to an earlier version than what's on the published site, we should still show the changed // If we roll back to an earlier version than what's on the published site, we should still show the changed
$changedPage->Title = 'Changed 2'; $changedPage->Title = 'Changed 2';
@ -115,7 +115,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
$f = new CMSSiteTreeFilter_ChangedPages(['Term' => 'Changed']); $f = new CMSSiteTreeFilter_ChangedPages(['Term' => 'Changed']);
$results = $f->pagesIncluded(); $results = $f->pagesIncluded();
$this->assertEquals(1, count($results)); $this->assertEquals(1, count($results ?? []));
$this->assertEquals(['ID' => $changedPage->ID, 'ParentID' => 0], $results[0]); $this->assertEquals(['ID' => $changedPage->ID, 'ParentID' => 0], $results[0]);
} }
@ -166,7 +166,7 @@ class CMSSiteTreeFilterTest extends SapphireTest
{ {
$draftPage = $this->objFromFixture('Page', 'page4'); $draftPage = $this->objFromFixture('Page', 'page4');
// Grab the date // Grab the date
$date = substr($draftPage->LastEdited, 0, 10); $date = substr($draftPage->LastEdited ?? '', 0, 10);
// Filter with that date // Filter with that date
$filter = new CMSSiteTreeFilter_Search([ $filter = new CMSSiteTreeFilter_Search([
'LastEditedFrom' => $date, 'LastEditedFrom' => $date,

View File

@ -98,7 +98,7 @@ class CMSTreeTest extends FunctionalTest
$result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page1->ID); $result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page1->ID);
$this->assertEquals(200, $result->getStatusCode()); $this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type')); $this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody(), true); $data = json_decode($result->getBody() ?? '', true);
$pageData = $data[$page1->ID]; $pageData = $data[$page1->ID];
$this->assertEquals(0, $pageData['ParentID']); $this->assertEquals(0, $pageData['ParentID']);
$this->assertEquals($page2->ID, $pageData['NextID']); $this->assertEquals($page2->ID, $pageData['NextID']);
@ -108,7 +108,7 @@ class CMSTreeTest extends FunctionalTest
$result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page31->ID); $result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page31->ID);
$this->assertEquals(200, $result->getStatusCode()); $this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type')); $this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody(), true); $data = json_decode($result->getBody() ?? '', true);
$pageData = $data[$page31->ID]; $pageData = $data[$page31->ID];
$this->assertEquals($page3->ID, $pageData['ParentID']); $this->assertEquals($page3->ID, $pageData['ParentID']);
$this->assertEquals($page32->ID, $pageData['NextID']); $this->assertEquals($page32->ID, $pageData['NextID']);
@ -118,14 +118,14 @@ class CMSTreeTest extends FunctionalTest
$result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page1->ID.','.$page2->ID); $result = $this->get('admin/pages/edit/updatetreenodes?ids='.$page1->ID.','.$page2->ID);
$this->assertEquals(200, $result->getStatusCode()); $this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type')); $this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody(), true); $data = json_decode($result->getBody() ?? '', true);
$this->assertEquals(2, count($data)); $this->assertEquals(2, count($data ?? []));
// Invalid IDs // Invalid IDs
$result = $this->get('admin/pages/edit/updatetreenodes?ids=-3'); $result = $this->get('admin/pages/edit/updatetreenodes?ids=-3');
$this->assertEquals(200, $result->getStatusCode()); $this->assertEquals(200, $result->getStatusCode());
$this->assertEquals('application/json', $result->getHeader('Content-Type')); $this->assertEquals('application/json', $result->getHeader('Content-Type'));
$data = json_decode($result->getBody(), true); $data = json_decode($result->getBody() ?? '', true);
$this->assertEquals(0, count($data)); $this->assertEquals(0, count($data ?? []));
} }
} }

View File

@ -172,7 +172,7 @@ class ContentControllerTest extends FunctionalTest
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$response = $this->get($page->RelativeLink()); $response = $this->get($page->RelativeLink());
$this->assertEquals("ContentControllerTestPageWithoutController", trim($response->getBody())); $this->assertEquals("ContentControllerTestPageWithoutController", trim($response->getBody() ?? ''));
// // This should fall over to user Page.ss // // This should fall over to user Page.ss
$page = new ContentControllerTestPage(); $page = new ContentControllerTestPage();
@ -181,7 +181,7 @@ class ContentControllerTest extends FunctionalTest
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$response = $this->get($page->RelativeLink()); $response = $this->get($page->RelativeLink());
$this->assertEquals("Page", trim($response->getBody())); $this->assertEquals("Page", trim($response->getBody() ?? ''));
// Test that the action template is rendered. // Test that the action template is rendered.
@ -191,12 +191,12 @@ class ContentControllerTest extends FunctionalTest
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$response = $this->get($page->RelativeLink("test")); $response = $this->get($page->RelativeLink("test"));
$this->assertEquals("ContentControllerTestPage_test", trim($response->getBody())); $this->assertEquals("ContentControllerTestPage_test", trim($response->getBody() ?? ''));
// Test that an action without a template will default to the index template, which is // Test that an action without a template will default to the index template, which is
// to say the default Page.ss template // to say the default Page.ss template
$response = $this->get($page->RelativeLink("testwithouttemplate")); $response = $this->get($page->RelativeLink("testwithouttemplate"));
$this->assertEquals("Page", trim($response->getBody())); $this->assertEquals("Page", trim($response->getBody() ?? ''));
// Test that an action with a template will render the both action template *and* the // Test that an action with a template will render the both action template *and* the
// correct parent template // correct parent template

View File

@ -23,7 +23,7 @@ class SilverStripeNavigatorTest extends SapphireTest
$navigator = new SilverStripeNavigator($page); $navigator = new SilverStripeNavigator($page);
$items = $navigator->getItems(); $items = $navigator->getItems();
$classes = array_map('get_class', $items->toArray()); $classes = array_map('get_class', $items->toArray() ?? []);
$this->assertContains( $this->assertContains(
SilverStripeNavigatorItem_StageLink::class, SilverStripeNavigatorItem_StageLink::class,
$classes, $classes,
@ -48,18 +48,18 @@ class SilverStripeNavigatorTest extends SapphireTest
// TODO Shouldn't be necessary but SapphireTest logs in as ADMIN by default // TODO Shouldn't be necessary but SapphireTest logs in as ADMIN by default
$this->logInWithPermission('CMS_ACCESS_CMSMain'); $this->logInWithPermission('CMS_ACCESS_CMSMain');
$items = $navigator->getItems(); $items = $navigator->getItems();
$classes = array_map('get_class', $items->toArray()); $classes = array_map('get_class', $items->toArray() ?? []);
$this->assertNotContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes); $this->assertNotContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
$items = $navigator->getItems(); $items = $navigator->getItems();
$classes = array_map('get_class', $items->toArray()); $classes = array_map('get_class', $items->toArray() ?? []);
$this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes); $this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
// Unversioned record shouldn't be viewable in stage / live specific views // Unversioned record shouldn't be viewable in stage / live specific views
$unversioned = new SilverStripeNavigatorTest\UnstagedRecord(); $unversioned = new SilverStripeNavigatorTest\UnstagedRecord();
$navigator2 = new SilverStripeNavigator($unversioned); $navigator2 = new SilverStripeNavigator($unversioned);
$classes = array_map('get_class', $navigator2->getItems()->toArray()); $classes = array_map('get_class', $navigator2->getItems()->toArray() ?? []);
$this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes); $this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes);
$this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes); $this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes);
$this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes); $this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes);

View File

@ -78,8 +78,8 @@ class LinkablePluginTest extends SapphireTest
$this->assertTrue($result->exists()); $this->assertTrue($result->exists());
$this->assertCount(2, $result); $this->assertCount(2, $result);
$titles = $result->column('Title'); $titles = $result->column('Title');
$this->assertTrue(in_array('Test page', $titles)); $this->assertTrue(in_array('Test page', $titles ?? []));
$this->assertTrue(in_array('Other test page', $titles)); $this->assertTrue(in_array('Other test page', $titles ?? []));
$result = LinkablePlugin::applyLinkFilter( $result = LinkablePlugin::applyLinkFilter(
'test', 'test',

View File

@ -37,8 +37,8 @@ class SiteTreeBacklinksTest extends SapphireTest
$page3 = $this->objFromFixture('Page', 'page3'); $page3 = $this->objFromFixture('Page', 'page3');
$page3->Content = str_replace( $page3->Content = str_replace(
'$page1.ID', '$page1.ID',
$this->objFromFixture('Page', 'page1')->ID, $this->objFromFixture('Page', 'page1')->ID ?? '',
$page3->Content $page3->Content ?? ''
); );
$page3->write(); $page3->write();
} }

View File

@ -26,8 +26,8 @@ class SiteTreeHTMLEditorFieldTest extends FunctionalTest
$files = File::get()->exclude('ClassName', Folder::class); $files = File::get()->exclude('ClassName', Folder::class);
foreach ($files as $file) { foreach ($files as $file) {
$destPath = TestAssetStore::getLocalPath($file); $destPath = TestAssetStore::getLocalPath($file);
Filesystem::makeFolder(dirname($destPath)); Filesystem::makeFolder(dirname($destPath ?? ''));
file_put_contents($destPath, str_repeat('x', 1000000)); file_put_contents($destPath ?? '', str_repeat('x', 1000000));
} }
// Ensure all pages are published // Ensure all pages are published

View File

@ -81,11 +81,11 @@ class SiteTreeLinkTrackingTest extends SapphireTest
public function testHighlighter() public function testHighlighter()
{ {
$content = $this->highlight('<a href="[sitetree_link,id=123]" class="existing-class">link</a>'); $content = $this->highlight('<a href="[sitetree_link,id=123]" class="existing-class">link</a>');
$this->assertEquals(substr_count($content, 'ss-broken'), 1, 'A ss-broken class is added to the broken link.'); $this->assertEquals(substr_count($content ?? '', 'ss-broken'), 1, 'A ss-broken class is added to the broken link.');
$this->assertEquals(substr_count($content, 'existing-class'), 1, 'Existing class is not removed.'); $this->assertEquals(substr_count($content ?? '', 'existing-class'), 1, 'Existing class is not removed.');
$content = $this->highlight('<a href="[sitetree_link,id=123]">link</a>'); $content = $this->highlight('<a href="[sitetree_link,id=123]">link</a>');
$this->assertEquals(substr_count($content, 'ss-broken'), 1, 'ss-broken class is added to the broken link.'); $this->assertEquals(substr_count($content ?? '', 'ss-broken'), 1, 'ss-broken class is added to the broken link.');
$otherPage = new Page(); $otherPage = new Page();
$otherPage->Content = ''; $otherPage->Content = '';
@ -94,7 +94,7 @@ class SiteTreeLinkTrackingTest extends SapphireTest
$content = $this->highlight( $content = $this->highlight(
"<a href=\"[sitetree_link,id=$otherPage->ID]\" class=\"existing-class ss-broken ss-broken\">link</a>" "<a href=\"[sitetree_link,id=$otherPage->ID]\" class=\"existing-class ss-broken ss-broken\">link</a>"
); );
$this->assertEquals(substr_count($content, 'ss-broken'), 0, 'All ss-broken classes are removed from good link'); $this->assertEquals(substr_count($content ?? '', 'ss-broken'), 0, 'All ss-broken classes are removed from good link');
$this->assertEquals(substr_count($content, 'existing-class'), 1, 'Existing class is not removed.'); $this->assertEquals(substr_count($content ?? '', 'existing-class'), 1, 'Existing class is not removed.');
} }
} }

View File

@ -148,7 +148,7 @@ class SiteTreeTest extends SapphireTest
public function testDisallowedChildURLGeneration($title, $urlSegment) public function testDisallowedChildURLGeneration($title, $urlSegment)
{ {
// Using the same dataprovider, strip out the -2 from the admin and dev segment // Using the same dataprovider, strip out the -2 from the admin and dev segment
$urlSegment = str_replace('-2', '', $urlSegment); $urlSegment = str_replace('-2', '', $urlSegment ?? '');
$page = Page::create(['Title' => $title, 'ParentID' => 1]); $page = Page::create(['Title' => $title, 'ParentID' => 1]);
$id = $page->write(); $id = $page->write();
$page = Page::get()->byID($id); $page = Page::get()->byID($id);
@ -823,9 +823,9 @@ class SiteTreeTest extends SapphireTest
$diff = $page->compareVersions(1, 2); $diff = $page->compareVersions(1, 2);
$processedContent = trim($diff->Content); $processedContent = trim($diff->Content ?? '');
$processedContent = preg_replace('/\s*</', '<', $processedContent); $processedContent = preg_replace('/\s*</', '<', $processedContent ?? '');
$processedContent = preg_replace('/>\s*/', '>', $processedContent); $processedContent = preg_replace('/>\s*/', '>', $processedContent ?? '');
$this->assertEquals("<ins><span>This is a test</span></ins>", $processedContent); $this->assertEquals("<ins><span>This is a test</span></ins>", $processedContent);
Diff::$html_cleaner_class = $oldCleanerClass; Diff::$html_cleaner_class = $oldCleanerClass;
@ -1487,7 +1487,7 @@ class SiteTreeTest extends SapphireTest
// test the meta generator tag version can be configured off // test the meta generator tag version can be configured off
Config::modify()->set(SiteTree::class, 'show_meta_generator_version', false); Config::modify()->set(SiteTree::class, 'show_meta_generator_version', false);
$content = $expected['generator']['attributes']['content']; $content = $expected['generator']['attributes']['content'];
$expected['generator']['attributes']['content'] = str_replace(' 4.50', '', $content); $expected['generator']['attributes']['content'] = str_replace(' 4.50', '', $content ?? '');
$this->assertEquals($expected, $page->MetaComponents()); $this->assertEquals($expected, $page->MetaComponents());
} }

View File

@ -9,6 +9,6 @@ class VirtualPageTest_TestDBField extends DBVarchar implements TestOnly
{ {
public function forTemplate() public function forTemplate()
{ {
return strtoupper($this->XML()); return strtoupper($this->XML() ?? '');
} }
} }

View File

@ -52,12 +52,12 @@ class CmsReportsTest extends SapphireTest
// ASSERT that the "draft" report is returning the correct results. // ASSERT that the "draft" report is returning the correct results.
$parameters = ['CheckSite' => 'Draft']; $parameters = ['CheckSite' => 'Draft'];
$results = count($report->sourceRecords($parameters, null, null)) > 0; $results = count($report->sourceRecords($parameters, null, null) ?? []) > 0;
$isDraftBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct DRAFT results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct DRAFT results, as pages were found."); $isDraftBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct DRAFT results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct DRAFT results, as pages were found.");
// ASSERT that the "published" report is returning the correct results. // ASSERT that the "published" report is returning the correct results.
$parameters = ['CheckSite' => 'Published', 'OnLive' => 1]; $parameters = ['CheckSite' => 'Published', 'OnLive' => 1];
$results = count($report->sourceRecords($parameters, null, null)) > 0; $results = count($report->sourceRecords($parameters, null, null) ?? []) > 0;
$isPublishedBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct PUBLISHED results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct PUBLISHED results, as pages were found."); $isPublishedBroken ? $this->assertTrue($results, "{$class} has NOT returned the correct PUBLISHED results, as NO pages were found.") : $this->assertFalse($results, "{$class} has NOT returned the correct PUBLISHED results, as pages were found.");
} }
@ -124,7 +124,7 @@ class CmsReportsTest extends SapphireTest
// Correct the "draft" broken link. // Correct the "draft" broken link.
$page->Content = str_replace('987654321', $page->ID, $page->Content); $page->Content = str_replace('987654321', $page->ID ?? '', $page->Content ?? '');
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken link. // ASSERT that the "draft" report has NOT detected the page having a broken link.
@ -191,7 +191,7 @@ class CmsReportsTest extends SapphireTest
$file = File::create(); $file = File::create();
$file->Filename = 'name.pdf'; $file->Filename = 'name.pdf';
$file->write(); $file->write();
$page->Content = str_replace('987654321', $file->ID, $page->Content); $page->Content = str_replace('987654321', $file->ID ?? '', $page->Content ?? '');
$page->writeToStage('Stage'); $page->writeToStage('Stage');
// ASSERT that the "draft" report has NOT detected the page having a broken file. // ASSERT that the "draft" report has NOT detected the page having a broken file.

View File

@ -25,7 +25,7 @@ class CMSMainSearchFormTest extends FunctionalTest
); );
$titles = $this->getPageTitles(); $titles = $this->getPageTitles();
$this->assertEquals(count($titles), 1); $this->assertEquals(count($titles ?? []), 1);
// For some reason the title gets split into two lines // For some reason the title gets split into two lines
$this->assertStringContainsString('Page 1', $titles[0]); $this->assertStringContainsString('Page 1', $titles[0]);
@ -37,7 +37,7 @@ class CMSMainSearchFormTest extends FunctionalTest
$links = $this->cssParser()->getBySelector('.col-getTreeTitle span.item'); $links = $this->cssParser()->getBySelector('.col-getTreeTitle span.item');
if ($links) { if ($links) {
foreach ($links as $link) { foreach ($links as $link) {
$titles[] = preg_replace('/\n/', ' ', $link->asXML()); $titles[] = preg_replace('/\n/', ' ', $link->asXML() ?? '');
} }
} }
return $titles; return $titles;

View File

@ -46,7 +46,7 @@ class MigrateSiteTreeLinkingTaskTest extends SapphireTest
]; ];
foreach (DB::query('SELECT "ID", "Content" FROM "SiteTree"') as $row) { foreach (DB::query('SELECT "ID", "Content" FROM "SiteTree"') as $row) {
$id = (int)$row['ID']; $id = (int)$row['ID'];
$content = str_replace(array_keys($replacements), array_values($replacements), $row['Content']); $content = str_replace(array_keys($replacements ?? []), array_values($replacements ?? []), $row['Content'] ?? '');
DB::prepared_query('UPDATE "SiteTree" SET "Content" = ? WHERE "ID" = ?', [$content, $id]); DB::prepared_query('UPDATE "SiteTree" SET "Content" = ? WHERE "ID" = ?', [$content, $id]);
} }
DataObject::reset(); DataObject::reset();