-
Notifications
You must be signed in to change notification settings - Fork 23
[MIGRATO-191] Миграция расширенных прав доступа к инфоблокам #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7557676
[MIGRATO-191] добавил сущность для миграции расширенных прав доступа …
TrutnevItsMe 2467d02
[MIGRATO-191] добавил сущность right для миграции расширенных прав ин…
TrutnevItsMe 59488f3
[MIGRATO-191] добавил импорт типа установки прав доступа для инфоблок…
TrutnevItsMe d6c2749
[MIGRATO-191] убрал лишние поля из экспорта расширенных прав доступа
TrutnevItsMe 4811447
[MIGRATO-191] добавил импорт поля BINDING для таблицы b_task
TrutnevItsMe 9b79925
[MIGRATO-191] убрал пробел в конце lang записи
TrutnevItsMe e578639
[MIGRATO-191] добавил поле IBLOCK_ID для заполнения ID импорта расшир…
TrutnevItsMe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?php | ||
| $MESS['INTERVOLGA_MIGRATO.IBLOCK_RIGHTS'] = 'Расширенные права доступа'; | ||
| $MESS['INTERVOLGA_MIGRATO.TASK_NOT_FOUND'] = 'Не найдено описание права доступа'; | ||
| $MESS['INTERVOLGA_MIGRATO.IBLOCK_NOT_FOUND'] = 'Не найден инфоблок'; | ||
| $MESS['INTERVOLGA_MIGRATO.GROUP_NOT_FOUND'] = 'Не найдена группа пользователя'; | ||
| $MESS['INTERVOLGA_MIGRATO.INVALID_IBLOCK_ID'] = 'Неверный формат ID инфоблока. ID должен быть > 0'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| <?php namespace Intervolga\Migrato\Data\Module\Iblock; | ||
|
|
||
| use Bitrix\Iblock\IblockTable; | ||
| use Bitrix\Main\Loader; | ||
| use Bitrix\Main\Localization\Loc; | ||
| use Intervolga\Migrato\Data\BaseData; | ||
| use Intervolga\Migrato\Data\Link; | ||
| use Intervolga\Migrato\Data\Module\Main\Group; | ||
| use Intervolga\Migrato\Data\Module\Main\Task; | ||
| use Intervolga\Migrato\Data\Record; | ||
| use Intervolga\Migrato\Data\RecordId; | ||
| use Intervolga\Migrato\Tool\XmlIdProvider\BaseXmlIdProvider; | ||
|
|
||
| Loc::loadMessages(__FILE__); | ||
|
|
||
| class Right extends BaseData | ||
| { | ||
| const PREFIX_GROUP_CODE = 'G'; | ||
|
|
||
| protected static array $iblockRights = []; | ||
|
|
||
| protected function configure() | ||
| { | ||
| Loader::includeModule('iblock'); | ||
| $this->setVirtualXmlId(true); // Есть XML_ID, но при создании вручную поле NULL | ||
| $this->setEntityNameLoc(Loc::getMessage('INTERVOLGA_MIGRATO.IBLOCK_RIGHTS')); | ||
| $this->setFilesSubdir('/type/iblock/'); | ||
| $this->setDependencies([ | ||
| 'IBLOCK' => new Link(IblocK::getInstance()), | ||
| 'TASK' => new Link(Task::getInstance()), | ||
| 'GROUP' => new Link(Group::getInstance()), | ||
| ]); | ||
| } | ||
|
|
||
| public function createId($id) | ||
| { | ||
| return RecordId::createComplexId([ | ||
| 'IBLOCK_ID' => intval($id['IBLOCK_ID']), | ||
| 'GROUP_ID' => intval(trim($id['GROUP_CODE'], static::PREFIX_GROUP_CODE)), | ||
| 'ENTITY_ID' => intval($id['ENTITY_ID']), | ||
| ]); | ||
| } | ||
|
|
||
| public function getXmlId($id) | ||
| { | ||
| $array = $id->getValue(); | ||
| $iblockData = Iblock::getInstance(); | ||
| $groupData = Group::getInstance(); | ||
|
|
||
| $iblockXmlId = $iblockData->getXmlId($iblockData->createId($array['IBLOCK_ID'])); | ||
| $groupId = $groupData->getXmlId($groupData->createId($array['GROUP_ID'])); | ||
|
|
||
| $md5 = md5(serialize([ | ||
| $iblockXmlId, | ||
| $groupId, | ||
| ])); | ||
|
|
||
| return BaseXmlIdProvider::formatXmlId($md5); | ||
| } | ||
|
|
||
| public function getList(array $filter = []) | ||
| { | ||
| $result = []; | ||
| Loader::includeModule( 'iblock' ); | ||
|
|
||
| $iblockIterator = IblockTable::getList([ | ||
| 'select' => ['ID'] | ||
| ]); | ||
|
|
||
| while ($iblock = $iblockIterator->fetch()){ | ||
| $this->initIblockRights($iblock['ID']); | ||
|
|
||
| foreach (static::$iblockRights[$iblock['ID']] as $right){ | ||
| $record = new Record($this); | ||
| $id = $this->createId($right); | ||
|
|
||
| $record->setId($id); | ||
| $record->setXmlId($this->getXmlId($id)); | ||
|
|
||
| foreach ([ | ||
| 'IBLOCK' => [ | ||
| 'CLASS' => IblocK::class, | ||
| 'ID' => RecordId::createNumericId($iblock['ID']) | ||
| ], | ||
| 'TASK' => [ | ||
| 'CLASS' => Task::class, | ||
| 'ID' => $right['TASK_ID'] | ||
| ], | ||
| 'GROUP' => [ | ||
| 'CLASS' => Group::class, | ||
| 'ID' => RecordId::createNumericId(trim($right['GROUP_CODE'], static::PREFIX_GROUP_CODE)) | ||
| ] | ||
| ] as $field => $desc) | ||
| { | ||
| $dependency = clone $this->getDependency($field); | ||
| $dependency->setValue( | ||
| $desc['CLASS']::getInstance()->getXmlId($desc['ID']) | ||
| ); | ||
| $record->setDependency($field, $dependency); | ||
| } | ||
|
|
||
| $result[] = $record; | ||
| } | ||
| } | ||
|
|
||
| return $result; | ||
| } | ||
|
|
||
| protected function createInner(Record $record) | ||
| { | ||
| return $this->setRights($record); | ||
| } | ||
|
|
||
| public function update(Record $record) | ||
| { | ||
| $this->setRights($record); | ||
| } | ||
|
|
||
| protected function deleteInner(RecordId $id) | ||
| { | ||
| $array = $id->getValue(); | ||
| $iblockId = $array['IBLOCK_ID']; | ||
|
|
||
| if (!$iblockId){ | ||
| return; | ||
| } | ||
|
|
||
| $this->initIblockRights($iblockId); | ||
|
|
||
| $obIBlockRights = new \CIBlockRights($iblockId); | ||
| $obIBlockRights->setRights(static::$iblockRights[$iblockId]); | ||
| } | ||
|
|
||
| protected function setRights(Record $record) | ||
| { | ||
| $iblockLinkId = Iblock::getInstance()->findRecord($record->getDependency('IBLOCK')->getValue()); | ||
| $groupLinkId = Group::getInstance()->findRecord($record->getDependency('GROUP')->getValue()); | ||
| $taskLinkId = Task::getInstance()->findRecord($record->getDependency('TASK')->getValue()); | ||
|
|
||
| if (!$taskLinkId){ | ||
| throw new \Exception(Loc::getMessage('INTERVOLGA_MIGRATO.TASK_NOT_FOUND')); | ||
| } | ||
|
|
||
| if (!$iblockLinkId) { | ||
| throw new \Exception(Loc::getMessage('INTERVOLGA_MIGRATO.IBLOCK_NOT_FOUND')); | ||
| } | ||
|
|
||
| if (!$groupLinkId) { | ||
| throw new \Exception(Loc::getMessage('INTERVOLGA_MIGRATO.GROUP_NOT_FOUND')); | ||
| } | ||
|
|
||
| $groupId = $groupLinkId->getValue(); | ||
| $taskId = $taskLinkId->getValue(); | ||
| $iblockId = $iblockLinkId->getValue(); | ||
|
|
||
| $this->initIblockRights($iblockId); | ||
|
|
||
| $issetRight = false; | ||
|
|
||
| foreach (static::$iblockRights[$iblockId] as $i => $right){ | ||
| if ( | ||
| $right['ENTITY_TYPE'] == 'iblock' | ||
| && $right['GROUP_CODE'] == static::PREFIX_GROUP_CODE.$groupId | ||
| && $right['ENTITY_ID'] == $iblockId | ||
| ){ | ||
| static::$iblockRights[$iblockId][$i] = array_merge( | ||
| $right, | ||
| [ | ||
| 'TASK_ID' => $taskId, | ||
| ] | ||
| ); | ||
|
|
||
| $issetRight = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!$issetRight){ | ||
| static::$iblockRights[$iblockId]['n'.count(static::$iblockRights[$iblockId])] = [ | ||
| 'TASK_ID' => $taskId, | ||
| 'GROUP_CODE' => static::PREFIX_GROUP_CODE.$groupId, | ||
| ]; | ||
| } | ||
|
|
||
| $obIBlockRights = new \CIBlockRights($iblockId); | ||
| $obIBlockRights->setRights(static::$iblockRights[$iblockId]); | ||
|
|
||
| return $this->createId([ | ||
| 'IBLOCK_ID' => $iblockId, | ||
| 'TASK_ID' => $taskId, | ||
| 'GROUP_CODE' => static::PREFIX_GROUP_CODE.$groupId, | ||
| 'ENTITY_ID' => $iblockId, | ||
| ]); | ||
| } | ||
|
|
||
| protected function initIblockRights($iblockId): void | ||
| { | ||
| if (!is_numeric($iblockId) || $iblockId <= 0){ | ||
| throw new \Exception(Loc::getMessage('INTERVOLGA_MIGRATO.INVALID_IBLOCK_ID')); | ||
| } | ||
|
|
||
| if (!static::$iblockRights[$iblockId]){ | ||
| static::$iblockRights[$iblockId] = (new \CIBlockRights($iblockId))->getRights(); | ||
|
|
||
| if (static::$iblockRights[$iblockId]){ | ||
| foreach (static::$iblockRights[$iblockId] as $i => $right){ | ||
| static::$iblockRights[$iblockId][$i]["IBLOCK_ID"] = $iblockId; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.