Skip to content

Commit 15af16f

Browse files
author
Nikita Fomin
committed
Merge remote-tracking branch 'origin/2.2-develop' into MAGETWO-97023
2 parents e24948e + 76f484d commit 15af16f

File tree

29 files changed

+185
-99
lines changed

29 files changed

+185
-99
lines changed

app/code/Magento/Backend/Block/Dashboard/Bar.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Backend\Block\Dashboard;
77

8+
use Magento\Store\Model\Store;
9+
810
/**
911
* Adminhtml dashboard bar block
1012
*
@@ -73,6 +75,7 @@ public function setCurrency($currency)
7375
* Retrieve currency model if not set then return currency model for current store
7476
*
7577
* @return \Magento\Directory\Model\Currency
78+
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
7679
*/
7780
public function getCurrency()
7881
{
@@ -90,7 +93,8 @@ public function getCurrency()
9093
$this->getRequest()->getParam('group')
9194
)->getWebsite()->getBaseCurrency();
9295
} else {
93-
$this->_currentCurrencyCode = $this->_storeManager->getStore()->getBaseCurrency();
96+
$this->_currentCurrencyCode = $this->_storeManager->getStore(Store::DEFAULT_STORE_ID)
97+
->getBaseCurrency();
9498
}
9599
}
96100

app/code/Magento/Checkout/view/frontend/templates/cart/minicart.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
data-bind="scope: 'minicart_content'">
1313
<span class="text"><?= $block->escapeHtml(__('My Cart')) ?></span>
1414
<span class="counter qty empty"
15-
data-bind="css: { empty: !!getCartParam('summary_count') == false }, blockLoader: isLoading">
15+
data-bind="css: { empty: !!getCartParam('summary_count') == false && !isLoading() }, blockLoader: isLoading">
1616
<span class="counter-number"><!-- ko text: getCartParam('summary_count') --><!-- /ko --></span>
1717
<span class="counter-label">
1818
<!-- ko if: getCartParam('summary_count') -->

app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
/**
87
* Handling cron jobs
98
*/
109
namespace Magento\Cron\Observer;
1110

11+
use Magento\Cron\Model\Schedule;
1212
use Magento\Framework\App\State;
1313
use Magento\Framework\Console\Cli;
1414
use Magento\Framework\Event\ObserverInterface;
15-
use \Magento\Cron\Model\Schedule;
1615
use Magento\Framework\Profiler\Driver\Standard\Stat;
1716
use Magento\Framework\Profiler\Driver\Standard\StatFactory;
1817

