Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Release version 2.0.23
Browse files Browse the repository at this point in the history
ISSUE: CS-4769
  • Loading branch information
ivan-logeecom committed Oct 24, 2023
1 parent 1827b9b commit 368c38f
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
90 changes: 90 additions & 0 deletions Setup/Patch/Data/AddResourcesToRole.php
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 [];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "magento2-module",
"homepage": "https://www.sendcloud.com/",
"license": "Apache-2.0",
"version": "2.0.22",
"version": "2.0.23",
"require": {
"php": "~7.1.0|~7.2.0|~7.3.0|~7.4.0|~8.1.0|~8.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="SendCloud_SendCloud" setup_version="2.0.22">
<module name="SendCloud_SendCloud" setup_version="2.0.23">
<sequence>
<module name="Magento_Shipping"/>
<module name="Magento_Multishipping"/>
Expand Down

0 comments on commit 368c38f

Please sign in to comment.