Skip to content

Commit

Permalink
Merge branch '2.4-develop' into fix-adobe-stock-issue-1002
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaschenko authored Mar 26, 2020
2 parents 9c5528f + f3df323 commit e428056
Show file tree
Hide file tree
Showing 661 changed files with 13,606 additions and 10,675 deletions.
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions app/code/Magento/Analytics/Cron/SignUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 20 additions & 8 deletions app/code/Magento/Analytics/Cron/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Analytics\Setup\Patch\Data;

use Magento\Analytics\Model\Config\Backend\CollectionTime;
use Magento\Analytics\Model\SubscriptionStatusProvider;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Setup\Patch\DataPatchInterface;

/**
* Activate data collection mechanism
*/
class ActivateDataCollection implements DataPatchInterface
{
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var SubscriptionStatusProvider
*/
private $subscriptionStatusProvider;

/**
* @var string
*/
private $analyticsCollectionTimeConfigPath = 'analytics/general/collection_time';

/**
* @var CollectionTime
*/
private $collectionTimeBackendModel;

/**
* @param ScopeConfigInterface $scopeConfig
* @param SubscriptionStatusProvider $subscriptionStatusProvider
* @param CollectionTime $collectionTimeBackendModel
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
SubscriptionStatusProvider $subscriptionStatusProvider,
CollectionTime $collectionTimeBackendModel
) {
$this->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,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -24,66 +25,63 @@ 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()
{
return [];
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public static function getVersion()
{
return '2.0.0';
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function getAliases()
{
Expand Down
15 changes: 13 additions & 2 deletions app/code/Magento/Analytics/Test/Unit/Cron/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,6 +46,9 @@ class UpdateTest extends \PHPUnit\Framework\TestCase
*/
private $update;

/**
* @inheritDoc
*/
protected function setUp()
{
$this->connectorMock = $this->getMockBuilder(Connector::class)
Expand Down Expand Up @@ -74,6 +78,7 @@ protected function setUp()

/**
* @return void
* @throws NotFoundException
*/
public function testExecuteWithoutToken()
{
Expand All @@ -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();
Expand Down Expand Up @@ -120,6 +125,7 @@ private function addFinalOutputAsserts(bool $isExecuted = true)
* @param $counterData
* @return void
* @dataProvider executeWithEmptyReverseCounterDataProvider
* @throws NotFoundException
*/
public function testExecuteWithEmptyReverseCounter($counterData)
{
Expand Down Expand Up @@ -159,6 +165,7 @@ public function executeWithEmptyReverseCounterDataProvider()
* @param bool $functionResult
* @return void
* @dataProvider executeRegularScenarioDataProvider
* @throws NotFoundException
*/
public function testExecuteRegularScenario(
int $reverseCount,
Expand All @@ -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')
Expand Down
9 changes: 6 additions & 3 deletions app/code/Magento/Analytics/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<label>Time of day to send data</label>
<frontend_model>Magento\Analytics\Block\Adminhtml\System\Config\CollectionTimeLabel</frontend_model>
<backend_model>Magento\Analytics\Model\Config\Backend\CollectionTime</backend_model>
<depends>
<field id="analytics/general/enabled">1</field>
</depends>
</field>
<field id="vertical" translate="hint label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1">
<hint>Industry Data</hint>
Expand All @@ -36,9 +39,9 @@
<source_model>Magento\Analytics\Model\Config\Source\Vertical</source_model>
<backend_model>Magento\Analytics\Model\Config\Backend\Vertical</backend_model>
<frontend_model>Magento\Analytics\Block\Adminhtml\System\Config\Vertical</frontend_model>
<depends>
<field id="analytics/general/enabled">1</field>
</depends>
<depends>
<field id="analytics/general/enabled">1</field>
</depends>
</field>
<field id="additional_comment" translate="label comment" type="label" sortOrder="40" showInDefault="1">
<label><![CDATA[<strong>Get more insights from Magento Business Intelligence</strong>]]></label>
Expand Down
Loading

0 comments on commit e428056

Please sign in to comment.