1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Analytics\Model\Plugin;
use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Config\Value;
use Magento\Store\Model\Store;
/**
* Plugin on Base URL config value AfterSave method.
*/
class BaseUrlConfigPlugin
{
/**
* @var SubscriptionUpdateHandler
*/
private $subscriptionUpdateHandler;
/**
* @param SubscriptionUpdateHandler $subscriptionUpdateHandler
*/
public function __construct(
SubscriptionUpdateHandler $subscriptionUpdateHandler
) {
$this->subscriptionUpdateHandler = $subscriptionUpdateHandler;
}
/**
* Add additional handling after config value was saved.
*
* @param Value $subject
* @param Value $result
* @return Value
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterAfterSave(
Value $subject,
Value $result
) {
if ($this->isPluginApplicable($result)) {
$this->subscriptionUpdateHandler->processUrlUpdate($result->getOldValue());
}
return $result;
}
/**
* @param Value $result
* @return bool
*/
private function isPluginApplicable(Value $result)
{
return $result->isValueChanged()
&& ($result->getPath() === Store::XML_PATH_SECURE_BASE_URL)
&& ($result->getScope() === ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
}
}