Skip to content

Commit f7072a5

Browse files
committed
Adding pending state, when clicking the Refresh button in the adminhtml, so you know it actually did something.
1 parent 5786cdb commit f7072a5

File tree

5 files changed

+79
-12
lines changed

5 files changed

+79
-12
lines changed

Controller/Adminhtml/Catalog/Category/UrlPath/Refresh.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
namespace Baldwin\UrlDataIntegrityChecker\Controller\Adminhtml\Catalog\Category\UrlPath;
66

7+
use Baldwin\UrlDataIntegrityChecker\Checker\Catalog\Category\UrlPath as UrlPathChecker;
78
use Baldwin\UrlDataIntegrityChecker\Cron\CheckCategoryUrlPath as CheckCategoryUrlPathCron;
89
use Baldwin\UrlDataIntegrityChecker\Cron\ScheduleJob;
10+
use Baldwin\UrlDataIntegrityChecker\Exception\AlreadyRefreshingException;
11+
use Baldwin\UrlDataIntegrityChecker\Storage\Meta as MetaStorage;
912
use Magento\Backend\App\Action as BackendAction;
1013
use Magento\Backend\App\Action\Context as BackendContext;
1114

@@ -14,14 +17,17 @@ class Refresh extends BackendAction
1417
const ADMIN_RESOURCE = 'Baldwin_UrlDataIntegrityChecker::catalog_data_integrity';
1518

1619
private $scheduleJob;
20+
private $metaStorage;
1721

1822
public function __construct(
1923
BackendContext $context,
20-
ScheduleJob $scheduleJob
24+
ScheduleJob $scheduleJob,
25+
MetaStorage $metaStorage
2126
) {
2227
parent::__construct($context);
2328

2429
$this->scheduleJob = $scheduleJob;
30+
$this->metaStorage = $metaStorage;
2531
}
2632

