Skip to content

Commit 4406ac8

Browse files
Bohdan KorablovYevhen Miroshnychenko
authored andcommitted
MAGECLOUD-2501: Review cron:unlock Command Compatibility with MAGECLOUD-2445 Changes (#351)
* MAGECLOUD-2501: Review cron:unlock Command Compatibility with MAGECLOUD-2445 Changes
1 parent 308b13a commit 4406ac8

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/App/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ function () {
229229
'processes' => [
230230
$this->container->make(DeployProcess\PreDeploy::class),
231231
$this->container->make(DeployProcess\DisableCron::class),
232+
$this->container->make(DeployProcess\UnlockCronJobs::class),
232233
$this->container->make(\Magento\MagentoCloud\Process\ValidateConfiguration::class, [
233234
'validators' => [
234235
ValidatorInterface::LEVEL_CRITICAL => [
@@ -253,7 +254,6 @@ function () {
253254
$this->container->make(DeployProcess\DeployStaticContent::class),
254255
$this->container->make(DeployProcess\CompressStaticContent::class),
255256
$this->container->make(DeployProcess\DisableGoogleAnalytics::class),
256-
$this->container->make(DeployProcess\UnlockCronJobs::class),
257257
$this->container->make(DeployProcess\EnableCron::class),
258258

259259
/**

src/Process/Deploy/UnlockCronJobs.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\MagentoCloud\Process\Deploy;
77

88
use Magento\MagentoCloud\Cron\JobUnlocker;
9+
use Magento\MagentoCloud\Package\MagentoVersion;
910
use Magento\MagentoCloud\Process\ProcessInterface;
1011
use Psr\Log\LoggerInterface;
1112

@@ -28,16 +29,24 @@ class UnlockCronJobs implements ProcessInterface
2829
*/
2930
private $jobUnlocker;
3031

32+
/**
33+
* @var MagentoVersion
34+
*/
35+
private $magentoVersion;
36+
3137
/**
3238
* @param JobUnlocker $jobUnlocker
3339
* @param LoggerInterface $logger
40+
* @param MagentoVersion $version
3441
*/
3542
public function __construct(
3643
JobUnlocker $jobUnlocker,
37-
LoggerInterface $logger
44+
LoggerInterface $logger,
45+
MagentoVersion $version
3846
) {
3947
$this->jobUnlocker = $jobUnlocker;
4048
$this->logger = $logger;
49+
$this->magentoVersion = $version;
4150
}
4251

4352
/**
@@ -47,6 +56,13 @@ public function __construct(
4756
*/
4857
public function execute()
4958
{
59+
/**
60+
* Since version 2.2.2 Magento unlocks cron jobs during upgrade
61+
*/
62+
if ($this->magentoVersion->isGreaterOrEqual('2.2.2')) {
63+
return;
64+
}
65+
5066
$updatedJobsCount = $this->jobUnlocker->unlockAll();
5167

5268
if ($updatedJobsCount) {

src/Test/Unit/Process/Deploy/UnlockCronJobsTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\MagentoCloud\Test\Unit\Process\Deploy;
77

88
use Magento\MagentoCloud\Cron\JobUnlocker;
9+
use Magento\MagentoCloud\Package\MagentoVersion;
910
use Magento\MagentoCloud\Process\Deploy\UnlockCronJobs;
1011
use PHPUnit\Framework\MockObject\MockObject;
1112
use PHPUnit\Framework\TestCase;
@@ -26,6 +27,11 @@ class UnlockCronJobsTest extends TestCase
2627
*/
2728
private $jobUnlockerMock;
2829

30+
/**
31+
* @var MagentoVersion|MockObject
32+
*/
33+
private $magentoVersionMock;
34+
2935
/**
3036
* @var UnlockCronJobs
3137
*/
@@ -38,15 +44,19 @@ protected function setUp()
3844
{
3945
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
4046
$this->jobUnlockerMock = $this->createMock(JobUnlocker::class);
47+
$this->magentoVersionMock = $this->createMock(MagentoVersion::class);
4148

4249
$this->process = new UnlockCronJobs(
4350
$this->jobUnlockerMock,
44-
$this->loggerMock
51+
$this->loggerMock,
52+
$this->magentoVersionMock
4553
);
4654
}
4755

4856
public function testExecute()
4957
{
58+
$this->magentoVersionMock->method('isGreaterOrEqual')
59+
->willReturn(false);
5060
$this->jobUnlockerMock->expects($this->once())
5161
->method('unlockAll')
5262
->willReturn(5);
@@ -59,6 +69,8 @@ public function testExecute()
5969

6070
public function testExecuteNoJobsUpdated()
6171
{
72+
$this->magentoVersionMock->method('isGreaterOrEqual')
73+
->willReturn(false);
6274
$this->jobUnlockerMock->expects($this->once())
6375
->method('unlockAll')
6476
->willReturn(0);
@@ -67,4 +79,16 @@ public function testExecuteNoJobsUpdated()
6779

6880
$this->process->execute();
6981
}
82+
83+
public function testSkipExecute()
84+
{
85+
$this->magentoVersionMock->expects($this->once())
86+
->method('isGreaterOrEqual')
87+
->with('2.2.2')
88+
->willReturn(true);
89+
$this->jobUnlockerMock->expects($this->never())
90+
->method('unlockAll');
91+
92+
$this->process->execute();
93+
}
7094
}

0 commit comments

Comments
 (0)