diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 89aea7299855c..37b7bc2ca8c3a 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -31,7 +31,7 @@ If you are a new GitHub user, we recommend that you create your own [free github
This will allow you to collaborate with the Magento 2 development team, fork the Magento 2 project and send pull requests.
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.
-2. Review the [Contributor License Agreement](https://magento.com/legaldocuments/mca) if this is your first time contributing.
+2. Review the [Contributor License Agreement](https://opensource.adobe.com/cla.html) if this is your first time contributing.
3. Create and test your work.
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).
5. Once your contribution is received the Magento 2 development team will review the contribution and collaborate with you as needed.
diff --git a/app/code/Magento/Analytics/Cron/SignUp.php b/app/code/Magento/Analytics/Cron/SignUp.php
index 8f97b839ec8ee..2588b87e84c1c 100644
--- a/app/code/Magento/Analytics/Cron/SignUp.php
+++ b/app/code/Magento/Analytics/Cron/SignUp.php
@@ -7,6 +7,7 @@
use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
use Magento\Analytics\Model\Connector;
+use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\FlagManager;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
@@ -57,22 +58,24 @@ public function __construct(
}
/**
- * Execute scheduled subscription operation
+ * Execute scheduled subscription operation.
+ *
* In case of failure writes message to notifications inbox
*
* @return bool
+ * @throws NotFoundException
*/
public function execute()
{
- $attemptsCount = $this->flagManager->getFlagData(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE);
+ $attemptsCount = (int)$this->flagManager->getFlagData(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE);
- if (($attemptsCount === null) || ($attemptsCount <= 0)) {
+ if ($attemptsCount <= 0) {
$this->deleteAnalyticsCronExpr();
$this->flagManager->deleteFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE);
return false;
}
- $attemptsCount -= 1;
+ $attemptsCount--;
$this->flagManager->saveFlag(SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE, $attemptsCount);
$signUpResult = $this->connector->execute('signUp');
if ($signUpResult === false) {
diff --git a/app/code/Magento/Analytics/Cron/Update.php b/app/code/Magento/Analytics/Cron/Update.php
index 9062a7bac7551..b5e4b82a0777e 100644
--- a/app/code/Magento/Analytics/Cron/Update.php
+++ b/app/code/Magento/Analytics/Cron/Update.php
@@ -8,6 +8,7 @@
use Magento\Analytics\Model\AnalyticsToken;
use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler;
use Magento\Analytics\Model\Connector;
+use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\FlagManager;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
@@ -67,26 +68,37 @@ public function __construct(
* Execute scheduled update operation
*
* @return bool
+ * @throws NotFoundException
*/
public function execute()
{
$result = false;
- $attemptsCount = $this->flagManager
+ $attemptsCount = (int)$this->flagManager
->getFlagData(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE);
- if ($attemptsCount) {
- $attemptsCount -= 1;
+ if (($attemptsCount > 0) && $this->analyticsToken->isTokenExist()) {
+ $attemptsCount--;
+ $this->flagManager
+ ->saveFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $attemptsCount);
$result = $this->connector->execute('update');
}
if ($result || ($attemptsCount <= 0) || (!$this->analyticsToken->isTokenExist())) {
- $this->flagManager
- ->deleteFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE);
- $this->flagManager->deleteFlag(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE);
- $this->configWriter->delete(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH);
- $this->reinitableConfig->reinit();
+ $this->exitFromUpdateProcess();
}
return $result;
}
+
+ /**
+ * Clean-up flags and refresh configuration
+ */
+ private function exitFromUpdateProcess(): void
+ {
+ $this->flagManager
+ ->deleteFlag(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE);
+ $this->flagManager->deleteFlag(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE);
+ $this->configWriter->delete(SubscriptionUpdateHandler::UPDATE_CRON_STRING_PATH);
+ $this->reinitableConfig->reinit();
+ }
}
diff --git a/app/code/Magento/Analytics/Setup/Patch/Data/ActivateDataCollection.php b/app/code/Magento/Analytics/Setup/Patch/Data/ActivateDataCollection.php
new file mode 100644
index 0000000000000..dd60d74b53d09
--- /dev/null
+++ b/app/code/Magento/Analytics/Setup/Patch/Data/ActivateDataCollection.php
@@ -0,0 +1,95 @@
+scopeConfig = $scopeConfig;
+ $this->subscriptionStatusProvider = $subscriptionStatusProvider;
+ $this->collectionTimeBackendModel = $collectionTimeBackendModel;
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @throws LocalizedException
+ */
+ public function apply()
+ {
+ $subscriptionStatus = $this->subscriptionStatusProvider->getStatus();
+ $isCollectionProcessActivated = $this->scopeConfig->getValue(CollectionTime::CRON_SCHEDULE_PATH);
+ if ($subscriptionStatus !== $this->subscriptionStatusProvider->getStatusForDisabledSubscription()
+ && !$isCollectionProcessActivated
+ ) {
+ $this->collectionTimeBackendModel
+ ->setValue($this->scopeConfig->getValue($this->analyticsCollectionTimeConfigPath));
+ $this->collectionTimeBackendModel->setPath($this->analyticsCollectionTimeConfigPath);
+ $this->collectionTimeBackendModel->afterSave();
+ }
+
+ return $this;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getAliases()
+ {
+ return [];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public static function getDependencies()
+ {
+ return [
+ PrepareInitialConfig::class,
+ ];
+ }
+}
diff --git a/app/code/Magento/Analytics/Setup/Patch/Data/PrepareInitialConfig.php b/app/code/Magento/Analytics/Setup/Patch/Data/PrepareInitialConfig.php
index a352854a8b77b..97ac340f9d491 100644
--- a/app/code/Magento/Analytics/Setup/Patch/Data/PrepareInitialConfig.php
+++ b/app/code/Magento/Analytics/Setup/Patch/Data/PrepareInitialConfig.php
@@ -4,17 +4,18 @@
* See COPYING.txt for license details.
*/
+declare(strict_types=1);
+
namespace Magento\Analytics\Setup\Patch\Data;
use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
+use Magento\Config\Model\Config\Source\Enabledisable;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchVersionInterface;
/**
- * Initial patch.
- *
- * @package Magento\Analytics\Setup\Patch
+ * Active subscription process for Advanced Reporting
*/
class PrepareInitialConfig implements DataPatchInterface, PatchVersionInterface
{
@@ -24,50 +25,47 @@ class PrepareInitialConfig implements DataPatchInterface, PatchVersionInterface
private $moduleDataSetup;
/**
- * PrepareInitialConfig constructor.
+ * @var SubscriptionHandler
+ */
+ private $subscriptionHandler;
+
+ /**
+ * @var string
+ */
+ private $subscriptionEnabledConfigPath = 'analytics/subscription/enabled';
+
+ /**
* @param ModuleDataSetupInterface $moduleDataSetup
+ * @param SubscriptionHandler $subscriptionHandler
*/
public function __construct(
- ModuleDataSetupInterface $moduleDataSetup
+ ModuleDataSetupInterface $moduleDataSetup,
+ SubscriptionHandler $subscriptionHandler
) {
$this->moduleDataSetup = $moduleDataSetup;
+ $this->subscriptionHandler = $subscriptionHandler;
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
public function apply()
{
- $this->moduleDataSetup->getConnection()->insertMultiple(
+ $this->moduleDataSetup->getConnection()->insert(
$this->moduleDataSetup->getTable('core_config_data'),
[
- [
- 'scope' => 'default',
- 'scope_id' => 0,
- 'path' => 'analytics/subscription/enabled',
- 'value' => 1
- ],
- [
- 'scope' => 'default',
- 'scope_id' => 0,
- 'path' => SubscriptionHandler::CRON_STRING_PATH,
- 'value' => join(' ', SubscriptionHandler::CRON_EXPR_ARRAY)
- ]
+ 'path' => $this->subscriptionEnabledConfigPath,
+ 'value' => Enabledisable::ENABLE_VALUE,
]
);
- $this->moduleDataSetup->getConnection()->insert(
- $this->moduleDataSetup->getTable('flag'),
- [
- 'flag_code' => SubscriptionHandler::ATTEMPTS_REVERSE_COUNTER_FLAG_CODE,
- 'state' => 0,
- 'flag_data' => 24,
- ]
- );
+ $this->subscriptionHandler->processEnabled();
+
+ return $this;
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
public static function getDependencies()
{
@@ -75,7 +73,7 @@ public static function getDependencies()
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
public static function getVersion()
{
@@ -83,7 +81,7 @@ public static function getVersion()
}
/**
- * {@inheritdoc}
+ * @inheritDoc
*/
public function getAliases()
{
diff --git a/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php b/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php
index aa3011ffc94f6..fa007268474c4 100644
--- a/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php
+++ b/app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php
@@ -11,6 +11,7 @@
use Magento\Analytics\Model\Connector;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
+use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\FlagManager;
class UpdateTest extends \PHPUnit\Framework\TestCase
@@ -45,6 +46,9 @@ class UpdateTest extends \PHPUnit\Framework\TestCase
*/
private $update;
+ /**
+ * @inheritDoc
+ */
protected function setUp()
{
$this->connectorMock = $this->getMockBuilder(Connector::class)
@@ -74,6 +78,7 @@ protected function setUp()
/**
* @return void
+ * @throws NotFoundException
*/
public function testExecuteWithoutToken()
{
@@ -82,12 +87,12 @@ public function testExecuteWithoutToken()
->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE)
->willReturn(10);
$this->connectorMock
- ->expects($this->once())
+ ->expects($this->never())
->method('execute')
->with('update')
->willReturn(false);
$this->analyticsTokenMock
- ->expects($this->once())
+ ->expects($this->any())
->method('isTokenExist')
->willReturn(false);
$this->addFinalOutputAsserts();
@@ -120,6 +125,7 @@ private function addFinalOutputAsserts(bool $isExecuted = true)
* @param $counterData
* @return void
* @dataProvider executeWithEmptyReverseCounterDataProvider
+ * @throws NotFoundException
*/
public function testExecuteWithEmptyReverseCounter($counterData)
{
@@ -159,6 +165,7 @@ public function executeWithEmptyReverseCounterDataProvider()
* @param bool $functionResult
* @return void
* @dataProvider executeRegularScenarioDataProvider
+ * @throws NotFoundException
*/
public function testExecuteRegularScenario(
int $reverseCount,
@@ -170,6 +177,10 @@ public function testExecuteRegularScenario(
->method('getFlagData')
->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE)
->willReturn($reverseCount);
+ $this->flagManagerMock
+ ->expects($this->once())
+ ->method('saveFlag')
+ ->with(SubscriptionUpdateHandler::SUBSCRIPTION_UPDATE_REVERSE_COUNTER_FLAG_CODE, $reverseCount - 1);
$this->connectorMock
->expects($this->once())
->method('execute')
diff --git a/app/code/Magento/Analytics/etc/adminhtml/system.xml b/app/code/Magento/Analytics/etc/adminhtml/system.xml
index 999d565353329..0aba6e4dd00ed 100644
--- a/app/code/Magento/Analytics/etc/adminhtml/system.xml
+++ b/app/code/Magento/Analytics/etc/adminhtml/system.xml
@@ -28,6 +28,9 @@
Magento\Analytics\Block\Adminhtml\System\Config\CollectionTimeLabel
Magento\Analytics\Model\Config\Backend\CollectionTime
+
+ 1
+
Industry Data
@@ -36,9 +39,9 @@
Magento\Analytics\Model\Config\Source\Vertical
Magento\Analytics\Model\Config\Backend\Vertical
Magento\Analytics\Block\Adminhtml\System\Config\Vertical
-
- 1
-
+
+ 1
+