@@ -201,7 +200,6 @@ public function __construct(
201200
*/
202201
public function execute(\Magento\Framework\Event\Observer $observer)
203202
{
204-
205203
$currentTime = $this->dateTime->gmtTimestamp();
206204
$jobGroupsRoot = $this->_config->getJobs();
207205
// sort jobs groups to start from used in separated process
@@ -255,7 +253,6 @@ function ($groupId) use ($currentTime, $jobsRoot) {
255253
*/
256254
private function lockGroup($groupId, callable $callback)
257255
{
258-
259256
if (!$this->lockManager->lock(self::LOCK_PREFIX . $groupId, self::LOCK_TIMEOUT)) {
260257
$this->logger->warning(
261258
sprintf(
@@ -290,17 +287,20 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
290287
$scheduleLifetime = $scheduleLifetime * self::SECONDS_IN_MINUTE;
291288
if ($scheduledTime < $currentTime - $scheduleLifetime) {
292289
$schedule->setStatus(Schedule::STATUS_MISSED);
290+
// phpcs:ignore Magento2.Exceptions.DirectThrow
293291
throw new \Exception(sprintf('Cron Job %s is missed at %s', $jobCode, $schedule->getScheduledAt()));
294292
}
295293

296294
if (!isset($jobConfig['instance'], $jobConfig['method'])) {
297295
$schedule->setStatus(Schedule::STATUS_ERROR);
298-
throw new \Exception('No callbacks found');
296+
// phpcs:ignore Magento2.Exceptions.DirectThrow
297+
throw new \Exception(sprintf('No callbacks found for cron job %s', $jobCode));
299298
}
300299
$model = $this->_objectManager->create($jobConfig['instance']);
301300
$callback = [$model, $jobConfig['method']];
302301
if (!is_callable($callback)) {
303302
$schedule->setStatus(Schedule::STATUS_ERROR);
303+
// phpcs:ignore Magento2.Exceptions.DirectThrow
304304
throw new \Exception(
305305
sprintf('Invalid callback: %s::%s can\'t be called', $jobConfig['instance'], $jobConfig['method'])
306306
);
@@ -311,15 +311,18 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
311311
$this->startProfiling();
312312
try {
313313
$this->logger->info(sprintf('Cron Job %s is run', $jobCode));
314+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
314315
call_user_func_array($callback, [$schedule]);
315316
} catch (\Throwable $e) {
316317
$schedule->setStatus(Schedule::STATUS_ERROR);
317-
$this->logger->error(sprintf(
318-
'Cron Job %s has an error: %s. Statistics: %s',
319-
$jobCode,
320-
$e->getMessage(),
321-
$this->getProfilingStat()
322-
));
318+
$this->logger->error(
319+
sprintf(
320+
'Cron Job %s has an error: %s. Statistics: %s',
321+
$jobCode,
322+
$e->getMessage(),
323+
$this->getProfilingStat()
324+
)
325+
);
323326
if (!$e instanceof \Exception) {
324327
$e = new \RuntimeException(
325328
'Error when running a cron job',
@@ -332,16 +335,22 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
332335
$this->stopProfiling();
333336
}
334337

335-
$schedule->setStatus(Schedule::STATUS_SUCCESS)->setFinishedAt(strftime(
336-
'%Y-%m-%d %H:%M:%S',
337-
$this->dateTime->gmtTimestamp()
338-
));
338+
$schedule->setStatus(
339+
Schedule::STATUS_SUCCESS
340+
)->setFinishedAt(
341+
strftime(
342+
'%Y-%m-%d %H:%M:%S',
343+
$this->dateTime->gmtTimestamp()
344+
)
345+
);
339346

340-
$this->logger->info(sprintf(
341-
'Cron Job %s is successfully finished. Statistics: %s',
342-
$jobCode,
343-
$this->getProfilingStat()
344-
));
347+
$this->logger->info(
348+
sprintf(
349+
'Cron Job %s is successfully finished. Statistics: %s',
350+
$jobCode,
351+
$this->getProfilingStat()
352+
)
353+
);
345354
}
346355

347356
/**
@@ -391,6 +400,28 @@ private function getPendingSchedules($groupId)
391400
return $pendingJobs;
392401
}
393402

403+
/**
404+
* Return job collection from database with status 'pending', 'running' or 'success'
405+
*
406+
* @param string $groupId
407+
* @return \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
408+
*/
409+
private function getNonExitedSchedules($groupId)
410+
{
411+
$jobs = $this->_config->getJobs();
412+
$pendingJobs = $this->_scheduleFactory->create()->getCollection();
413+
$pendingJobs->addFieldToFilter(
414+
'status',
415+
[
416+
'in' => [
417+
Schedule::STATUS_PENDING, Schedule::STATUS_RUNNING, Schedule::STATUS_SUCCESS
418+
]
419+
]
420+
);
421+
$pendingJobs->addFieldToFilter('job_code', ['in' => array_keys($jobs[$groupId])]);
422+
return $pendingJobs;
423+
}
424+
394425
/**
395426
* Generate cron schedule
396427
*
@@ -422,7 +453,7 @@ private function generateSchedules($groupId)
422453
null
423454
);
424455

425-
$schedules = $this->getPendingSchedules($groupId);
456+
$schedules = $this->getNonExitedSchedules($groupId);
426457
$exists = [];
427458
/** @var Schedule $schedule */
428459
foreach ($schedules as $schedule) {
@@ -653,11 +684,14 @@ private function cleanupScheduleMismatches()
653684
/** @var \Magento\Cron\Model\ResourceModel\Schedule $scheduleResource */
654685
$scheduleResource = $this->_scheduleFactory->create()->getResource();
655686
foreach ($this->invalid as $jobCode => $scheduledAtList) {
656-
$scheduleResource->getConnection()->delete($scheduleResource->getMainTable(), [
657-
'status = ?' => Schedule::STATUS_PENDING,
658-
'job_code = ?' => $jobCode,
659-
'scheduled_at in (?)' => $scheduledAtList,
660-
]);
687+
$scheduleResource->getConnection()->delete(
688+
$scheduleResource->getMainTable(),
689+
[
690+
'status = ?' => Schedule::STATUS_PENDING,
691+
'job_code = ?' => $jobCode,
692+
'scheduled_at in (?)' => $scheduledAtList,
693+
]
694+
);
661695
}
662696
return $this;
663697
}

app/code/Magento/Cron/Test/Unit/Observer/ProcessCronQueueObserverTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ public function testDispatchExceptionTooLate()
355355
*/
356356
public function testDispatchExceptionNoCallback()
357357
{
358-
$exceptionMessage = 'No callbacks found';
358+
$jobCode = 'test_job1';
359+
$exceptionMessage = sprintf('No callbacks found for cron job %s', $jobCode);
359360
$exception = new \Exception(__($exceptionMessage));
360361

361362
$dateScheduledAt = date('Y-m-d H:i:s', $this->time - 86400);
@@ -364,7 +365,7 @@ public function testDispatchExceptionNoCallback()
364365
)->setMethods(
365366
['getJobCode', 'tryLockJob', 'getScheduledAt', 'save', 'setStatus', 'setMessages', '__wakeup', 'getStatus']
366367
)->disableOriginalConstructor()->getMock();
367-
$schedule->expects($this->any())->method('getJobCode')->will($this->returnValue('test_job1'));
368+
$schedule->expects($this->any())->method('getJobCode')->will($this->returnValue($jobCode));
368369
$schedule->expects($this->once())->method('getScheduledAt')->will($this->returnValue($dateScheduledAt));
369370
$schedule->expects($this->once())->method('tryLockJob')->will($this->returnValue(true));
370371
$schedule->expects(
@@ -384,7 +385,7 @@ public function testDispatchExceptionNoCallback()
384385

385386
$this->loggerMock->expects($this->once())->method('critical')->with($exception);
386387

387-
$jobConfig = ['test_group' => ['test_job1' => ['instance' => 'Some_Class']]];
388+
$jobConfig = ['test_group' => [$jobCode => ['instance' => 'Some_Class']]];
388389

389390
$this->_config->expects($this->exactly(2))->method('getJobs')->will($this->returnValue($jobConfig));
390391

app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,12 @@
157157
<column name="billing_telephone" sortOrder="60">
158158
<settings>
159159
<filter>text</filter>
160-
<editor>
161-
<editorType>text</editorType>
162-
</editor>
163160
<label translate="true">Phone</label>
164161
</settings>
165162
</column>
166163
<column name="billing_postcode" sortOrder="70">
167164
<settings>
168165
<filter>text</filter>
169-
<editor>
170-
<editorType>text</editorType>
171-
</editor>
172166
<label translate="true">ZIP</label>
173167
</settings>
174168
</column>
@@ -269,59 +263,41 @@
269263
<column name="billing_city" sortOrder="210">
270264
<settings>
271265
<filter>text</filter>
272-
<editor>
273-
<editorType>text</editorType>
274-
</editor>
275266
<label translate="true">City</label>
276267
<visible>false</visible>
277268
</settings>
278269
</column>
279270
<column name="billing_fax" sortOrder="220">
280271
<settings>
281272
<filter>text</filter>
282-
<editor>
283-
<editorType>text</editorType>
284-
</editor>
285273
<label translate="true">Fax</label>
286274
<visible>false</visible>
287275
</settings>
288276
</column>
289277
<column name="billing_vat_id" sortOrder="230">
290278
<settings>
291279
<filter>text</filter>
292-
<editor>
293-
<editorType>text</editorType>
294-
</editor>
295280
<label translate="true">VAT Number</label>
296281
<visible>false</visible>
297282
</settings>
298283
</column>
299284
<column name="billing_company" sortOrder="240">
300285
<settings>
301286
<filter>text</filter>
302-
<editor>
303-
<editorType>text</editorType>
304-
</editor>
305287
<label translate="true">Company</label>
306288
<visible>false</visible>
307289
</settings>
308290
</column>
309291
<column name="billing_firstname" sortOrder="250">
310292
<settings>
311293
<filter>text</filter>
312-
<editor>
313-
<editorType>text</editorType>
314-
</editor>
315294
<label translate="true">Billing Firstname</label>
316295
<visible>false</visible>
317296
</settings>
318297
</column>
319298
<column name="billing_lastname" sortOrder="260">
320299
<settings>
321300
<filter>text</filter>
322-
<editor>
323-
<editorType>text</editorType>
324-
</editor>
325301
<label translate="true">Billing Lastname</label>
326302
<visible>false</visible>
327303
</settings>

app/code/Magento/Email/Model/AbstractTemplate.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Store\Model\Information as StoreInformation;
1515
use Magento\Store\Model\ScopeInterface;
1616
use Magento\Store\Model\Store;
17+
use Magento\MediaStorage\Helper\File\Storage\Database;
1718

1819
/**
1920
* Template model class
@@ -163,6 +164,11 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
163164
*/
164165
private $urlModel;
165166

167+
/**
168+
* @var Database
169+
*/
170+
private $fileStorageDatabase;
171+
166172
/**
167173
* @param \Magento\Framework\Model\Context $context
168174
* @param \Magento\Framework\View\DesignInterface $design
@@ -177,6 +183,7 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
177183
* @param \Magento\Framework\Filter\FilterManager $filterManager
178184
* @param \Magento\Framework\UrlInterface $urlModel
179185
* @param array $data
186+
* @param Database $fileStorageDatabase
180187
*
181188
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
182189
*/
@@ -193,7 +200,8 @@ public function __construct(
193200
\Magento\Email\Model\TemplateFactory $templateFactory,
194201
\Magento\Framework\Filter\FilterManager $filterManager,
195202
\Magento\Framework\UrlInterface $urlModel,
196-
array $data = []
203+
array $data = [],
204+
Database $fileStorageDatabase = null
197205
) {
198206
$this->design = $design;
199207
$this->area = isset($data['area']) ? $data['area'] : null;
@@ -207,6 +215,8 @@ public function __construct(
207215
$this->templateFactory = $templateFactory;
208216
$this->filterManager = $filterManager;
209217
$this->urlModel = $urlModel;
218+
$this->fileStorageDatabase = $fileStorageDatabase ?:
219+
\Magento\Framework\App\ObjectManager::getInstance()->get(Database::class);
210220
parent::__construct($context, $registry, null, null, $data);
211221
}
212222

@@ -394,6 +404,11 @@ protected function getLogoUrl($store)
394404
if ($fileName) {
395405
$uploadDir = \Magento\Email\Model\Design\Backend\Logo::UPLOAD_DIR;
396406
$mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
407+
if ($this->fileStorageDatabase->checkDbUsage() &&
408+
!$mediaDirectory->isFile($uploadDir . '/' . $fileName)
409+
) {
410+
$this->fileStorageDatabase->saveFileToFilesystem($uploadDir . '/' . $fileName);
411+
}
397412
if ($mediaDirectory->isFile($uploadDir . '/' . $fileName)) {
398413
return $this->storeManager->getStore()->getBaseUrl(
399414
\Magento\Framework\UrlInterface::URL_TYPE_MEDIA

0 commit comments

Comments
 (0)