This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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,90 @@ | ||
<?php | ||
|
||
namespace SendCloud\SendCloud\Setup\Patch\Data; | ||
|
||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Module\ModuleListInterface; | ||
|
||
class AddResourcesToRole implements DataPatchInterface | ||
{ | ||
const ROLE_NAME = 'SendCloudApi'; | ||
const RESOURCES = [ | ||
'Magento_Catalog::catalog', | ||
'Magento_Catalog::inventory', | ||
'Magento_Catalog::products' | ||
]; | ||
|
||
/** | ||
* @var ModuleDataSetupInterface | ||
*/ | ||
private $moduleDataSetup; | ||
/** | ||
* @var ModuleListInterface | ||
*/ | ||
private $moduleList; | ||
|
||
/** | ||
* @param ModuleDataSetupInterface $moduleDataSetup | ||
* @param ModuleListInterface $moduleList | ||
*/ | ||
public function __construct(ModuleDataSetupInterface $moduleDataSetup, ModuleListInterface $moduleList) | ||
{ | ||
$this->moduleDataSetup = $moduleDataSetup; | ||
$this->moduleList = $moduleList; | ||
} | ||
|
||
/** | ||
* Apply patch | ||
* | ||
* @return void | ||
*/ | ||
public function apply() | ||
{ | ||
$moduleVersion = $this->moduleList->getOne('SendCloud_SendCloud')['setup_version']; | ||
|
||
if (version_compare($moduleVersion, '2.0.23', '<=')) { | ||
$connection = $this->moduleDataSetup->getConnection(); | ||
$aclRoleTable = $this->moduleDataSetup->getTable('authorization_role'); | ||
$aclRuleTable = $this->moduleDataSetup->getTable('authorization_rule'); | ||
|
||
$roleId = $connection->fetchOne( | ||
$connection->select() | ||
->from($aclRoleTable, ['role_id']) | ||
->where('role_name = ?', self::ROLE_NAME) | ||
); | ||
|
||
if ($roleId) { | ||
$resourcesToAdd = []; | ||
|
||
foreach (self::RESOURCES as $resource) { | ||
$resourcesToAdd[] = [ | ||
'role_id' => $roleId, | ||
'resource_id' => $resource, | ||
'permission' => 'allow' | ||
]; | ||
} | ||
|
||
$connection->insertOnDuplicate($aclRuleTable, $resourcesToAdd); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getAliases() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get array of patches that have to be executed prior to this | ||
* | ||
* @return string[] | ||
*/ | ||
public static function getDependencies() | ||
{ | ||
return []; | ||
} | ||
} |
This file contains 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 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