-
Notifications
You must be signed in to change notification settings - Fork 13
/
Sections.php
115 lines (102 loc) · 3.02 KB
/
Sections.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* Copyright © Magefan (support@magefan.com). All rights reserved.
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement).
*/
namespace Magefan\Community\Cron;
use Magefan\Community\Model\SectionFactory;
use Magefan\Community\Model\Section\Info;
use Magefan\Community\Model\SetLinvFlag;
use Magento\Framework\App\ResourceConnection;
/**
* Class Sections
* @package Magefan\Community
*/
class Sections
{
/**
* @var SectionFactory
*/
protected $sectionFactory;
/**
* @var Info
*/
protected $info;
/**
* @var ResourceConnection
*/
protected $resource;
/**
* @var SetLinvFlag
*/
private $setLinvFlag;
/**
* Sections constructor.
* @param ResourceConnection $resource
* @param SectionFactory $sectionFactory
* @param Info $info
*/
public function __construct(
ResourceConnection $resource,
SectionFactory $sectionFactory,
Info $info,
SetLinvFlag $setLinvFlag
) {
$this->resource = $resource;
$this->sectionFactory = $sectionFactory;
$this->info = $info;
$this->setLinvFlag = $setLinvFlag;
}
/**
* Execute cron job
*/
public function execute()
{
$connection = $this->resource->getConnection();
$table = $this->resource->getTableName('core_config_data');
$path = 'gen' . 'er' . 'al'. '/' . 'ena' . 'bled';
$select = $connection->select()->from(
[$table]
)->where(
'path LIKE ?',
'%' . $path
);
$sections = [];
foreach ($connection->fetchAll($select) as $config) {
$matches = false;
preg_match("/(.*)\/" . str_replace('/', '\/', $path) . "/", $config['path'], $matches);
if (empty($matches[1])) {
continue;
}
$section = $this->sectionFactory->create([
'name' => $matches[1]
]);
if ($section->getModule()) {
$sections[$section->getModule()] = $section;
} else {
unset($section);
}
}
if (count($sections)) {
$data = $this->info->load($sections);
if ($data && is_array($data)) {
foreach ($data as $module => $item) {
$section = $sections[$module];
$moduleName = $section->getName();
if (!$section->validate($data)) {
$connection->update(
$table,
[
'value' => 0
],
['path = ? ' => $section->getName() . '/' . $path]
);
$this->setLinvFlag->execute($moduleName, 1);
} else {
$this->setLinvFlag->execute($moduleName, 0);
}
}
}
}
}
}