Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
callbackgroundfolderrights.php
1<?php
2
3namespace Bitrix\Im\Update;
4
7
8
10{
11 public const OPTION_NAME = 'im_call_background_folder_rights';
12 public const LIMIT = 100;
13 protected static $moduleId = "im";
14
15 public function execute(array &$option)
16 {
17 $stepResult = Stepper::FINISH_EXECUTION;
18
19 if (!\Bitrix\Main\Loader::includeModule('disk'))
20 {
21 return $stepResult;
22 }
23
24 $storageId = (int)Option::get('im', 'disk_storage_id', 0);
25 if ($storageId <= 0)
26 {
27 return $stepResult;
28 }
29
30 $topFolder = \Bitrix\Disk\Internals\FolderTable::getRow([
31 'select' => ['ID'],
32 'filter' => [
33 '=STORAGE_ID' => $storageId,
34 '=TYPE' => \Bitrix\Disk\Internals\FolderTable::TYPE_FOLDER,
35 '=CODE' => 'CALL_BACKGROUND',
36 ]
37 ]);
38 if (!$topFolder || (int)$topFolder['ID'] <= 0)
39 {
40 return $stepResult;
41 }
42 $topFolderId = (int)$topFolder['ID'];
43
44 $stepVars = Option::get(self::$moduleId, self::OPTION_NAME, '');
45 $stepVars = ($stepVars !== "" ? @unserialize($stepVars, ['allowed_classes' => false]) : []);
46 $stepVars = (is_array($stepVars) ? $stepVars : []);
47
48 $filter = [
49 '=STORAGE_ID' => $storageId,
50 '=TYPE' => \Bitrix\Disk\Internals\FolderTable::TYPE_FOLDER,
51 '=PARENT_ID' => $topFolderId,
52 'CODE' => 'CALL_BACKGROUND_%',
53 ];
54
55 if (empty($stepVars))
56 {
57 $stepVars = [
58 'lastId' => 0,
59 'number' => 0,
60 'count' => (int)\Bitrix\Disk\Internals\FolderTable::getCount($filter),
61 ];
62 }
63
64 if ($stepVars['count'] > 0)
65 {
66 $option['progress'] = 1;
67 $option['steps'] = '';
68 $option['count'] = $stepVars['count'];
69
70 $filter['>ID'] = $stepVars['lastId'];
71
72 $diskRightsManager = \Bitrix\Disk\Driver::getInstance()->getRightsManager();
73 $accessTaskFull = $diskRightsManager->getTaskIdByName(\Bitrix\Disk\RightsManager::TASK_FULL);
74
75 $cursor = \Bitrix\Disk\Folder::getList([
76 'select' => ['ID', 'CREATED_BY'],
77 'filter' => $filter,
78 'order' => ['ID' => 'ASC'],
79 'limit' => self::LIMIT,
80 ]);
81 $found = false;
82 foreach ($cursor as $row)
83 {
84 $folder = \Bitrix\Disk\Folder::loadById((int)$row['ID']);
85 if ($folder instanceof \Bitrix\Disk\Folder)
86 {
87 $diskRightsManager->append(
88 $folder,
89 [
90 [
91 'ACCESS_CODE' => 'U'. (int)$row['CREATED_BY'],
92 'TASK_ID' => $accessTaskFull,
93 ]
94 ]
95 );
96 }
97 $stepVars['number'] ++;
98 $stepVars['lastId'] = (int)$row['ID'];
99 $found = true;
100 }
101
102 if ($found)
103 {
104 Option::set(self::$moduleId, self::OPTION_NAME, serialize($stepVars));
105 $stepResult = Stepper::CONTINUE_EXECUTION;
106 }
107 else
108 {
109 Option::delete(self::$moduleId, ["name" => self::OPTION_NAME]);
110 }
111
112 $option['progress'] = round($stepVars['number'] * 100 / $stepVars['count']);
113 $option['steps'] = $stepVars['number'];
114 }
115 elseif ($stepVars['count'] == 0)
116 {
117 Option::delete(self::$moduleId, ["name" => self::OPTION_NAME]);
118 }
119
120 return $stepResult;
121 }
122}