refactor(autoload): migrate theme classes to Composer PSR-4
Move 288 types from global AKSRT_* + inc/classes manual requires into
namespace AKSRT\{Domain} under src/AKSRT/, wire composer.json psr-4,
and slim bootstrap to helpers/modules/hooks only. Split multi-class
widget/gateway files, update admin contract audit paths, and document
the layout in ADR/README.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Admin;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
trait ImportExportControllerPart2 {
|
||||
|
||||
|
||||
private function get_backup_schedule_settings(): array {
|
||||
$provider = SchemaProvider::get_instance();
|
||||
$settings = $provider->read_settings('tools', 'backup');
|
||||
$frequency = sanitize_key((string) ($settings['backup_frequency'] ?? 'weekly'));
|
||||
$allowed = ['daily', 'weekly', 'monthly'];
|
||||
if (!in_array($frequency, $allowed, true)) {
|
||||
$frequency = 'weekly';
|
||||
}
|
||||
|
||||
return [
|
||||
'enabled' => !empty($settings['backup_auto']),
|
||||
'schedule' => $frequency === 'monthly' ? self::MONTHLY_SCHEDULE : $frequency,
|
||||
];
|
||||
}
|
||||
|
||||
private function build_settings_backup(string $type, string $label = ''): array {
|
||||
$schema_provider = SchemaProvider::get_instance();
|
||||
$domains = $schema_provider->get_domain_keys();
|
||||
|
||||
$payload = [
|
||||
'version' => AKSRT_VERSION ?? '3.4.0',
|
||||
'exported' => gmdate('Y-m-d H:i:s'),
|
||||
'domains' => [],
|
||||
'standalone'=> [],
|
||||
];
|
||||
|
||||
foreach ($domains as $domain) {
|
||||
$payload['domains'][$domain] = [
|
||||
'option_key' => $schema_provider->get_option_key($domain),
|
||||
'data' => $schema_provider->read_settings($domain),
|
||||
];
|
||||
}
|
||||
|
||||
foreach (\AKSRT\Settings\Settings::STANDALONE_OPTION_KEYS as $key) {
|
||||
$value = get_option($key);
|
||||
if ($value !== false) {
|
||||
$payload['standalone'][$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => time(),
|
||||
'type' => $type,
|
||||
'label' => $label !== '' ? $label : $this->default_backup_label($type),
|
||||
'created_at' => gmdate('Y-m-d H:i:s'),
|
||||
'payload' => $payload,
|
||||
];
|
||||
}
|
||||
|
||||
private function trim_setting_backups(array $backups): array {
|
||||
$retain = (int) (\AKSRT\Settings\Settings::get_value('backup_retain', 7));
|
||||
$retain = max(3, min(20, $retain));
|
||||
|
||||
if (count($backups) <= $retain) {
|
||||
return array_values($backups);
|
||||
}
|
||||
|
||||
return array_values(array_slice($backups, 0, $retain));
|
||||
}
|
||||
|
||||
private function default_backup_label(string $type): string {
|
||||
$map = [
|
||||
'manual' => __('手动备份', 'aksrt'),
|
||||
'scheduled' => __('定期备份', 'aksrt'),
|
||||
'reset_all' => __('重置全部前快照', 'aksrt'),
|
||||
'reset_domain' => __('重置分区前快照', 'aksrt'),
|
||||
'update_theme' => __('更新主题前快照', 'aksrt'),
|
||||
];
|
||||
|
||||
return $map[$type] ?? __('设置快照', 'aksrt');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user