-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove the previous apikey upon installation to force the use of the new Oauth Token
- Loading branch information
Showing
2 changed files
with
81 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,79 @@ | ||
<?php | ||
namespace Extend\Warranty\Setup; | ||
|
||
use Magento\Framework\Setup\InstallDataInterface; | ||
use Magento\Framework\Setup\ModuleContextInterface; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
use Magento\Config\Model\ResourceModel\Config as ConfigResource; | ||
|
||
|
||
class InstallData implements InstallDataInterface | ||
{ | ||
//protected $configWriter; | ||
protected $scopeConfig; | ||
protected $storeManager; | ||
/** | ||
* Config Resource Model | ||
* | ||
* @var ConfigResource | ||
*/ | ||
private $configResource; | ||
|
||
|
||
public const WARRANTY_AUTHENTICATION_CLIENT_ID_XML_PATH = 'warranty/authentication/client_id'; | ||
public const WARRANTY_AUTHENTICATION_SANDBOX_CLIENT_ID_XML_PATH = 'warranty/authentication/sandbox_client_id'; | ||
public const WARRANTY_AUTHENTICATION_CLIENT_SECRET_XML_PATH = 'warranty/authentication/client_secret'; | ||
public const WARRANTY_AUTHENTICATION_SANDBOX_CLIENT_SECRET_XML_PATH = 'warranty/authentication/sandbox_client_secret'; | ||
public const WARRANTY_AUTHENTICATION_API_KEY_XML_PATH = 'warranty/authentication/api_key'; | ||
public const WARRANTY_AUTHENTICATION_SANDBOX_API_KEY_XML_PATH = 'warranty/authentication/sandbox_api_key'; | ||
|
||
|
||
public function __construct( | ||
ScopeConfigInterface $scopeConfig, | ||
StoreManagerInterface $storeManager, | ||
ConfigResource $configResource, | ||
) { | ||
$this->scopeConfig = $scopeConfig; | ||
$this->storeManager = $storeManager; | ||
$this->configResource = $configResource; | ||
} | ||
|
||
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) | ||
{ | ||
// Get all store views | ||
$stores = $this->storeManager->getStores(); | ||
|
||
foreach ($stores as $store) { | ||
$storeId = $store->getId(); | ||
|
||
// Fetch the values for each store view | ||
$clientId = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_CLIENT_ID_XML_PATH, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId); | ||
$clientSecret = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_CLIENT_SECRET_XML_PATH, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId); | ||
$apiKey = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_API_KEY_XML_PATH, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId); | ||
$sandboxClientId = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_SANDBOX_CLIENT_ID_XML_PATH, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId); | ||
$sandboxClientSecret = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_SANDBOX_CLIENT_SECRET_XML_PATH, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId); | ||
$sandboxApiKey = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_SANDBOX_API_KEY_XML_PATH, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId); | ||
|
||
// Check the conditions and delete the config if necessary | ||
if (empty($clientId) && empty($clientSecret) && !empty($apiKey)) { | ||
$this->configResource->deleteConfig(self::WARRANTY_AUTHENTICATION_API_KEY_XML_PATH, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId); | ||
} | ||
|
||
if (empty($sandboxClientId) && empty($sandboxClientSecret) && !empty($sandboxApiKey)) { | ||
$this->configResource->deleteConfig(self::WARRANTY_AUTHENTICATION_SANDBOX_API_KEY_XML_PATH, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId); | ||
} | ||
|
||
} | ||
} | ||
} |
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