Skip to content

Commit 4b5e605

Browse files
authored
Merge pull request #25 from ivanhrytsaim/master
10509-Invalid-Key-Notification
2 parents 9c2d68a + 35b02b0 commit 4b5e605

File tree

6 files changed

+198
-3
lines changed

6 files changed

+198
-3
lines changed

Block/Adminhtml/Linv.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magefan\Community\Block\Adminhtml;
10+
11+
use Magento\Backend\Block\Template;
12+
use Magento\Framework\App\ResourceConnection;
13+
use Magefan\Community\Model\SectionFactory;
14+
15+
class Linv extends Template
16+
{
17+
/**
18+
* @var ResourceConnection
19+
*/
20+
private $resource;
21+
22+
/**
23+
* @var SectionFactory
24+
*/
25+
private $sectionFactory;
26+
27+
/**
28+
* @param SectionFactory $sectionFactory
29+
* @param Template\Context $context
30+
* @param ResourceConnection $resource
31+
* @param array $data
32+
*/
33+
public function __construct(
34+
SectionFactory $sectionFactory,
35+
Template\Context $context,
36+
ResourceConnection $resource,
37+
array $data = []
38+
) {
39+
parent::__construct($context, $data);
40+
$this->sectionFactory = $sectionFactory;
41+
$this->resource = $resource;
42+
}
43+
44+
/**
45+
* @return array
46+
*/
47+
public function getItems()
48+
{
49+
$connection = $this->resource->getConnection();
50+
$table = $this->resource->getTableName('core_config_data');
51+
$path = '/g'.'en'.'er'.'al'.'/l'.'in'.'v';
52+
$select = $connection->select()
53+
->from([$table])
54+
->where( 'path LIKE ?', '%' . $path )
55+
->where('value = ?',1);
56+
$items = $connection->fetchAll($select);
57+
$result = [];
58+
59+
foreach ($items as $config) {
60+
$configPath = explode('/', $config['path']);
61+
$moduleName = $configPath[0];
62+
$section = $this->sectionFactory->create([
63+
'name' => $moduleName
64+
]);
65+
$module = $section->getModule(true);
66+
if ($module) {
67+
$result[] = $module;
68+
}
69+
70+
}
71+
return $result;
72+
}
73+
}

Cron/Sections.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magefan\Community\Model\SectionFactory;
1010
use Magefan\Community\Model\Section\Info;
11+
use Magefan\Community\Model\SetLinvFlag;
1112
use Magento\Framework\App\ResourceConnection;
1213

1314
/**
@@ -31,6 +32,11 @@ class Sections
3132
*/
3233
protected $resource;
3334

35+
/**
36+
* @var SetLinvFlag
37+
*/
38+
private $setLinvFlag;
39+
3440
/**
3541
* Sections constructor.
3642
* @param ResourceConnection $resource
@@ -40,11 +46,13 @@ class Sections
4046
public function __construct(
4147
ResourceConnection $resource,
4248
SectionFactory $sectionFactory,
43-
Info $info
49+
Info $info,
50+
SetLinvFlag $setLinvFlag
4451
) {
4552
$this->resource = $resource;
4653
$this->sectionFactory = $sectionFactory;
4754
$this->info = $info;
55+
$this->setLinvFlag = $setLinvFlag;
4856
}
4957

5058
/**
@@ -87,6 +95,7 @@ public function execute()
8795
if ($data && is_array($data)) {
8896
foreach ($data as $module => $item) {
8997
$section = $sections[$module];
98+
$moduleName = $section->getName();
9099
if (!$section->validate($data)) {
91100
$connection->update(
92101
$table,
@@ -95,6 +104,9 @@ public function execute()
95104
],
96105
['path = ? ' => $section->getName() . '/' . $path]
97106
);
107+
$this->setLinvFlag->execute($moduleName, 1);
108+
} else {
109+
$this->setLinvFlag->execute($moduleName, 0);
98110
}
99111
}
100112
}

Model/SetLinvFlag.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magefan\Community\Model;
10+
11+
use Magento\Framework\App\Config\Storage\WriterInterface;
12+
use Magento\Framework\App\Cache\TypeListInterface;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\App\Cache\Type\Config;
15+
16+
class SetLinvFlag
17+
{
18+
/**
19+
* @var WriterInterface
20+
*/
21+
private $configWriter;
22+
23+
/**
24+
* @var TypeListInterface
25+
*/
26+
private $cacheTypeList;
27+
28+
/**
29+
* @param WriterInterface $configWriter
30+
* @param TypeListInterface $cacheTypeList
31+
*/
32+
public function __construct(
33+
WriterInterface $configWriter,
34+
TypeListInterface $cacheTypeList
35+
) {
36+
$this->configWriter = $configWriter;
37+
$this->cacheTypeList = $cacheTypeList;
38+
}
39+
40+
/**
41+
* @param $module
42+
* @param $value
43+
* @return void
44+
*/
45+
public function execute($module, $value)
46+
{
47+
$this->configWriter->save($module . '/g'.'en'.'er'.'al'.'/l'.'in'.'v', $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, 0);
48+
$this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER);
49+
}
50+
}

