Skip to content

Commit 390facb

Browse files
Merge branch 'MC-32099' into 2.3-develop-com-pr17
2 parents e8e94c9 + d1872c9 commit 390facb

File tree

97 files changed

+2226
-707
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2226
-707
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
10+
<policies>
11+
<policy id="script-src">
12+
<values>
13+
<value id="adobedtm" type="host">assets.adobedtm.com</value>
14+
</values>
15+
</policy>
16+
</policies>
17+
</csp_whitelist>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
10+
<policies>
11+
<policy id="img-src">
12+
<values>
13+
<value id="commerce_widgets" type="host">widgets.magentocommerce.com</value>
14+
</values>
15+
</policy>
16+
</policies>
17+
</csp_whitelist>
18+

app/code/Magento/Analytics/Cron/SignUp.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
99
use Magento\Analytics\Model\Connector;
10+
use Magento\Framework\Exception\NotFoundException;
1011
use Magento\Framework\FlagManager;
1112
use Magento\Framework\App\Config\ReinitableConfigInterface;
1213
use Magento\Framework\App\Config\Storage\WriterInterface;
@@ -57,22 +58,24 @@ public function __construct(
5758
}
5859

5960
/**
60-
* Execute scheduled subscription operation
61+
* Execute scheduled subscription operation.
62+
*
6163
* In case of failure writes message to notifications inbox
6264
*
6365
* @return bool
66+
* @throws NotFoundException
6467
*/
6568
public function execute()
6669
{
67-
$attemptsCount = $this->flagManager->getFlagData(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE);
70+
$attemptsCount = (int)$this->flagManager->getFlagData(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE);
6871

69-
if (($attemptsCount === null) || ($attemptsCount <= 0)) {
72+
if ($attemptsCount <= 0) {
7073
$this->deleteAnalyticsCronExpr();
7174
$this->flagManager->deleteFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE);
7275
return false;
7376
}
7477

75-
$attemptsCount -= 1;
78+
$attemptsCount--;
7679
$this->flagManager->saveFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, $attemptsCount);
7780
$signUpResult = $this->connector->execute('signUp');
7881
if ($signUpResult === false) {

app/code/Magento/Analytics/Cron/Update.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Analytics\Model\AnalyticsToken;
99
use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler;
1010
use Magento\Analytics\Model\Connector;
11+
use Magento\Framework\Exception\NotFoundException;
1112
use Magento\Framework\FlagManager;
1213
use Magento\Framework\App\Config\ReinitableConfigInterface;
1314
use Magento\Framework\App\Config\Storage\WriterInterface;
@@ -67,26 +68,37 @@ public function __construct(
6768
* Execute scheduled update operation
6869
*
6970
* @return bool
71+
* @throws NotFoundException
7072
*/
7173
public function execute()
7274
{
7375
$result = false;
74-
$attemptsCount = $this->flagManager
76+
$attemptsCount = (int)$this->flagManager
7577
->getFlagData(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE);
7678

77-
if ($attemptsCount) {
78-
$attemptsCount -= 1;
79+
if (($attemptsCount > 0) && $this->analyticsToken->isTokenExist()) {
80+
$attemptsCount--;
81+
$this->flagManager
82+
->saveFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $attemptsCount);
7983
$result = $this->connector->execute('update');
8084
}
8185

8286
if ($result || ($attemptsCount <= 0) || (!$this->analyticsToken->isTokenExist())) {
83-
$this->flagManager
84-
->deleteFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE);
85-
$this->flagManager->deleteFlag(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE);
86-
$this->configWriter->delete(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH);
87-
$this->reinitableConfig->reinit();
87+
$this->exitFromUpdateProcess();
8888
}
8989

9090
return $result;
9191
}
92+
93+
/**
94+
* Clean-up flags and refresh configuration
95+
*/
96+
private function exitFromUpdateProcess(): void
97+
{
98+
$this->flagManager
99+
->deleteFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE);
100+
$this->flagManager->deleteFlag(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE);
101+
$this->configWriter->delete(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH);
102+
$this->reinitableConfig->reinit();
103+
}
92104
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Analytics\Setup\Patch\Data;
10+
11+
use Magento\Analytics\Model\Config\Backend\CollectionTime;
12+
use Magento\Analytics\Model\SubscriptionStatusProvider;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\Exception\LocalizedException;
15+
use Magento\Framework\Setup\Patch\DataPatchInterface;
16+
17+
/**
18+
* Activate data collection mechanism
19+
*/
20+
class ActivateDataCollection implements DataPatchInterface
21+
{
22+
/**
23+
* @var ScopeConfigInterface
24+
*/
25+
private $scopeConfig;
26+
27+
/**
28+
* @var SubscriptionStatusProvider
29+
*/
30+
private $subscriptionStatusProvider;
31+
32+
/**
33+
* @var string
34+
*/
35+
private $analyticsCollectionTimeConfigPath = 'analytics/general/collection_time';
36+
37+
/**
38+
* @var CollectionTime
39+
*/
40+
private $collectionTimeBackendModel;
41+
42+
/**
43+
* @param ScopeConfigInterface $scopeConfig
44+
* @param SubscriptionStatusProvider $subscriptionStatusProvider
45+
* @param CollectionTime $collectionTimeBackendModel
46+
*/
47+
public function __construct(
48+
ScopeConfigInterface $scopeConfig,
49+
SubscriptionStatusProvider $subscriptionStatusProvider,
50+
CollectionTime $collectionTimeBackendModel
51+
) {
52+
$this->scopeConfig = $scopeConfig;
53+
$this->subscriptionStatusProvider = $subscriptionStatusProvider;
54+
$this->collectionTimeBackendModel = $collectionTimeBackendModel;
55+
}
56+
57+
/**
58+
* @inheritDoc
59+
*
60+
* @throws LocalizedException
61+
*/
62+
public function apply()
63+
{
64+
$subscriptionStatus = $this->subscriptionStatusProvider->getStatus();
65+
$isCollectionProcessActivated = $this->scopeConfig->getValue(CollectionTime::CRON_SCHEDULE_PATH);
66+
if ($subscriptionStatus !== $this->subscriptionStatusProvider->getStatusForDisabledSubscription()
67+
&& !$isCollectionProcessActivated
68+
) {
69+
$this->collectionTimeBackendModel
70+
->setValue($this->scopeConfig->getValue($this->analyticsCollectionTimeConfigPath));
71+
$this->collectionTimeBackendModel->setPath($this->analyticsCollectionTimeConfigPath);
72+
$this->collectionTimeBackendModel->afterSave();
73+
}
74+
75+
return $this;
76+
}
77+
78+
/**
79+
* @inheritDoc
80+
*/
81+
public function getAliases()
82+
{
83+
return [];
84+
}
85+
86+
/**
87+
* @inheritDoc
88+
*/
89+
public static function getDependencies()
90+
{
91+
return [
92+
PrepareInitialConfig::class,
93+
];
94+
}
95+
}

