How I should 'Setup/update System/store Configuration values through setup script'? Trying with Setup/Patch/Data script using something like
//app/code/Namespace/Module/Setup/Patch/Data/SetupConfigData.php
namespace Namespace\Module\Setup\Patch\Data;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\App\Config\MutableScopeConfigInterface;
class SetupConfigData implements DataPatchInterface
{
const XML_PATH_STORE_NAME = 'general/store_information/name';
const XML_PATH_STORE_PHONE = 'general/store_information/phone';
const XML_PATH_ADMIN_ACCOUNT_SHARING = 'admin/security/admin_account_sharing';
const XML_PATH_ADMIN_URL_SECRET_KEY = 'admin/security/use_form_key';
const SCOPE_STORE = 'store';
/**
* @var \Magento\Framework\App\Config\MutableScopeConfigInterface
*/
private $mutableScopeConfig;
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
MutableScopeConfigInterface $mutableScopeConfig
)
{
$this->moduleDataSetup = $moduleDataSetup;
$this->mutableScopeConfig = $mutableScopeConfig;
}
public function apply()
{
$this->moduleDataSetup->startSetup();
$this->mutableScopeConfig->setValue(self::XML_PATH_STORE_NAME, "Title", self::SCOPE_STORE);
$this->mutableScopeConfig->setValue(self::XML_PATH_STORE_PHONE, "Default contact", self::SCOPE_STORE);
$this->mutableScopeConfig->setValue(self::XML_PATH_ADMIN_ACCOUNT_SHARING, 0, self::SCOPE_STORE);
$this->mutableScopeConfig->setValue(self::XML_PATH_ADMIN_URL_SECRET_KEY, 0, self::SCOPE_STORE);
$this->moduleDataSetup->endSetup();
}
public function getAliases()
{
return [];
}
public static function getDependencies()
{
return [];
}
}
Environment: Magento 2.3.3
and nothing changed after running setup:upgrade
, am not sure what am I missing.