Observer/ConfigObserver.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magefan\Community\Model\SectionFactory;
1111
use Magefan\Community\Model\Section\Info;
1212
use Magento\Framework\Message\ManagerInterface;
13+
use Magefan\Community\Model\SetLinvFlag;
1314

1415
/**
1516
* Community observer
@@ -31,6 +32,11 @@ class ConfigObserver implements ObserverInterface
3132
*/
3233
private $messageManager;
3334

35+
/**
36+
* @var SetLinvFlag
37+
*/
38+
private $setLinvFlag;
39+
3440
/**
3541
* ConfigObserver constructor.
3642
* @param SectionFactory $sectionFactory
@@ -40,11 +46,13 @@ class ConfigObserver implements ObserverInterface
4046
final public function __construct(
4147
SectionFactory $sectionFactory,
4248
Info $info,
43-
ManagerInterface $messageManager
49+
ManagerInterface $messageManager,
50+
SetLinvFlag $setLinvFlag
4451
) {
4552
$this->sectionFactory = $sectionFactory;
4653
$this->info = $info;
4754
$this->messageManager = $messageManager;
55+
$this->setLinvFlag = $setLinvFlag;
4856
}
4957

5058
/**
@@ -70,11 +78,12 @@ final public function execute(\Magento\Framework\Event\Observer $observer)
7078
if (!$section->getModule()) {
7179
return;
7280
}
73-
81+
$module = $section->getName();
7482
$data = $this->info->load([$section]);
7583

7684
if (!$section->validate($data)) {
7785
$groups['general']['fields']['enabled']['value'] = 0;
86+
$this->setLinvFlag->execute($module, 1);
7887
$request->setPostValue('groups', $groups);
7988

8089
$this->messageManager->addError(
@@ -88,6 +97,8 @@ final public function execute(\Magento\Framework\Event\Observer $observer)
8897
]
8998
))
9099
);
100+
} else {
101+
$this->setLinvFlag->execute($module, 0);
91102
}
92103
}
93104
}

view/adminhtml/layout/default.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magefan ([email protected]). All rights reserved.
5+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceContainer name="page.wrapper">
11+
<block class="Magefan\Community\Block\Adminhtml\Linv" name="magefan_community_linv" template="Magefan_Community::linv.phtml" after="header" />
12+
</referenceContainer>
13+
</body>
14+
</page>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
5+
*/
6+
?>
7+
<?php
8+
/**
9+
* Help template
10+
*
11+
* @var $block \Magefan\Community\Block\Adminhtml\Linv
12+
*/
13+
?>
14+
<?php if ($items = $block->getItems()) { ?>
15+
16+
<div class="messages">
17+
<div class="message message-notice notice">
18+
<div data-ui-id="messages-message-notice" class="linv">
19+
<?= 'Important! So' . 'me ' . 'Mag'.'efan'.' Ex'.'tensions'.' a'.'re'.' dis'.'abl'.'ed d'.'ue '.'to i'.'nva'.'lid'.' Product K'.'ey: ' ?>
20+
<div style="margin-left: 30px">
21+
<br/>
22+
<ul>
23+
<?php foreach ($items as $key => $name) { ?>
24+
<li>
25+
<?= $block->escapeHtml($result = preg_replace('/([A-Z])/', ' $1', $name)); ?>
26+
</li>
27+
<?php } ?>
28+
</ul>
29+
</div>
30+
<?= 'Ple' . 'ase che' . 'ck exten' . 'sions config' . 'uration' ?>.
31+
</div>
32+
</div>
33+
</div>
34+
35+
<?php } ?>

0 commit comments

Comments
 (0)