Skip to content

Commit

Permalink
Update afterDelete function in AssetsTable
Browse files Browse the repository at this point in the history
Included explicit return type for the afterDelete function and made it use the asset's absolute_path for deletion instead of manually building the path. Also, the afterDelete function now accepts an Asset object instead of a general EntityInterface.
  • Loading branch information
jcsiegrist committed May 16, 2024
1 parent 824c3d1 commit 0a2dea6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Model/Table/AssetsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Assets\Model\Table;

use ArrayObject;
use Assets\Model\Entity\Asset;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Event\EventInterface;
Expand Down Expand Up @@ -131,11 +132,13 @@ public function beforeFind(EventInterface $e, Query $query, ArrayObject $options
return $query->orderDesc('modified');
}

public function afterDelete(EventInterface $e, EntityInterface $entity, ArrayObject $options)
public function afterDelete(EventInterface $e, Asset $entity, ArrayObject $options): bool
{
if (Configure::read('AssetsPlugin.AssetsTable.deleteFile') === true) {
FileSystem::delete(ROOT . DS . $entity->directory . $entity->filename);
FileSystem::delete($entity->absolute_path);
}

return true;
}

/**
Expand Down

0 comments on commit 0a2dea6

Please sign in to comment.