public function deleteContent($contenttype, $id)
{
if (empty($contenttype)) {
$this->app['logger.system']->error('Contenttype is required for' . __FUNCTION__, ['event' => 'exception']);
throw new StorageException('Contenttype is required for ' . __FUNCTION__);
}
// Make sure $contenttype is a 'slug'
if (is_array($contenttype)) {
$contenttype = $contenttype['slug'];
}
// Get the old content record
$tablename = $this->getContenttypeTablename($contenttype);
$oldContent = $this->findContent($tablename, $id);
// Dispatch pre-delete event
if ($this->app['dispatcher']->hasListeners(StorageEvents::PRE_DELETE)) {
$event = new StorageEvent($oldContent, ['contenttype' => $contenttype]);
$this->app['dispatcher']->dispatch(StorageEvents::PRE_DELETE, $event);
}
$this->logDelete($contenttype, $id, $oldContent);
$res = $this->app['db']->delete($tablename, ['id' => $id]);
// Make sure relations and taxonomies are deleted as well.
if ($res) {
$this->app['db']->delete($this->getTablename('relations'), ['from_contenttype' => $contenttype, 'from_id' => $id]);
$this->app['db']->delete($this->getTablename('relations'), ['to_contenttype' => $contenttype, 'to_id' => $id]);
$this->app['db']->delete($this->getTablename('taxonomy'), ['contenttype' => $contenttype, 'content_id' => $id]);
}
// Dispatch post-delete event
if ($this->app['dispatcher']->hasListeners(StorageEvents::POST_DELETE)) {
$event = new StorageEvent($oldContent, ['contenttype' => $contenttype]);
$this->app['dispatcher']->dispatch(StorageEvents::POST_DELETE, $event);
}
return $res;
}