-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 59272: Update cleaner configs in admin
## What's being changed This PR moves cleaner configs to a new section in Dotdigital > Developer Settings. The setting for `table_cleaner_interval` is now editable. There's a patch to migrate the configs, and I've added some small improvements to the Cleaner class also. ## Why it's being changed Merchants have requested full admin access to certain configs, including `table_cleaner_interval`, so it made sense to move these out of 'Manage Cron Timings' and into their own section. ## How to review / test this change - Before switching to this branch, set configs for the old paths 'connector_developer_settings/cron_schedules/cleaner' and 'connector_developer_settings/cron_schedules/table_cleaner_interval' - Switch to this branch and run setup:upgrade - Confirm the old path values are moved to the new paths - Review the new admin section, check your saved values appear in core_config_data - Test amending the configs, see new values update in the table - Run bin/magento dotdigital:task Cleaner - Confirm it still works i.e. data is purged older than x date - Check email_sms_message_queue is also purged via its plugin Related work items: #242257
- Loading branch information
Showing
5 changed files
with
175 additions
and
21 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
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
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,126 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dotdigitalgroup\Email\Setup\Patch\Data; | ||
|
||
use Dotdigitalgroup\Email\Helper\Config; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
|
||
/** | ||
* Patch is mechanism, that allows to do atomic upgrade data changes | ||
*/ | ||
class UpdateCleanerPaths implements DataPatchInterface | ||
{ | ||
/** | ||
* @var ModuleDataSetupInterface $moduleDataSetup | ||
*/ | ||
private $moduleDataSetup; | ||
|
||
/** | ||
* @param ModuleDataSetupInterface $moduleDataSetup | ||
*/ | ||
public function __construct(ModuleDataSetupInterface $moduleDataSetup) | ||
{ | ||
$this->moduleDataSetup = $moduleDataSetup; | ||
} | ||
|
||
/** | ||
* Do Upgrade | ||
* | ||
* @return void | ||
*/ | ||
public function apply() | ||
{ | ||
$oldCleanerSchedulePath = 'connector_developer_settings/cron_schedules/cleaner'; | ||
$oldCleanerIntervalPath = 'connector_developer_settings/cron_schedules/table_cleaner_interval'; | ||
|
||
$this->moduleDataSetup->getConnection()->startSetup(); | ||
$select = $this->moduleDataSetup->getConnection()->select()->from( | ||
$this->moduleDataSetup->getTable('core_config_data'), | ||
['*'] | ||
)->where('path in (?)', [$oldCleanerSchedulePath, $oldCleanerIntervalPath]); | ||
|
||
foreach ($this->moduleDataSetup->getConnection()->fetchAll($select) as $configRow) { | ||
switch ($configRow['path']) { | ||
case $oldCleanerSchedulePath: | ||
$path = Config::XML_PATH_CRON_SCHEDULE_CLEANER; | ||
break; | ||
case $oldCleanerIntervalPath: | ||
$path = Config::XML_PATH_CRON_SCHEDULE_TABLE_CLEANER_INTERVAL; | ||
break; | ||
} | ||
|
||
if (isset($path)) { | ||
$this->updateRow($configRow, $path); | ||
} | ||
} | ||
$this->moduleDataSetup->getConnection()->endSetup(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getAliases() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function getDependencies() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Update consent record row paths. | ||
* | ||
* @param array $configRow | ||
* @param string $path | ||
* @return void | ||
*/ | ||
private function updateRow($configRow, $path) | ||
{ | ||
if ($this->keyAlreadyExists($path)) { | ||
$this->moduleDataSetup->getConnection()->delete( | ||
$this->moduleDataSetup->getTable('core_config_data'), | ||
['path = ?' => $configRow['path']] | ||
); | ||
return; | ||
} | ||
|
||
$this->moduleDataSetup->getConnection()->update( | ||
$this->moduleDataSetup->getTable('core_config_data'), | ||
[ | ||
'path' => $path, | ||
], | ||
[ | ||
'path = ?' => $configRow['path'] | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Check if newer path name equivalent already exists. | ||
* | ||
* @param string $path | ||
* | ||
* @return bool | ||
*/ | ||
private function keyAlreadyExists($path) | ||
{ | ||
$existingKey = $this->moduleDataSetup->getConnection()->select()->from( | ||
$this->moduleDataSetup->getTable('core_config_data'), | ||
['*'] | ||
)->where( | ||
'path = ?', | ||
$path | ||
); | ||
|
||
$result = $this->moduleDataSetup->getConnection()->fetchAll($existingKey); | ||
return count($result) > 0; | ||
} | ||
} |
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
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