Bitrix Site Manager

OnChangeFile

event_handler(
 string path,
 string site_id
);

The OnChangeFile event is fired right after a file is saved by a call to method $APPLICATION->SaveFileContent.

Parameters

ParameterDescription
path File path relative to the site root.
site_id The ID of the site whose file has changed.

See Also

Example



<?
// file /bitrix/php_interface/init.php
AddEventHandler("main", 
                "OnChangeFile", 
                Array("MyClass", 
                      "OnChangeFileHandler"));

class MyClass
{
    // create handler "OnChangeFile"
    function OnChangeFileHandler($path, $site)
    {
        // get DOCUMENT_ROOT to the specified site
        $DOC_ROOT = CSite::GetSiteDocRoot($site);

        // obtain the file contents using absolute path
        $filesrc = $application->getfilecontent($doc_root.$path);

        // parse file
        $arContent = ParseFileContent($filesrc);
        $TITLE = $arContent["TITLE"];
        $BODY = $arContent["CONTENT"];

        // insert a record on the file change in the table
        $arFields = array(
            "MODIFIED_BY" => $USER->GetID(), // who changed
            "TITLE"       => $TITLE,         // file title
            "FILENAME"    => $path,          // path relative to root
            "SITE_ID"     => $site,          // site ID
            "BODY"        => $BODY,          // file contents
            );
        $arInsert = $DB->PrepareInsert("b_workflow_log", 
                                       $arFields, "workflow");
        $strSql = "INSERT INTO b_workflow_log (TIMESTAMP_X,  ".
                  $arInsert[0].") VALUES(now(), ".$arInsert[1].")";
        $DB->Query($strSql, false, 
                   "FILE: ".__FILE__."<br>LINE: ".__LINE__);
    }
}
?>