Skip to content

Commit 3e9dd01

Browse files
Merge pull request #1774 from magento-tango/2.2.2-develop-PR
Bugs: - MAGETWO-84000 Undefined index: region_id is presented after save customer address - MAGETWO-84106 [2.2.1] Implementation (fix) of session locking mechanism in php-redis-session-abstract leads to 30 sec timeout - MAGETWO-84544 Configurable product reindex too slow for big amount of options - MAGETWO-84646 Cron jobs incorrect behavior when running job terminated
2 parents 60854ad + d02fd00 commit 3e9dd01

File tree

9 files changed

+107
-21
lines changed

9 files changed

+107
-21
lines changed

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/Configurable.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ protected function _applyConfigurableOption()
133133
['le' => $this->getTable('catalog_product_entity')],
134134
'le.' . $linkField . ' = l.parent_id',
135135
['parent_id' => 'entity_id']
136+
)->join(
137+
['i' => $this->_getDefaultFinalPriceTable()],
138+
'le.entity_id = i.entity_id',
139+
[]
136140
);
137141

138142
$select = $connection->select();

app/code/Magento/Cron/Model/ResourceModel/Schedule.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ public function trySetJobUniqueStatusAtomic($scheduleId, $newStatus, $currentSta
6666
{
6767
$connection = $this->getConnection();
6868

69-
$match = $connection->quoteInto('existing.job_code = current.job_code AND existing.status = ?', $newStatus);
69+
// this condition added to avoid cron jobs locking after incorrect termination of running job
70+
$match = $connection->quoteInto(
71+
'existing.job_code = current.job_code ' .
72+
'AND (existing.executed_at > UTC_TIMESTAMP() - INTERVAL 1 DAY OR existing.executed_at IS NULL) ' .
73+
'AND existing.status = ?',
74+
$newStatus
75+
);
76+
7077
$selectIfUnlocked = $connection->select()
7178
->joinLeft(
7279
['existing' => $this->getTable('cron_schedule')],
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Cron\Setup;
8+
9+
use Magento\Framework\Setup\InstallSchemaInterface;
10+
use Magento\Framework\Setup\ModuleContextInterface;
11+
use Magento\Framework\Setup\SchemaSetupInterface;
12+
13+
/**
14+
* Cron recurring setup
15+
*/
16+
class Recurring implements InstallSchemaInterface
17+
{
18+
/**
19+
* @var \Magento\Cron\Model\ResourceModel\Schedule
20+
*/
21+
private $schedule;
22+
23+
/**
24+
* Recurring constructor.
25+
* @param \Magento\Cron\Model\ResourceModel\Schedule $schedule
26+
*/
27+
public function __construct(
28+
\Magento\Cron\Model\ResourceModel\Schedule $schedule
29+
) {
30+
$this->schedule = $schedule;
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
37+
{
38+
$connection = $this->schedule->getConnection();
39+
$connection->update(
40+
$this->schedule->getMainTable(),
41+
[
42+
'status' => \Magento\Cron\Model\Schedule::STATUS_ERROR,
43+
'messages' => 'The job is terminated due to system upgrade'
44+
],
45+
$connection->quoteInto('status = ?', \Magento\Cron\Model\Schedule::STATUS_RUNNING)
46+
);
47+
}
48+
}

app/code/Magento/Customer/Block/Address/Edit.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ protected function _prepareLayout()
139139

140140
if ($postedData = $this->_customerSession->getAddressFormData(true)) {
141141
$postedData['region'] = [
142-
'region_id' => $postedData['region_id'],
143-
'region' => $postedData['region'],
142+
'region' => $postedData['region'] ?? null,
144143
];
144+
if (!empty($postedData['region_id'])) {
145+
$postedData['region']['region_id'] = $postedData['region_id'];
146+
}
145147
$this->dataObjectHelper->populateWithArray(
146148
$this->_address,
147149
$postedData,

app/code/Magento/Customer/Model/AttributeChecker.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\Customer\Api\AddressMetadataInterface;
99
use Magento\Customer\Api\AddressMetadataManagementInterface;
1010
use Magento\Customer\Model\Metadata\AttributeResolver;
11-
use Magento\Framework\App\Helper\Context;
1211

1312
/**
1413
* Customer attribute checker.

app/code/Magento/Customer/Test/Unit/Block/Address/EditTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ protected function setUp()
101101
);
102102
}
103103

104-
public function testSetLayoutWithOwnAddressAndPostedData()
104+
/**
105+
* @param array $postedData
106+
* @dataProvider postedDataProvider
107+
*/
108+
public function testSetLayoutWithOwnAddressAndPostedData(array $postedData)
105109
{
106110
$addressId = 1;
107111
$customerId = 1;
108112
$title = __('Edit Address');
109-
$postedData = [
110-
'region_id' => 1,
111-
'region' => 'region',
112-
];
113113
$newPostedData = $postedData;
114114
$newPostedData['region'] = $postedData;
115115

@@ -169,6 +169,21 @@ public function testSetLayoutWithOwnAddressAndPostedData()
169169
$this->assertEquals($layoutMock, $this->model->getLayout());
170170
}
171171

172+
/**
173+
* @return array
174+
*/
175+
public function postedDataProvider()
176+
{
177+
return [
178+
[
179+
['region_id' => 1, 'region' => 'region']
180+
],
181+
[
182+
['region' => 'region without id']
183+
]
184+
];
185+
}
186+
172187
/**
173188
* @throws \Magento\Framework\Exception\LocalizedException
174189
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)

app/code/Magento/Customer/view/frontend/templates/widget/telephone.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<?php
2020
$_validationClass = $block->escapeHtmlAttr(
2121
$this->helper('Magento\Customer\Helper\Address')
22-
->getAttributeValidationClass('fax')
22+
->getAttributeValidationClass('telephone')
2323
);
2424
?>
2525
<input type="text"

dev/tests/integration/testsuite/Magento/Cron/Model/ScheduleTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@ public function testTryLockJobAlreadyLockedFails()
5454
$this->assertFalse($schedule->tryLockJob());
5555
}
5656

57+
/**
58+
* If the job is already locked but lock time less than 1 day ago, attempting to lock it again should fail
59+
*/
60+
public function testTryLockJobAlreadyLockedSucceeds()
61+
{
62+
$offsetInThePast = 2*24*60*60;
63+
64+
$oldSchedule = $this->scheduleFactory->create()
65+
->setCronExpr("* * * * *")
66+
->setJobCode("test_job")
67+
->setStatus(Schedule::STATUS_RUNNING)
68+
->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $this->dateTime->gmtTimestamp() - $offsetInThePast))
69+
->setScheduledAt(strftime('%Y-%m-%d %H:%M', $this->dateTime->gmtTimestamp() - $offsetInThePast + 60))
70+
->setExecutedAt(strftime('%Y-%m-%d %H:%M', $this->dateTime->gmtTimestamp() - $offsetInThePast + 61));
71+
$oldSchedule->save();
72+
73+
$schedule = $this->createSchedule("test_job", Schedule::STATUS_PENDING);
74+
75+
$this->assertTrue($schedule->tryLockJob());
76+
}
77+
5778
/**
5879
* If there's a job already locked, should not be able to lock another job
5980
*/

lib/internal/Magento/Framework/Session/SessionManager.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -504,18 +504,8 @@ public function regenerateId()
504504
return $this;
505505
}
506506

507-
//@see http://php.net/manual/en/function.session-regenerate-id.php#53480 workaround
508507
if ($this->isSessionExists()) {
509-
$oldSessionId = session_id();
510-
session_regenerate_id();
511-
$newSessionId = session_id();
512-
session_id($oldSessionId);
513-
session_destroy();
514-
515-
$oldSession = $_SESSION;
516-
session_id($newSessionId);
517-
session_start();
518-
$_SESSION = $oldSession;
508+
session_regenerate_id(true);
519509
} else {
520510
session_start();
521511
}

0 commit comments

Comments
 (0)