Bitrix Site Manager

OnBeforeEventMessageDelete

bool
event_handler(
 int template_id
);

The OnBeforeEventMessageDelete event fires before the mail template is deleted. A common use of this module is to allow or disallow the template deletion.

Parameters

ParameterDescription
template_id The ID of the template which is to be deleted.

Return Values

To cancel the template deletion and terminate the CEventMessage::Delete method, raise an exception from within the handler using the method $APPLICATION->ThrowException() and return false.

See Also

Example



<?
// file /bitrix/modules/my_module_id/include.php
class MyClass
{
    // create handler "OnBeforeEventMessageDelete"
    function OnBeforeEventMessageDeleteHandler($template_id)
    {
        // check if any records exist bound to the deleted template
        $strSql = "SELECT * FROM my_table WHERE EMAIL_TEMPLATE_ID=".intval($template_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 registration


<?
// register handler "OnBeforeEventMessageDelete"
RegisterModuleDependences("main", 
                          "OnBeforeEventMessageDelete", 
                          "my_module_id", 
                          "MyClass", 
                          "OnBeforeEventMessageDeleteHandler");
?>