-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Expand file tree
/
Copy pathConfig.php
More file actions
99 lines (92 loc) · 2.7 KB
/
Config.php
File metadata and controls
99 lines (92 loc) · 2.7 KB
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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\Model\ResourceModel;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
/**
* Core Resource Resource Model
*
* @api
* @since 100.0.2
*/
class Config extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb implements
\Magento\Framework\App\Config\ConfigResource\ConfigInterface
{
/**
* @var PoisonPillPutInterface
*/
private $pillPut;
/**
* Define main table
*
* @param PoisonPillPutInterface|null $pillPut
* @return void
*/
protected function _construct(
PoisonPillPutInterface $pillPut = null
) {
$this->_init('core_config_data', 'config_id');
$this->pillPut = $pillPut ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(PoisonPillPutInterface::class);
}
/**
* Save config value
*
* @param string $path
* @param string $value
* @param string $scope
* @param int $scopeId
* @return $this
*/
public function saveConfig($path, $value, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0)
{
$connection = $this->getConnection();
$select = $connection->select()->from(
$this->getMainTable()
)->where(
'path = ?',
$path
)->where(
'scope = ?',
$scope
)->where(
'scope_id = ?',
$scopeId
);
$row = $connection->fetchRow($select);
$newData = ['scope' => $scope, 'scope_id' => $scopeId, 'path' => $path, 'value' => $value];
if ($row) {
$whereCondition = [$this->getIdFieldName() . '=?' => $row[$this->getIdFieldName()]];
$connection->update($this->getMainTable(), $newData, $whereCondition);
} else {
$connection->insert($this->getMainTable(), $newData);
}
$this->pillPut->put();
return $this;
}
/**
* Delete config value
*
* @param string $path
* @param string $scope
* @param int $scopeId
* @return $this
*/
public function deleteConfig($path, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0)
{
$connection = $this->getConnection();
$connection->delete(
$this->getMainTable(),
[
$connection->quoteInto('path = ?', $path),
$connection->quoteInto('scope = ?', $scope),
$connection->quoteInto('scope_id = ?', $scopeId)
]
);
$this->pillPut->put();
return $this;
}
}