Current Path : /home/bitrix/ext_www/rg-so.yacl.site/ |
Current File : /home/bitrix/ext_www/rg-so.yacl.site/dzo_update_structure.php |
<? define("NOT_CHECK_PERMISSIONS", true); if (!$_SERVER["DOCUMENT_ROOT"]) { $_SERVER["DOCUMENT_ROOT"] = realpath(__DIR__); } else { die ('Script for console only'); } require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"); require_once $_SERVER["DOCUMENT_ROOT"] . '/local/composer/vendor/autoload.php'; use Bitrix\Main\Type\DateTime; use Bitrix\Main\Loader; use Bitrix\Highloadblock\HighloadBlockTable as HLBT; use Bitrix\Disk\Security\DiskSecurityContext; use Bitrix\Disk\Security\SecurityContext; use Bitrix\Disk\Storage; use Bitrix\Main\Localization\Loc; Loader::includeModule('tasks'); Loader::includeModule('iblock'); $offset = 3; $dzoRootId = 512; $entity = \Bitrix\Iblock\Model\Section::compileEntityByIblock(IBLOCK_DEPARTMENT); $bs = new CIBlockSection; $dzoRootSection = $entity::getList([ 'filter' => ['ID' => $dzoRootId, 'ACTIVE' => 'Y'], 'select' => ['ID', 'NAME', 'LEFT_MARGIN', 'RIGHT_MARGIN'] ])->fetch(); if (!$dzoRootSection) { echo "Wrong DZO Root Section!\n"; die(); } $dzoSections = $entity::getList([ 'filter' => [ 'ACTIVE' => 'Y', '>=LEFT_MARGIN' => $dzoRootSection['LEFT_MARGIN'], '<=RIGHT_MARGIN' => $dzoRootSection['RIGHT_MARGIN'], '!UF_HEAD' => false, ], 'select' => ['ID', 'NAME', 'LEFT_MARGIN', 'RIGHT_MARGIN', 'UF_HEAD'] ])->fetchAll(); $ids = []; foreach ($dzoSections as $section) { $ids[] = $section['ID']; $head = $section['UF_HEAD']; $departments = getUserInfoById($head, ['UF_DEPARTMENT'])['UF_DEPARTMENT']; // okp($departments); // okp($newDepartments); // if (!in_array($section['ID'], $departments)) { // $departments[] = $section['ID']; // $USER->Update($head, ['UF_DEPARTMENT' => $departments]); // break; // } // okp($section); } $userList = \Bitrix\Main\UserTable::getList([ 'filter' => ['ACTIVE' => 'Y', '@UF_DEPARTMENT' => $ids], 'select' => ['ID', 'UF_DEPARTMENT'] ])->fetchAll(); foreach ($userList as $userInfo) { $departments = $userInfo['UF_DEPARTMENT']; sort($departments); $newDepartments = array_unique($departments); if ($newDepartments != $departments) { $USER->Update($userInfo['ID'], ['UF_DEPARTMENT' => $newDepartments]); } }