BaseUrlConfigPlugin.php 1.6 KB

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