Skip to content

Commit

Permalink
Remove install/upgrade scripts and turn them into patches
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinverschoor committed Jan 18, 2022
1 parent 68d2d3f commit a929eed
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 149 deletions.
47 changes: 0 additions & 47 deletions Setup/InstallSchema.php

This file was deleted.

65 changes: 65 additions & 0 deletions Setup/Patch/Data/Install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Paynl\Payment\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Store\Model\Store;
use \Paynl\Payment\Helper\PayHelper;

class Install implements DataPatchInterface
{
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;

/**
* @var WriterInterface
*/
private $configWriter;

/**
* @var Store
* */
private $store;

/**
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(ModuleDataSetupInterface $moduleDataSetup, WriterInterface $configWriter, Store $store)
{
$this->moduleDataSetup = $moduleDataSetup;
$this->configWriter = $configWriter;
$this->store = $store;
}

/**
* @inheritdoc
*/
public function apply()
{
$this->moduleDataSetup->startSetup();

if (empty($this->store->getConfig('payment/paynl/apitoken')) && empty($this->store->getConfig('payment/paynl/serviceid'))) {
payHelper::logDebug('Installing module.');
$this->configWriter->save('payment/paynl/order_description_prefix', 'Order ');
$this->configWriter->save('payment/paynl/image_style', 'newest');
$this->configWriter->save('payment/paynl/pay_style_checkout', 1);
$this->configWriter->save('payment/paynl/icon_size', 'small');
}

$this->moduleDataSetup->endSetup();
}

public static function getDependencies()
{
return [];
}

public function getAliases()
{
return [];
}
}
81 changes: 81 additions & 0 deletions Setup/Patch/Data/UpdateFashionGiftcard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Paynl\Payment\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Config\Model\ResourceModel\Config;
use \Paynl\Payment\Helper\PayHelper;

class UpdateFashionGiftcard implements DataPatchInterface, PatchVersionInterface
{
/**
* @var ModuleDataSetupInterface
*/
private $moduleDataSetup;

/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @var Config
*/
private $resourceConfig;

/**
* @param ModuleDataSetupInterface $moduleDataSetup
*/
public function __construct(ModuleDataSetupInterface $moduleDataSetup, ResourceConnection $resourceConnection, Config $resourceConfig)
{
$this->moduleDataSetup = $moduleDataSetup;
$this->resourceConnection = $resourceConnection;
$this->resourceConfig = $resourceConfig;
}

/**
* @inheritdoc
*/
public function apply()
{
$this->moduleDataSetup->startSetup();

payHelper::logDebug('Apply patch: updateFashionGiftcard.');

$connection = $this->resourceConnection->getConnection();
$tableName = $this->resourceConnection->getTableName('core_config_data');

$path = 'payment/paynl_payment_fashiongiftcard/payment_option_id';
$query = "SELECT `value` FROM " . $tableName . " WHERE scope = 'default' AND `path`= '" . $path . "'";

$result = $connection->fetchOne($query, ['path' => $path]);
if (!$result) {
return;
}
payHelper::logDebug('updateFashionGiftcard result ' . $result);
if ($result == '1699') {
# Update the incorrect profileid.
$this->resourceConfig->saveConfig($path, '1669', 'default', 0);
}

$this->moduleDataSetup->endSetup();
}

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

public static function getDependencies()
{
return [];
}

public function getAliases()
{
return [];
}
}
102 changes: 0 additions & 102 deletions Setup/UpgradeData.php

This file was deleted.

0 comments on commit a929eed

Please sign in to comment.