mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-30 11:14:59 -04:00
- Add missing `MailchimpPlugin.` prefix to lang() calls. - Do not subscribe customer if consent is not true. - Escape output in tabular_helper.php - Removed testConnection() as unneeded code - Fix activity count logic - Whitelist Sort Column Headers for Plugins.php - Store encrypted API key as base64 instead of raw binary to prevent truncation - Rollback on batchSave partial failure. - Remove dead code. - Disable plugin before uninstalling it. - Fix getPluginSettings() internal key leak - Add action column to plugin headers function - Automatically add grant to all admins in case person_id 1 is not active Signed-off-by: objec <objecttothis@gmail.com>
109 lines
2.7 KiB
PHP
109 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class PluginConfig extends Model
|
|
{
|
|
protected $table = 'plugin_config';
|
|
protected $primaryKey = 'key';
|
|
protected $useAutoIncrement = false;
|
|
protected $useSoftDeletes = false;
|
|
protected $allowedFields = [
|
|
'key',
|
|
'value'
|
|
];
|
|
|
|
public function exists(string $key): bool
|
|
{
|
|
$builder = $this->db->table('plugin_config');
|
|
$builder->where('key', $key);
|
|
|
|
return ($builder->get()->getNumRows() === 1);
|
|
}
|
|
|
|
public function getValue(string $key): ?string
|
|
{
|
|
$builder = $this->db->table('plugin_config');
|
|
$query = $builder->getWhere(['key' => $key], 1);
|
|
|
|
if ($query->getNumRows() === 1) {
|
|
return $query->getRow()->value;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function setValue(string $key, string $value): bool
|
|
{
|
|
$builder = $this->db->table('plugin_config');
|
|
|
|
if ($this->exists($key)) {
|
|
return $builder->update(['value' => $value], ['key' => $key]);
|
|
}
|
|
|
|
return $builder->insert(['key' => $key, 'value' => $value]);
|
|
}
|
|
|
|
public function getPluginSettings(string $pluginId): array
|
|
{
|
|
$builder = $this->db->table('plugin_config');
|
|
$builder->like('key', $pluginId . '_', 'after')
|
|
->notLike('key', $pluginId . '__', 'after');
|
|
$query = $builder->get();
|
|
|
|
$settings = [];
|
|
$prefix = $pluginId . '_';
|
|
foreach ($query->getResult() as $row) {
|
|
$key = str_starts_with($row->key, $prefix)
|
|
? substr($row->key, strlen($prefix))
|
|
: $row->key;
|
|
$settings[$key] = $row->value;
|
|
}
|
|
|
|
return $settings;
|
|
}
|
|
|
|
public function deleteKey(string $key): bool
|
|
{
|
|
$builder = $this->db->table('plugin_config');
|
|
return $builder->delete(['key' => $key]);
|
|
}
|
|
|
|
public function deleteAllStartingWith(string $prefix): bool
|
|
{
|
|
$builder = $this->db->table('plugin_config');
|
|
$builder->like('key', $prefix, 'after');
|
|
return $builder->delete();
|
|
}
|
|
|
|
public function batchSave(array $data): bool
|
|
{
|
|
$this->db->transBegin();
|
|
|
|
foreach ($data as $key => $value) {
|
|
if (!$this->setValue($key, $value)) {
|
|
$this->db->transRollback();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
$this->db->transCommit();
|
|
return true;
|
|
}
|
|
|
|
public function getAll(): array
|
|
{
|
|
$builder = $this->db->table('plugin_config');
|
|
$query = $builder->get();
|
|
|
|
$configs = [];
|
|
foreach ($query->getResult() as $row) {
|
|
$configs[$row->key] = $row->value;
|
|
}
|
|
|
|
return $configs;
|
|
}
|
|
}
|