app/code/Magento/Analytics/Setup/Patch/Data/PrepareInitialConfig.php

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Magento\Analytics\Setup\Patch\Data;
810

911
use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
12+
use Magento\Config\Model\Config\Source\Enabledisable;
1013
use Magento\Framework\Setup\ModuleDataSetupInterface;
1114
use Magento\Framework\Setup\Patch\DataPatchInterface;
1215
use Magento\Framework\Setup\Patch\PatchVersionInterface;
1316

1417
/**
15-
* Initial patch.
16-
*
17-
* @package Magento\Analytics\Setup\Patch
18+
* Active subscription process for Advanced Reporting
1819
*/
1920
class PrepareInitialConfig implements DataPatchInterface, PatchVersionInterface
2021
{
@@ -24,66 +25,63 @@ class PrepareInitialConfig implements DataPatchInterface, PatchVersionInterface
2425
private $moduleDataSetup;
2526

2627
/**
27-
* PrepareInitialConfig constructor.
28+
* @var SubscriptionHandler
29+
*/
30+
private $subscriptionHandler;
31+
32+
/**
33+
* @var string
34+
*/
35+
private $subscriptionEnabledConfigPath = 'analytics/subscription/enabled';
36+
37+
/**
2838
* @param ModuleDataSetupInterface $moduleDataSetup
39+
* @param SubscriptionHandler $subscriptionHandler
2940
*/
3041
public function __construct(
31-
ModuleDataSetupInterface $moduleDataSetup
42+
ModuleDataSetupInterface $moduleDataSetup,
43+
SubscriptionHandler $subscriptionHandler
3244
) {
3345
$this->moduleDataSetup = $moduleDataSetup;
46+
$this->subscriptionHandler = $subscriptionHandler;
3447
}
3548

3649
/**
37-
* {@inheritdoc}
50+
* @inheritDoc
3851
*/
3952
public function apply()
4053
{
41-
$this->moduleDataSetup->getConnection()->insertMultiple(
54+
$this->moduleDataSetup->getConnection()->insert(
4255
$this->moduleDataSetup->getTable('core_config_data'),
4356
[
44-
[
45-
'scope' => 'default',
46-
'scope_id' => 0,
47-
'path' => 'analytics/subscription/enabled',
48-
'value' => 1
49-
],
50-
[
51-
'scope' => 'default',
52-
'scope_id' => 0,
53-
'path' => SubscriptionHandler::CRON_STRING_PATH,
54-
'value' => join(' ', SubscriptionHandler::CRON_EXPR_ARRAY)
55-
]
57+
'path' => $this->subscriptionEnabledConfigPath,
58+
'value' => Enabledisable::ENABLE_VALUE,
5659
]
5760
);
5861

59-
$this->moduleDataSetup->getConnection()->insert(
60-
$this->moduleDataSetup->getTable('flag'),
61-
[
62-
'flag_code' => SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE,
63-
'state' => 0,
64-
'flag_data' => 24,
65-
]
66-
);
62+
$this->subscriptionHandler->processEnabled();
63+
64+
return $this;
6765
}
6866

6967
/**
70-
* {@inheritdoc}
68+
* @inheritDoc
7169
*/
7270
public static function getDependencies()
7371
{
7472
return [];
7573
}
7674

7775
/**
78-
* {@inheritdoc}
76+
* @inheritDoc
7977
*/
8078
public static function getVersion()
8179
{
8280
return '2.0.0';
8381
}
8482

8583
/**
86-
* {@inheritdoc}
84+
* @inheritDoc
8785
*/
8886
public function getAliases()
8987
{

0 commit comments

Comments
 (0)