Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.
Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)
Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
(dropped 3 stale entries, added the 17 missing ones)
Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
when it is empty
Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.
Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
236 lines
7.6 KiB
PHP
236 lines
7.6 KiB
PHP
<?php
|
|
/**
|
|
* @package Jio
|
|
*/
|
|
|
|
namespace Jio\Admin;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
trait ImportExportControllerPart1 {
|
|
|
|
/**
|
|
* Get the schema definition for a domain (for frontend introspection).
|
|
*/
|
|
public function rest_get_schema(\WP_REST_Request $request): \WP_REST_Response {
|
|
$domain = $request->get_param('domain');
|
|
$schema_provider = SchemaProvider::get_instance();
|
|
|
|
$schema = $schema_provider->get_schema($domain);
|
|
if (!$schema) {
|
|
return $this->error('未知的设置域: ' . esc_html($domain), 404);
|
|
}
|
|
|
|
return $this->success(['schema' => $schema]);
|
|
}
|
|
|
|
public function rest_get_schema_section(\WP_REST_Request $request): \WP_REST_Response {
|
|
return $this->get_section_settings($request, (string) $request->get_param('domain'));
|
|
}
|
|
|
|
public function rest_save_schema_section(\WP_REST_Request $request): \WP_REST_Response {
|
|
return $this->save_section_settings($request, (string) $request->get_param('domain'));
|
|
}
|
|
|
|
public function list_setting_backups(\WP_REST_Request $request): \WP_REST_Response {
|
|
$backups = get_option('jio_settings_backups', []);
|
|
if (!is_array($backups)) {
|
|
$backups = [];
|
|
}
|
|
|
|
usort($backups, static function ($a, $b) {
|
|
return strcmp((string) ($b['created_at'] ?? ''), (string) ($a['created_at'] ?? ''));
|
|
});
|
|
|
|
return $this->success([
|
|
'data' => [
|
|
'items' => array_values($backups),
|
|
'total' => count($backups),
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function create_setting_backup(\WP_REST_Request $request): \WP_REST_Response {
|
|
$params = $this->get_json_params($request);
|
|
$type = sanitize_key((string) ($params['type'] ?? 'manual'));
|
|
$label = sanitize_text_field((string) ($params['label'] ?? ''));
|
|
|
|
$allowed_types = ['manual', 'scheduled', 'reset_all', 'reset_domain', 'update_theme'];
|
|
if (!in_array($type, $allowed_types, true)) {
|
|
$type = 'manual';
|
|
}
|
|
|
|
$backup = $this->build_settings_backup($type, $label);
|
|
$this->persist_setting_backup($backup);
|
|
|
|
return $this->success([
|
|
'message' => __('设置快照已创建', 'jio'),
|
|
'data' => $backup,
|
|
]);
|
|
}
|
|
|
|
public function restore_setting_backup(\WP_REST_Request $request): \WP_REST_Response {
|
|
$id = (int) $request->get_param('id');
|
|
$backups = get_option('jio_settings_backups', []);
|
|
if (!is_array($backups)) {
|
|
$backups = [];
|
|
}
|
|
|
|
$target = null;
|
|
foreach ($backups as $backup) {
|
|
if ((int) ($backup['id'] ?? 0) === $id) {
|
|
$target = $backup;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$target || !is_array($target['payload'] ?? null)) {
|
|
return $this->error(__('备份快照不存在', 'jio'), 404);
|
|
}
|
|
|
|
$payload = $target['payload'];
|
|
$domains = $payload['domains'] ?? [];
|
|
$standalone = \Jio\Settings\Settings::filter_sensitive_import(
|
|
is_array($payload['standalone'] ?? null) ? $payload['standalone'] : []
|
|
);
|
|
$provider = SchemaProvider::get_instance();
|
|
|
|
foreach ($domains as $domain => $domainPayload) {
|
|
$data = $domainPayload['data'] ?? $domainPayload;
|
|
if (is_array($data) && in_array((string) $domain, $provider->get_domain_keys(), true)) {
|
|
$clean = $provider->sanitize_payload((string) $domain, $data);
|
|
$validation = $provider->validate((string) $domain, $clean);
|
|
if ($validation['valid']) {
|
|
$provider->write_settings((string) $domain, $clean);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($standalone as $key => $value) {
|
|
if (is_string($key) && in_array($key, \Jio\Settings\Settings::standalone_export_keys(), true)) {
|
|
update_option($key, $value);
|
|
}
|
|
}
|
|
|
|
\Jio\Settings\Settings::flush_settings_cache();
|
|
|
|
return $this->success([
|
|
'message' => __('设置已从快照恢复', 'jio'),
|
|
'data' => [
|
|
'id' => $id,
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function delete_setting_backup(\WP_REST_Request $request): \WP_REST_Response {
|
|
$id = (int) $request->get_param('id');
|
|
$backups = get_option('jio_settings_backups', []);
|
|
if (!is_array($backups)) {
|
|
$backups = [];
|
|
}
|
|
|
|
$filtered = [];
|
|
$found = false;
|
|
foreach ($backups as $backup) {
|
|
if ((int) ($backup['id'] ?? 0) === $id) {
|
|
$found = true;
|
|
continue;
|
|
}
|
|
$filtered[] = $backup;
|
|
}
|
|
|
|
if (!$found) {
|
|
return $this->error(__('备份快照不存在', 'jio'), 404);
|
|
}
|
|
|
|
update_option('jio_settings_backups', array_values($filtered));
|
|
|
|
return $this->success([
|
|
'message' => __('备份快照已删除', 'jio'),
|
|
]);
|
|
}
|
|
|
|
|
|
private function persist_setting_backup(array $backup): void {
|
|
$backups = get_option('jio_settings_backups', []);
|
|
if (!is_array($backups)) {
|
|
$backups = [];
|
|
}
|
|
|
|
array_unshift($backups, $backup);
|
|
update_option('jio_settings_backups', $this->trim_setting_backups($backups));
|
|
}
|
|
|
|
private function create_backup_record(string $type, string $label = ''): array {
|
|
return $this->build_settings_backup($type, $label);
|
|
}
|
|
|
|
public function register_backup_schedules(array $schedules): array {
|
|
if (!isset($schedules[self::MONTHLY_SCHEDULE])) {
|
|
$schedules[self::MONTHLY_SCHEDULE] = [
|
|
'interval' => MONTH_IN_SECONDS,
|
|
'display' => __('每月', 'jio'),
|
|
];
|
|
}
|
|
|
|
return $schedules;
|
|
}
|
|
|
|
public function sync_backup_schedule(): void {
|
|
$settings = $this->get_backup_schedule_settings();
|
|
$next = wp_next_scheduled(self::SCHEDULED_BACKUP_HOOK);
|
|
|
|
if (!$settings['enabled']) {
|
|
if ($next) {
|
|
wp_unschedule_event($next, self::SCHEDULED_BACKUP_HOOK);
|
|
}
|
|
return;
|
|
}
|
|
|
|
$schedule = $settings['schedule'];
|
|
if ($next && wp_get_schedule(self::SCHEDULED_BACKUP_HOOK) !== $schedule) {
|
|
wp_unschedule_event($next, self::SCHEDULED_BACKUP_HOOK);
|
|
$next = false;
|
|
}
|
|
|
|
if (!$next) {
|
|
wp_schedule_event(time() + HOUR_IN_SECONDS, $schedule, self::SCHEDULED_BACKUP_HOOK);
|
|
}
|
|
}
|
|
|
|
public function clear_backup_schedule(): void {
|
|
$next = wp_next_scheduled(self::SCHEDULED_BACKUP_HOOK);
|
|
while ($next) {
|
|
wp_unschedule_event($next, self::SCHEDULED_BACKUP_HOOK);
|
|
$next = wp_next_scheduled(self::SCHEDULED_BACKUP_HOOK);
|
|
}
|
|
}
|
|
|
|
public function run_scheduled_backup(): void {
|
|
$settings = $this->get_backup_schedule_settings();
|
|
if (!$settings['enabled']) {
|
|
return;
|
|
}
|
|
|
|
$backup = $this->create_backup_record('scheduled');
|
|
$this->persist_setting_backup($backup);
|
|
}
|
|
|
|
public function handle_theme_upgrade_snapshot($response, array $hook_extra) {
|
|
if (($hook_extra['type'] ?? '') !== 'theme') {
|
|
return $response;
|
|
}
|
|
|
|
$themes = $hook_extra['themes'] ?? [];
|
|
$stylesheet = wp_get_theme()->get_stylesheet();
|
|
if (!in_array($stylesheet, (array) $themes, true)) {
|
|
return $response;
|
|
}
|
|
|
|
$backup = $this->create_backup_record('update_theme');
|
|
$this->persist_setting_backup($backup);
|
|
|
|
return $response;
|
|
}
|
|
}
|