public function onBeforeDelete(DataModel &$model, $oid)
{
if (!$model->isAssetsTracked()) {
return true;
}
$k = $model->getKeyName();
// If the table is not loaded, let's try to load it with the id
if (!$model->{$k}) {
$model->load($oid);
}
// If I have an invalid assetName I have to stop
$name = $model->getAssetName();
// Do NOT touch JTable here -- we are loading the core asset table which is a JTable, not a FOF Table
$asset = \JTable::getInstance('Asset');
if ($asset->loadByName($name)) {
// Since we are using JTable, there is no way to mock it and test for failures :(
// @codeCoverageIgnoreStart
if (!$asset->delete()) {
throw new \Exception($asset->getError());
}
// @codeCoverageIgnoreEnd
}
return true;
}