use json rather than serialize
parent
c1f8c9666c
commit
3f347f0330
|
@ -36,7 +36,7 @@ use ArrayObject;
|
||||||
*/
|
*/
|
||||||
abstract class Action
|
abstract class Action
|
||||||
{
|
{
|
||||||
/** @var array<string> Current module */
|
/** @var array<string,mixed> Current module */
|
||||||
protected $module = [];
|
protected $module = [];
|
||||||
|
|
||||||
/** @var string Current full path */
|
/** @var string Current full path */
|
||||||
|
@ -87,7 +87,7 @@ abstract class Action
|
||||||
|
|
||||||
$settings = dcCore::app()->blog->settings->get(Core::id())->get('settings_' . $this->class_name);
|
$settings = dcCore::app()->blog->settings->get(Core::id())->get('settings_' . $this->class_name);
|
||||||
if (null != $settings) {
|
if (null != $settings) {
|
||||||
$settings = unserialize($settings);
|
$settings = json_decode($settings, true);
|
||||||
}
|
}
|
||||||
$this->settings = is_array($settings) ? $settings : [];
|
$this->settings = is_array($settings) ? $settings : [];
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ abstract class Action
|
||||||
{
|
{
|
||||||
dcCore::app()->blog->settings->get(Core::id())->put(
|
dcCore::app()->blog->settings->get(Core::id())->put(
|
||||||
'settings_' . $this->class_name,
|
'settings_' . $this->class_name,
|
||||||
serialize($this->settings),
|
json_encode($this->settings),
|
||||||
'string',
|
'string',
|
||||||
null,
|
null,
|
||||||
true,
|
true,
|
||||||
|
|
21
src/Core.php
21
src/Core.php
|
@ -79,6 +79,11 @@ class Core
|
||||||
return basename(dirname(__DIR__));
|
return basename(dirname(__DIR__));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function name()
|
||||||
|
{
|
||||||
|
return __('improve');
|
||||||
|
}
|
||||||
|
|
||||||
public function getLogs(): array
|
public function getLogs(): array
|
||||||
{
|
{
|
||||||
return $this->logs;
|
return $this->logs;
|
||||||
|
@ -95,8 +100,8 @@ class Core
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcLog::LOG_TABLE_NAME);
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcLog::LOG_TABLE_NAME);
|
||||||
$cur->log_msg = serialize($this->logs);
|
$cur->log_msg = json_encode($this->logs);
|
||||||
$cur->log_table = 'improve';
|
$cur->log_table = self::id();
|
||||||
$id = dcCore::app()->log->addLog($cur);
|
$id = dcCore::app()->log->addLog($cur);
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
|
@ -104,13 +109,13 @@ class Core
|
||||||
|
|
||||||
public function readLogs(int $id): array
|
public function readLogs(int $id): array
|
||||||
{
|
{
|
||||||
$rs = dcCore::app()->log->getLogs(['log_table' => 'improve', 'log_id' => $id, 'limit' => 1]);
|
$rs = dcCore::app()->log->getLogs(['log_table' => self::id(), 'log_id' => $id, 'limit' => 1]);
|
||||||
if ($rs->isEmpty()) {
|
if ($rs->isEmpty()) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
dcCore::app()->log->delLogs($rs->__get('log_id'));
|
dcCore::app()->log->delLogs($rs->__get('log_id'));
|
||||||
|
|
||||||
$res = unserialize($rs->__get('log_msg'));
|
$res = json_decode($rs->__get('log_msg'), true);
|
||||||
|
|
||||||
return is_array($res) ? $res : [];
|
return is_array($res) ? $res : [];
|
||||||
}
|
}
|
||||||
|
@ -122,7 +127,7 @@ class Core
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$lines = [];
|
$lines = [];
|
||||||
foreach ($logs['improve'] as $path => $tools) {
|
foreach ($logs[self::id()] as $path => $tools) {
|
||||||
$l_types = [];
|
$l_types = [];
|
||||||
foreach (['success', 'warning', 'error'] as $type) {
|
foreach (['success', 'warning', 'error'] as $type) {
|
||||||
$l_tools = [];
|
$l_tools = [];
|
||||||
|
@ -198,7 +203,7 @@ class Core
|
||||||
}
|
}
|
||||||
foreach ($workers as $action) {
|
foreach ($workers as $action) {
|
||||||
// trace all path and action in logs
|
// trace all path and action in logs
|
||||||
$this->logs['improve'][__('Begin')][] = $action->id();
|
$this->logs[self::id()][__('Begin')][] = $action->id();
|
||||||
// info: set current module
|
// info: set current module
|
||||||
$action->setModule($module);
|
$action->setModule($module);
|
||||||
$action->setPath(__('Begin'), '', true);
|
$action->setPath(__('Begin'), '', true);
|
||||||
|
@ -215,7 +220,7 @@ class Core
|
||||||
}
|
}
|
||||||
foreach ($workers as $action) {
|
foreach ($workers as $action) {
|
||||||
// trace all path and action in logs
|
// trace all path and action in logs
|
||||||
$this->logs['improve'][$file[0]][] = $action->id();
|
$this->logs[self::id()][$file[0]][] = $action->id();
|
||||||
// info: set current path
|
// info: set current path
|
||||||
$action->setPath($file[0], $file[1], $file[2]);
|
$action->setPath($file[0], $file[1], $file[2]);
|
||||||
}
|
}
|
||||||
|
@ -254,7 +259,7 @@ class Core
|
||||||
}
|
}
|
||||||
foreach ($workers as $action) {
|
foreach ($workers as $action) {
|
||||||
// trace all path and action in logs
|
// trace all path and action in logs
|
||||||
$this->logs['improve'][__('End')][] = $action->id();
|
$this->logs[self::id()][__('End')][] = $action->id();
|
||||||
// info: set current module
|
// info: set current module
|
||||||
$action->setPath(__('End'), '', true);
|
$action->setPath(__('End'), '', true);
|
||||||
// action: close module
|
// action: close module
|
||||||
|
|
|
@ -16,6 +16,7 @@ namespace Dotclear\Plugin\improve;
|
||||||
|
|
||||||
/* dotclear */
|
/* dotclear */
|
||||||
use dcCore;
|
use dcCore;
|
||||||
|
use dcNamespace;
|
||||||
use dcNsProcess;
|
use dcNsProcess;
|
||||||
|
|
||||||
/* php */
|
/* php */
|
||||||
|
@ -33,7 +34,7 @@ class Install extends dcNsProcess
|
||||||
private static $default_settings = [[
|
private static $default_settings = [[
|
||||||
'disabled',
|
'disabled',
|
||||||
'List of hidden action modules',
|
'List of hidden action modules',
|
||||||
'tab;newline;endoffile',
|
'cssheader;tab;newline;endoffile',
|
||||||
'string',
|
'string',
|
||||||
]];
|
]];
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ class Install extends dcNsProcess
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self::update_0_8_0();
|
self::update_0_8_0();
|
||||||
|
self::update_1_1_0();
|
||||||
self::putSettings();
|
self::putSettings();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -88,4 +90,31 @@ class Install extends dcNsProcess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Update improve < 1.1 : use json_(en|de)code rather than (un)serialize */
|
||||||
|
private static function update_1_1_0(): void
|
||||||
|
{
|
||||||
|
if (version_compare(dcCore::app()->getVersion(Core::id()) ?? '0', '1.1', '<')) {
|
||||||
|
foreach (['setting_', 'preferences'] as $key) {
|
||||||
|
$record = dcCore::app()->con->select(
|
||||||
|
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
||||||
|
"WHERE setting_ns = '" . dcCore::app()->con->escape(Core::id()) . "' " .
|
||||||
|
"AND setting_id LIKE '" . $key . "%' "
|
||||||
|
);
|
||||||
|
|
||||||
|
while ($record->fetch()) {
|
||||||
|
try {
|
||||||
|
$value = @unserialize($record->f('setting_value'));
|
||||||
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
||||||
|
$cur->setting_value = json_encode(is_array($value) ? $value : []);
|
||||||
|
$cur->update(
|
||||||
|
"WHERE setting_id = '" . $record->f('setting_id') . "' and setting_ns = '" . dcCore::app()->con->escape($record->f('setting_ns')) . "' " .
|
||||||
|
'AND blog_id ' . (null === $record->f('blog_id') ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->f('blog_id')) . "' "))
|
||||||
|
);
|
||||||
|
} catch(Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ class Manage extends dcNsProcess
|
||||||
if (!empty(self::$type)) {
|
if (!empty(self::$type)) {
|
||||||
$preferences = dcCore::app()->blog->settings->get(Core::id())->get('preferences');
|
$preferences = dcCore::app()->blog->settings->get(Core::id())->get('preferences');
|
||||||
if (is_string($preferences)) {
|
if (is_string($preferences)) {
|
||||||
$preferences = unserialize($preferences);
|
$preferences = json_decode($preferences, true);
|
||||||
if (is_array($preferences)) {
|
if (is_array($preferences)) {
|
||||||
return $all ? $preferences : (array_key_exists(self::$type, $preferences) ? $preferences[self::$type] : []);
|
return $all ? $preferences : (array_key_exists(self::$type, $preferences) ? $preferences[self::$type] : []);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue