public function deleteAssetRecords($object) { // create list of asset_ids to delete $asset_ids = []; foreach ($object->assets as $asset) { // if object has proper rights if ($object->can_zoom == 1 && $object->can_download == 1) { // if it has old protected assest if ($asset->type->asset_type_name == 'protected') { array_push($asset_ids, $asset->id); } } else { if ($asset->type->asset_type_name != 'protected') { $protected_size = $this->protected[$object->protected_size]; // if the size is smaller than the protected size foreach ($this->sizes as $key => $value) { if (strtolower($key) == $asset->type->asset_type_name) { if ($value > $protected_size['width']) { array_push($asset_ids, $asset->id); } } } // always add 'dzi' and 'jsonp' if they exist if ($asset->type->asset_type_name == 'dzi') { array_push($asset_ids, $asset->id); } if ($asset->type->asset_type_name == 'jsonp') { array_push($asset_ids, $asset->id); } } } } Asset::destroy($asset_ids); }