Documentation

OnBeforeSiteDelete

bool
handler function(
 string site_id
);
The event OnBeforeSiteDelete fires before site is deleted. Usually, the purpose of this event handler is to allow or deny site deletion.

Parameters

ParameterDescription
site_id Deleted site ID.

Returned value

To cancel the site deletion and terminate the execution for the method CSite::Delete, throw an exception in the handler function via the method $APPLICATION->ThrowException() and return false.

See Also

Example а handler function:

<?
// file /bitrix/modules/my_module_id/include.php
class MyClass
{
    // create handler "OnBeforeSiteDelete"
   public static function OnBeforeSiteDeleteHandler($site_id)
    {
        // check if any records exist bound to the deleted language
        $strSql = "SEL ECT * FR OM my_table WHERE SITE_ID=".$DB->ForSql($site_id);
        $rs = $DB->Query($strSql, false, "FILE: ".__FILE__."<br>LINE: ".__LINE__);

        // if found...
        if ($ar = $rs->Fetch()) 
        {
            // cancel deletion
            global $APPLICATION;
            $APPLICATION->throwException("My table has bound records.");
            return false;
        }
    }
}
?>

Example of handler function:

<?
// register the event handler "OnBeforeSiteDelete"
RegisterModuleDependences("main", "OnBeforeSiteDelete", 
      "my_module_id", "MyClass", "OnBeforeSiteDeleteHandler");
?>


© «Bitrix24», 2001-2024