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:
Thomas Portelange 2023-08-18 14:42:21 +02:00 committed by GitHub
parent 7a17383e47
commit 3295dd5062
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -116,15 +116,22 @@ class SiteTreeLinkTracking extends DataExtension
$allFields = DataObject::getSchema()->fieldSpecs($this->owner);
$linkedPages = [];
$anyBroken = false;
$hasTrackedFields = false;
foreach ($allFields as $field => $fieldSpec) {
$fieldObj = $this->owner->dbObject($field);
if ($fieldObj instanceof DBHTMLText) {
$hasTrackedFields = true;
// Merge links in this field with global list.
$linksInField = $this->trackLinksInField($field, $anyBroken);
$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)
if ($this->owner->hasField('HasBrokenLink')) {
$this->owner->HasBrokenLink = $anyBroken;