Documentation

OnChangePermissions

hander function(
 array site_path,
 array permissions
);
The event OnChangePermissions fires when access permissions to a file or folder are updated via the method $APPLICATION->SetFileAccessPermission.

Parameters

ParameterDescription
site_path Array type: array("site ID", "path to file relative to this site root").
permissions Array of access permissions.

See Also

Example:

<?
// file /bitrix/modules/search/classes/mysql/search.php
class CSearch extends CAllSearch
{
    // create the event handler "OnChangePermissions"
    public static function OnChangeFilePermissions($path, $permission)
    {
        CMain::InitPathVars($site, $path);
        $DOC_ROOT = CSite::GetSiteDocRoot($site);

        while(strlen($path)>0 && $path[strlen($path)-1]=="/") //cut off / at the end, if available
            $path=substr($path, 0, strlen($path)-1);

        global $APPLICATION, $DB;
        if(file_exists($DOC_ROOT.$path))
        {
            @set_time_limit(300);
            $arGroups = CSearch::GetGroupCached();
            if(is_dir($DOC_ROOT.$path))
            {
                $handle  = @opendir($DOC_ROOT.$path);
                while($file = @readdir($handle))
                {
                    if($file == "." || $file == "..") continue;
                    if(is_dir($DOC_ROOT.$path."/".$file))
                    {
                        if($path."/".$file=="/bitrix")
                            continue;
                    }
                    CSearch::OnChangeFilePermissions(Array($site, $path."/".$file), Array());
                }
            }
            else //if(is_dir($DOCUMENT_ROOT.$path))
            {
                $strGPerm = "0";
                for($i=0; $i<count($arGroups); $i++)
                {
                    if($arGroups[$i]>1)
                    {
                        $p = $APPLICATION->GetFileAccessPermission(Array($site, $path), Array($arGroups[$i]));
                        if($p>="R")
                        {
                            $strGPerm .= ",".$arGroups[$i];
                            if($arGroups[$i]==2) break;
                        }
                    }
                }

                $r = $DB->Query("SEL ECT ID FR OM b_search_content WHERE MODULE_ID='main' AND ITEM_ID='".$site."|".$path."'");
                while($arR = $r->Fetch())
                    $DB->Query("DELETE FR OM b_search_content_group WH ERE SEARCH_CONTENT_ID=".$arR["ID"]);

                $strSql =
                    "INS ERT INTO b_search_content_group(SEARCH_CONTENT_ID, GROUP_ID) ".
                    "SELE CT S.ID, G.ID ".
                    "FR OM b_search_content S, b_group G ".
                    "WH ERE MODULE_ID='main' ".
                    "    AND ITEM_ID='".$site."|".$path."' ".
                    "    AND G.ID IN (".$strGPerm.") ";

                $DB->Query($strSql);
            } //if(is_dir($DOCUMENT_ROOT.$path))
        }//if(file_exists($DOCUMENT_ROOT.$path))
    }
}
?>

Example of handler function registration:

<?
// register the event handler "OnChangePermissions"
RegisterModuleDependences("main", "OnChangePermissions", "search", "CSearch", "OnChangeFilePermissions");
?>


© «Bitrix24», 2001-2024