From c9a354e4baf88d3654dd069ab2215ec375198e91 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 14 Aug 2023 12:22:54 +0300 Subject: [PATCH] implement hostSetting set/get methods --- README.md | 5 +-- src/cli/yggo.php | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dce4d9b..b0f7dc9 100644 --- a/README.md +++ b/README.md @@ -235,8 +235,9 @@ _*CLI interface still under construction, use it for your own risk!_ * [x] crawl * [x] clean * [ ] hostSetting - + [ ] get - + [ ] set + + [x] get + + [x] set + + [ ] list + [ ] delete + [ ] flush * [x] hostPage diff --git a/src/cli/yggo.php b/src/cli/yggo.php index 1003ec3..426e404 100644 --- a/src/cli/yggo.php +++ b/src/cli/yggo.php @@ -100,6 +100,96 @@ if (!empty($argv[1])) { } } + break; + case 'hostSetting': + + if (!empty($argv[2])) { + + switch ($argv[2]) { + + case 'set': + + if (!empty($argv[3]) && !empty($argv[4]) && !empty($argv[5])) { + + switch ($argv[4]) { + + case 'PAGES_LIMIT': + + if ($hostSetting = $db->findHostSetting((int) $argv[3], 'PAGES_LIMIT')) { + + if ($db->updateHostSetting($hostSetting->hostSettingId, (int) $argv[5], time())) { + + CLI::warning(sprintf(_('%s for hostId %s updated:'), $argv[4], $argv[3])); + CLI::warning( + sprintf( + '%s > %s', + $hostSetting->value, + $argv[5], + ) + ); + + exit; + } + + } else { + + if ($db->addHostSetting((int) $argv[3], 'PAGES_LIMIT', (int) $argv[5], time())) { + + CLI::warning(sprintf(_('%s for hostId %s added:'), $argv[4], $argv[3])); + CLI::warning( + sprintf( + '%s > %s', + $argv[4], + $argv[5], + ) + ); + + exit; + } + } + + break; + default: + + CLI::danger('unsupported host settings key'); + } + } + + break; + + case 'get': + + if (!empty($argv[3]) && !empty($argv[4])) { + + if ($hostSetting = $db->findHostSetting((int) $argv[3], (string) $argv[4])) { + + CLI::success(sprintf(_('%s for hostId %s is:'), $argv[4], $argv[3])); + CLI::success( + is_array($hostSetting->value) ? print_r($hostSetting->value, true) : $hostSetting->value + ); + + exit; + + } else { + + CLI::warning( + sprintf( + 'setting %s for hostId %s not found!', + $argv[4], + $argv[3] + ) + ); + + exit; + } + } + + break; + } + } + + break; + break; case 'hostPageSnap': @@ -489,6 +579,10 @@ CLI::default(' hostPage '); CLI::default(' rank '); CLI::default(' reindex - reindex hostPage.rank fields'); CLI::break(); +CLI::default(' hostSetting '); +CLI::default(' set [hostId] [key] [value] - set formatted value by hostId and key'); +CLI::default(' get [hostId] [key] - get formatted value by hostId and key'); +CLI::break(); CLI::default(' hostPageSnap '); CLI::default(' repair '); CLI::default(' db - scan database registry for new or deprecated snap files');