Skip to content

Commit

Permalink
Get rid of old Install/Upgrade scripts, migrate to declarative schema…
Browse files Browse the repository at this point in the history
… completely. (#159)
  • Loading branch information
siddwarkhedkar authored Jan 19, 2022
1 parent 9877a35 commit 817c32a
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 235 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### [Unreleased]

### [4.0.0] - 2022-01-19
### [4.0.0] - 2022-01-20
### Added
- Declarative schema, patch data scripts available for backward compatibility

#### Removed
- InstallData/UpgradeData and InstallSchema/UpgradeSchema scripts

#### Fixed
- Whitelisting Klaviyo onsite scripts
Expand Down
48 changes: 0 additions & 48 deletions Setup/InstallData.php

This file was deleted.

51 changes: 0 additions & 51 deletions Setup/InstallSchema.php

This file was deleted.

104 changes: 104 additions & 0 deletions Setup/Patch/Data/UpdateOldPrivateKeysToEncryptedVersions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Klaviyo\Reclaim\Setup\Patch\Data;

use Klaviyo\Reclaim\Helper\ScopeSetting;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;

/**
* Patch is mechanism, that allows to do atomic upgrade data changes
*/
class UpdateOldPrivateKeysToEncryptedVersions implements DataPatchInterface, PatchVersionInterface
{
/**
* Klaviyo ScopeSetting
* @var ScopeSetting $_klaviyoScopeSetting
*/
protected $_klaviyoScopeSetting;

/**
* @var ModuleDataSetupInterface $moduleDataSetup
*/
private $moduleDataSetup;

/**
* Magento Encryptor
* @var EncryptorInterface $_encryptor
*/
protected $_encryptor;

/**
* @param ScopeSetting $_klaviyoScopeSetting
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EncryptorInterface $encryptor
*/
public function __construct(
ScopeSetting $klaviyoScopeSettings,
ModuleDataSetupInterface $moduleDataSetup,
EncryptorInterface $encryptor
)
{
$this->_klaviyoScopeSetting = $klaviyoScopeSettings;
$this->moduleDataSetup = $moduleDataSetup;
$this->_encryptor = $encryptor;
}

/**
* Do Upgrade
*
* @return void
*/
public function apply()
{
$this->moduleDataSetup->getConnection()->startSetup();
$this->updateOldPrivateKeysToEncryptedVersions();
$this->moduleDataSetup->getConnection()->endSetup();
}

/**
* @inheritdoc
*/
public function getAliases()
{
return [];
}

/**
* @inheritdoc
*/
public static function getDependencies()
{
return [];
}

public static function getVersion()
{
return '1.1.7';
}

/**
* in release 1.1.7 we started using the encrypted backend model for the private api key
* this check ensures that when upgrading to this version the key is stored properly
* otherwise we'd be trying to decrypt an unencrypted value elsewhere in the extension code (yikes)
*/
private function updateOldPrivateKeysToEncryptedVersions()
{
$value = $this->_klaviyoScopeSetting->getPrivateApiKey();
//check if there is a private key to encrypt
if (!empty($value)) {
//encrypt the private key
$encrypted = $this->_encryptor->encrypt($value);
//set the private key to the encrypted value
$this->_klaviyoScopeSetting->setPrivateApiKey($encrypted);
}
}
}
82 changes: 0 additions & 82 deletions Setup/UpgradeData.php

This file was deleted.

53 changes: 0 additions & 53 deletions Setup/UpgradeSchema.php

This file was deleted.

8 changes: 8 additions & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@
<column name="updated_at"/>
</index>
</table>
<table name="quote" resource="default">
<column xsi:type="text" name="kl_sms_consent" nullable="true" comment="SMS Consent"/>
<column xsi:type="text" name="kl_email_consent" nullable="true" comment="Email Consent"/>
</table>
<table name="sales_order" resource="default">
<column xsi:type="text" name="kl_sms_consent" nullable="true" comment="SMS Consent"/>
<column xsi:type="text" name="kl_email_consent" nullable="true" comment="Email Consent"/>
</table>
</schema>
Loading

0 comments on commit 817c32a

Please sign in to comment.