mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Don't make query if not needed (#2863)
* Don't make query if not needed See https://github.com/silverstripe/silverstripe-assets/issues/557 for background * add comment
This commit is contained in:
parent
7a17383e47
commit
3295dd5062
@ -116,15 +116,22 @@ class SiteTreeLinkTracking extends DataExtension
|
|||||||
$allFields = DataObject::getSchema()->fieldSpecs($this->owner);
|
$allFields = DataObject::getSchema()->fieldSpecs($this->owner);
|
||||||
$linkedPages = [];
|
$linkedPages = [];
|
||||||
$anyBroken = false;
|
$anyBroken = false;
|
||||||
|
$hasTrackedFields = false;
|
||||||
foreach ($allFields as $field => $fieldSpec) {
|
foreach ($allFields as $field => $fieldSpec) {
|
||||||
$fieldObj = $this->owner->dbObject($field);
|
$fieldObj = $this->owner->dbObject($field);
|
||||||
if ($fieldObj instanceof DBHTMLText) {
|
if ($fieldObj instanceof DBHTMLText) {
|
||||||
|
$hasTrackedFields = true;
|
||||||
// Merge links in this field with global list.
|
// Merge links in this field with global list.
|
||||||
$linksInField = $this->trackLinksInField($field, $anyBroken);
|
$linksInField = $this->trackLinksInField($field, $anyBroken);
|
||||||
$linkedPages = array_merge($linkedPages, $linksInField);
|
$linkedPages = array_merge($linkedPages, $linksInField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need a boolean flag instead of checking linkedPages because it can be empty when pages are removed
|
||||||
|
if (!$hasTrackedFields) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Soft support for HasBrokenLink db field (e.g. SiteTree)
|
// Soft support for HasBrokenLink db field (e.g. SiteTree)
|
||||||
if ($this->owner->hasField('HasBrokenLink')) {
|
if ($this->owner->hasField('HasBrokenLink')) {
|
||||||
$this->owner->HasBrokenLink = $anyBroken;
|
$this->owner->HasBrokenLink = $anyBroken;
|
||||||
|
Loading…
Reference in New Issue
Block a user