CBlogPost::Delete: Bitrix method

      
<?php 
//  CBlogPost :: Delete()
//  /dist/bitrix/modules/blog/general/blog_post.php:433

    
public static function Delete($ID)
    {
        global 
$DB$CACHE_MANAGER$USER_FIELD_MANAGER;

        
$ID IntVal($ID);

        
$arPost CBlogPost::GetByID($ID);
        if (
$arPost)
        {
            foreach(
GetModuleEvents("blog""OnBeforePostDelete"true) as $arEvent)
            {
                if (
ExecuteModuleEventEx($arEvent, Array($ID))===false)
                    return 
false;
            }

            
$dbResult CBlogComment::GetList(
                array(),
                array(
"POST_ID" => $ID),
                
false,
                
false,
                array(
"ID")
            );
            while (
$arResult $dbResult->Fetch())
            {
                if (!
CBlogComment::Delete($arResult["ID"]))
                    return 
False;
            }

            
$dbResult CBlogUserGroupPerms::GetList(
                array(),
                array(
"POST_ID" => $ID"BLOG_ID" => $arPost["BLOG_ID"]),
                
false,
                
false,
                array(
"ID")
            );
            while (
$arResult $dbResult->Fetch())
            {
                if (!
CBlogUserGroupPerms::Delete($arResult["ID"]))
                    return 
False;
            }

            
$dbResult CBlogTrackback::GetList(
                array(),
                array(
"POST_ID" => $ID"BLOG_ID" => $arPost["BLOG_ID"]),
                
false,
                
false,
                array(
"ID")
            );
            while (
$arResult $dbResult->Fetch())
            {
                if (!
CBlogTrackback::Delete($arResult["ID"]))
                    return 
False;
            }

            
$dbResult CBlogPostCategory::GetList(
                array(),
                array(
"POST_ID" => $ID"BLOG_ID" => $arPost["BLOG_ID"]),
                
false,
                
false,
                array(
"ID")
            );
            while (
$arResult $dbResult->Fetch())
            {
                if (!
CBlogPostCategory::Delete($arResult["ID"]))
                    return 
False;
            }

            
$strSql =
                
"SELECT F.ID ".
                
"FROM b_blog_post P, b_file F ".
                
"WHERE P.ID = ".$ID." ".
                
"    AND P.ATTACH_IMG = F.ID ";
            
$z $DB->Query($strSqlfalse"FILE: ".__FILE__." LINE:".__LINE__);
            while (
$zr $z->Fetch())
                
CFile::Delete($zr["ID"]);

            
CBlogPost::DeleteSocNetPostPerms($ID);

            unset(static::
$arBlogPostCache[$ID]);

            
$arBlog CBlog::GetByID($arPost["BLOG_ID"]);

            
$result $DB->Query("DELETE FROM b_blog_post WHERE ID = ".$IDtrue);

            if (
IntVal($arBlog["LAST_POST_ID"]) == $ID)
                
CBlog::SetStat($arPost["BLOG_ID"]);

            if (
$result)
            {
                
$res CBlogImage::GetList(array(), array("POST_ID"=>$ID"IS_COMMENT" => "N"));
                while(
$aImg $res->Fetch())
                    
CBlogImage::Delete($aImg['ID']);
            }
            if (
$result)
                
$USER_FIELD_MANAGER->Delete("BLOG_POST"$ID);

            foreach(
GetModuleEvents("blog""OnPostDelete"true) as $arEvent)
                
ExecuteModuleEventEx($arEvent, Array($ID, &$result));

            if (
CModule::IncludeModule("search"))
            {
                
CSearch::Index("blog""P".$ID,
                    array(
                        
"TITLE" => "",
                        
"BODY" => ""
                    
)
                );
                
//CSearch::DeleteIndex("blog", false, "COMMENT", $arPost["BLOG_ID"]."|".$ID);
            
}
            if(
defined("BX_COMP_MANAGED_CACHE"))
            {
                
$CACHE_MANAGER->ClearByTag("blog_post_".$ID);
            }
            
            return 
$result;
        }
        else
            return 
false;
    }