Skip to content

Commit

Permalink
Merge pull request #560 from lekoala/patch-2
Browse files Browse the repository at this point in the history
AssetControlExtension should run less queries
  • Loading branch information
GuySartorelli authored Aug 10, 2023
2 parents 676924d + 418906d commit 19c0bc6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/AssetControlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class AssetControlExtension extends DataExtension
*/
public function onAfterDelete()
{
if (!$this->hasAssets()) {
return;
}

// Prepare blank manipulation
$manipulations = new AssetManipulationList();

Expand All @@ -71,6 +75,10 @@ public function onAfterDelete()
*/
public function onBeforeWrite()
{
if (!$this->hasAssets()) {
return;
}

// Prepare blank manipulation
$manipulations = new AssetManipulationList();

Expand Down Expand Up @@ -209,6 +217,18 @@ protected function addAssetsFromRecord(AssetManipulationList $manipulation, Data
}
}

private function hasAssets(): bool
{
$fields = DataObject::getSchema()->fieldSpecs($this->owner);
foreach ($fields as $field => $db) {
$fieldObj = $this->owner->dbObject($field);
if ($fieldObj instanceof DBFile) {
return true;
}
}
return false;
}

/**
* Return a list of all tuples attached to this dataobject
* Note: Variants are excluded
Expand Down

0 comments on commit 19c0bc6

Please sign in to comment.