Skip to content

Commit 96e0c73

Browse files
committed
Merge remote-tracking branch 'upstream/2.4-develop' into 2.4-develop
2 parents 736a1f7 + 715d9de commit 96e0c73

File tree

774 files changed

+19301
-11706
lines changed

Some content is hidden

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

774 files changed

+19301
-11706
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ If you are a new GitHub user, we recommend that you create your own [free github
3131
This will allow you to collaborate with the Magento 2 development team, fork the Magento 2 project and send pull requests.
3232

3333
1. Search current [listed issues](https://github.com/magento/magento2/issues) (open or closed) for similar proposals of intended contribution before starting work on a new contribution.
34-
2. Review the [Contributor License Agreement](https://magento.com/legaldocuments/mca) if this is your first time contributing.
34+
2. Review the [Contributor License Agreement](https://opensource.adobe.com/cla.html) if this is your first time contributing.
3535
3. Create and test your work.
3636
4. Fork the Magento 2 repository according to the [Fork A Repository instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#fork) and when you are ready to send us a pull request – follow the [Create A Pull Request instructions](https://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#pull_request).
3737
5. Once your contribution is received the Magento 2 development team will review the contribution and collaborate with you as needed.

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
{

app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Analytics\Model\Connector;
1212
use Magento\Framework\App\Config\ReinitableConfigInterface;
1313
use Magento\Framework\App\Config\Storage\WriterInterface;
14+
use Magento\Framework\Exception\NotFoundException;
1415
use Magento\Framework\FlagManager;
1516

1617
class UpdateTest extends \PHPUnit\Framework\TestCase
@@ -45,6 +46,9 @@ class UpdateTest extends \PHPUnit\Framework\TestCase
4546
*/
4647
private $update;
4748

49+
/**
50+
* @inheritDoc
51+
*/
4852
protected function setUp()
4953
{
5054
$this->connectorMock = $this->getMockBuilder(Connector::class)
@@ -74,6 +78,7 @@ protected function setUp()
7478

7579
/**
7680
* @return void
81+
* @throws NotFoundException
7782
*/
7883
public function testExecuteWithoutToken()
7984
{
@@ -82,12 +87,12 @@ public function testExecuteWithoutToken()
8287
->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE)
8388
->willReturn(10);
8489
$this->connectorMock
85-
->expects($this->once())
90+
->expects($this->never())
8691
->method('execute')
8792
->with('update')
8893
->willReturn(false);
8994
$this->analyticsTokenMock
90-
->expects($this->once())
95+
->expects($this->any())
9196
->method('isTokenExist')
9297
->willReturn(false);
9398
$this->addFinalOutputAsserts();
@@ -120,6 +125,7 @@ private function addFinalOutputAsserts(bool $isExecuted = true)
120125
* @param $counterData
121126
* @return void
122127
* @dataProvider executeWithEmptyReverseCounterDataProvider
128+
* @throws NotFoundException
123129
*/
124130
public function testExecuteWithEmptyReverseCounter($counterData)
125131
{
@@ -159,6 +165,7 @@ public function executeWithEmptyReverseCounterDataProvider()
159165
* @param bool $functionResult
160166
* @return void
161167
* @dataProvider executeRegularScenarioDataProvider
168+
* @throws NotFoundException
162169
*/
163170
public function testExecuteRegularScenario(
164171
int $reverseCount,
@@ -170,6 +177,10 @@ public function testExecuteRegularScenario(
170177
->method('getFlagData')
171178
->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE)
172179
->willReturn($reverseCount);
180+
$this->flagManagerMock
181+
->expects($this->once())
182+
->method('saveFlag')
183+
->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $reverseCount - 1);
173184
$this->connectorMock
174185
->expects($this->once())
175186
->method('execute')

app/code/Magento/Analytics/etc/adminhtml/system.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<label>Time of day to send data</label>
2929
<frontend_model>Magento\Analytics\Block\Adminhtml\System\Config\CollectionTimeLabel</frontend_model>
3030
<backend_model>Magento\Analytics\Model\Config\Backend\CollectionTime</backend_model>
31+
<depends>
32+
<field id="analytics/general/enabled">1</field>
33+
</depends>
3134
</field>
3235
<field id="vertical" translate="hint label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1">
3336
<hint>Industry Data</hint>
@@ -36,9 +39,9 @@
3639
<source_model>Magento\Analytics\Model\Config\Source\Vertical</source_model>
3740
<backend_model>Magento\Analytics\Model\Config\Backend\Vertical</backend_model>
3841
<frontend_model>Magento\Analytics\Block\Adminhtml\System\Config\Vertical</frontend_model>
39-
<depends>
40-
<field id="analytics/general/enabled">1</field>
41-
</depends>
42+
<depends>
43+
<field id="analytics/general/enabled">1</field>
44+
</depends>
4245
</field>
4346
<field id="additional_comment" translate="label comment" type="label" sortOrder="40" showInDefault="1">
4447
<label><![CDATA[<strong>Get more insights from Magento Business Intelligence</strong>]]></label>

0 commit comments

Comments
 (0)