public static function delete($ids)
{
// make sure $ids is an array
$ids = (array) $ids;
// make sure we have elements
if (empty($ids)) {
return;
}
// loop and cast to integers
foreach ($ids as &$id) {
$id = (int) $id;
}
// create an string with an equal amount of questionmarks as ids provided
$idPlaceHolders = implode(', ', array_fill(0, count($ids), '?'));
// get db
$db = BackendModel::getContainer()->get('database');
// get used meta ids
$metaIds = (array) $db->getColumn('SELECT meta_id
FROM blog_posts AS p
WHERE id IN (' . $idPlaceHolders . ') AND language = ?', array_merge($ids, array(BL::getWorkingLanguage())));
// delete meta
if (!empty($metaIds)) {
$db->delete('meta', 'id IN (' . implode(',', $metaIds) . ')');
}
// delete image files
$images = $db->getColumn('SELECT image FROM blog_posts WHERE id IN (' . $idPlaceHolders . ')', $ids);
foreach ($images as $image) {
BackendModel::deleteThumbnails(FRONTEND_FILES_PATH . '/blog/images', $image);
}
// delete records
$db->delete('blog_posts', 'id IN (' . $idPlaceHolders . ') AND language = ?', array_merge($ids, array(BL::getWorkingLanguage())));
$db->delete('blog_comments', 'post_id IN (' . $idPlaceHolders . ') AND language = ?', array_merge($ids, array(BL::getWorkingLanguage())));
// delete tags
foreach ($ids as $id) {
BackendTagsModel::saveTags($id, '', 'Blog');
}
}