2733
public function execute()
@@ -34,6 +40,13 @@ public function execute()
3440
'The refresh job was scheduled, please check back in a few moments to see the updated results'
3541
)
3642
);
43+
44+
try {
45+
$storageIdentifier = UrlPathChecker::STORAGE_IDENTIFIER;
46+
$this->metaStorage->setPending($storageIdentifier, MetaStorage::INITIATOR_CRON);
47+
} catch (AlreadyRefreshingException $ex) {
48+
$this->getMessageManager()->addError($ex->getMessage());
49+
}
3750
} else {
3851
$this->getMessageManager()->addError(
3952
(string) __('Couldn\'t schedule refreshing due to some unknown error')

Controller/Adminhtml/Catalog/Product/UrlKey/Refresh.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
namespace Baldwin\UrlDataIntegrityChecker\Controller\Adminhtml\Catalog\Product\UrlKey;
66

7+
use Baldwin\UrlDataIntegrityChecker\Checker\Catalog\Product\UrlKey as UrlKeyChecker;
78
use Baldwin\UrlDataIntegrityChecker\Cron\CheckProductUrlKey as CheckProductUrlKeyCron;
89
use Baldwin\UrlDataIntegrityChecker\Cron\ScheduleJob;
10+
use Baldwin\UrlDataIntegrityChecker\Exception\AlreadyRefreshingException;
11+
use Baldwin\UrlDataIntegrityChecker\Storage\Meta as MetaStorage;
912
use Magento\Backend\App\Action as BackendAction;
1013
use Magento\Backend\App\Action\Context as BackendContext;
1114

@@ -14,14 +17,17 @@ class Refresh extends BackendAction
1417
const ADMIN_RESOURCE = 'Baldwin_UrlDataIntegrityChecker::catalog_data_integrity';
1518

1619
private $scheduleJob;
20+
private $metaStorage;
1721

1822
public function __construct(
1923
BackendContext $context,
20-
ScheduleJob $scheduleJob
24+
ScheduleJob $scheduleJob,
25+
MetaStorage $metaStorage
2126
) {
2227
parent::__construct($context);
2328

2429
$this->scheduleJob = $scheduleJob;
30+
$this->metaStorage = $metaStorage;
2531
}
2632

2733
public function execute()
@@ -34,6 +40,13 @@ public function execute()
3440
'The refresh job was scheduled, please check back in a few moments to see the updated results'
3541
)
3642
);
43+
44+
try {
45+
$storageIdentifier = UrlKeyChecker::STORAGE_IDENTIFIER;
46+
$this->metaStorage->setPending($storageIdentifier, MetaStorage::INITIATOR_CRON);
47+
} catch (AlreadyRefreshingException $ex) {
48+
$this->getMessageManager()->addError($ex->getMessage());
49+
}
3750
} else {
3851
$this->getMessageManager()->addError(
3952
(string) __('Couldn\'t schedule refreshing due to some unknown error')

Controller/Adminhtml/Catalog/Product/UrlPath/Refresh.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
namespace Baldwin\UrlDataIntegrityChecker\Controller\Adminhtml\Catalog\Product\UrlPath;
66

7+
use Baldwin\UrlDataIntegrityChecker\Checker\Catalog\Product\UrlPath as UrlPathChecker;
78
use Baldwin\UrlDataIntegrityChecker\Cron\CheckProductUrlPath as CheckProductUrlPathCron;
89
use Baldwin\UrlDataIntegrityChecker\Cron\ScheduleJob;
10+
use Baldwin\UrlDataIntegrityChecker\Exception\AlreadyRefreshingException;
11+
use Baldwin\UrlDataIntegrityChecker\Storage\Meta as MetaStorage;
912
use Magento\Backend\App\Action as BackendAction;
1013
use Magento\Backend\App\Action\Context as BackendContext;
1114

@@ -14,14 +17,17 @@ class Refresh extends BackendAction
1417
const ADMIN_RESOURCE = 'Baldwin_UrlDataIntegrityChecker::catalog_data_integrity';
1518

1619
private $scheduleJob;
20+
private $metaStorage;
1721

1822
public function __construct(
1923
BackendContext $context,
20-
ScheduleJob $scheduleJob
24+
ScheduleJob $scheduleJob,
25+
MetaStorage $metaStorage
2126
) {
2227
parent::__construct($context);
2328

2429
$this->scheduleJob = $scheduleJob;
30+
$this->metaStorage = $metaStorage;
2531
}
2632

2733
public function execute()
@@ -34,6 +40,13 @@ public function execute()
3440
'The refresh job was scheduled, please check back in a few moments to see the updated results'
3541
)
3642
);
43+
44+
try {
45+
$storageIdentifier = UrlPathChecker::STORAGE_IDENTIFIER;
46+
$this->metaStorage->setPending($storageIdentifier, MetaStorage::INITIATOR_CRON);
47+
} catch (AlreadyRefreshingException $ex) {
48+
$this->getMessageManager()->addError($ex->getMessage());
49+
}
3750
} else {
3851
$this->getMessageManager()->addError(
3952
(string) __('Couldn\'t schedule refreshing due to some unknown error')

Storage/Meta.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
namespace Baldwin\UrlDataIntegrityChecker\Storage;
66

7+
use Baldwin\UrlDataIntegrityChecker\Exception\AlreadyRefreshingException;
78
use Magento\Framework\Stdlib\DateTime\DateTime;
89

910
class Meta
1011
{
1112
const STORAGE_SUFFIX = '-meta';
1213

14+
const STATUS_PENDING = 'pending';
1315
const STATUS_REFRESHING = 'refreshing';
1416
const STATUS_FINISHED = 'finished';
1517

@@ -27,6 +29,26 @@ public function __construct(
2729
$this->dateTime = $dateTime;
2830
}
2931

32+
public function setPending(string $storageIdentifier, string $initiator)
33+
{
34+
if ($this->isRefreshing($storageIdentifier)) {
35+
throw new AlreadyRefreshingException(__(
36+
'We are already refreshing this checker. ' .
37+
'If you believe this is an error, clear it by providing the \'--force\' flag using the command line ' .
38+
'in the appropriate integrity check command'
39+
));
40+
}
41+
42+
$storageIdentifier .= self::STORAGE_SUFFIX;
43+
44+
$this->storage->update($storageIdentifier, [
45+
'initiator' => $initiator,
46+
'started' => 0,
47+
'finished' => 0,
48+
'status' => self::STATUS_PENDING,
49+
]);
50+
}
51+
3052
public function setStartRefreshing(string $storageIdentifier, string $initiator)
3153
{
3254
$storageIdentifier .= self::STORAGE_SUFFIX;

view/adminhtml/templates/metadata.phtml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
use Baldwin\UrlDataIntegrityChecker\Storage\Meta as MetaStorage;
3+
24
$metadata = $block->getMetadata();
35
?>
46
<style>
@@ -16,19 +18,22 @@
1618
}
1719
</style>
1820
<div class="data-integrity-meta-data" style="float: left">
21+
<?php if (isset($metadata['status'])): ?>
1922
<h2><?= $block->escapeHtml(__('Info')) ?></h2>
2023
<dl>
2124
<dt><?= $block->escapeHtml(__('Status')) ?>:</dt>
2225
<dd><?= $block->escapeHtml($metadata['status'] ?? '') ?></dd>
23-
<dt><?= $block->escapeHtml(__('Started refreshing')) ?>:</dt>
24-
<dd><?= $block->escapeHtml($metadata['started'] ?? '') ?></dd>
25-
<?php if (isset($metadata['finished'])): ?>
26-
<dt><?= $block->escapeHtml(__('Finished refreshing')) ?>:</dt>
27-
<dd><?= $block->escapeHtml($metadata['finished'] ?? '') ?></dd>
28-
<?php endif; ?>
29-
<?php if (isset($metadata['execution_time'])): ?>
30-
<dt><?= $block->escapeHtml(__('Execution time')) ?>:</dt>
31-
<dd><?= $block->escapeHtml($metadata['execution_time'] ?? '') ?></dd>
26+
<?php if ($metadata['status'] !== MetaStorage::STATUS_PENDING): ?>
27+
<dt><?= $block->escapeHtml(__('Started refreshing')) ?>:</dt>
28+
<dd><?= $block->escapeHtml($metadata['started'] ?? '') ?></dd>
29+
<?php if (isset($metadata['finished'])): ?>
30+
<dt><?= $block->escapeHtml(__('Finished refreshing')) ?>:</dt>
31+
<dd><?= $block->escapeHtml($metadata['finished'] ?? '') ?></dd>
32+
<?php endif; ?>
33+
<?php if (isset($metadata['execution_time'])): ?>
34+
<dt><?= $block->escapeHtml(__('Execution time')) ?>:</dt>
35+
<dd><?= $block->escapeHtml($metadata['execution_time'] ?? '') ?></dd>
36+
<?php endif; ?>
3237
<?php endif; ?>
3338
<dt><?= $block->escapeHtml(__('Initiator')) ?>:</dt>
3439
<dd><?= $block->escapeHtml($metadata['initiator'] ?? '') ?></dd>
@@ -37,4 +42,5 @@
3742
<dd><?= $block->escapeHtml($metadata['error'] ?? '') ?></dd>
3843
<?php endif; ?>
3944
</dl>
45+
<?php endif; ?>
4046
</div>

0 commit comments

Comments
 (0)