/
home
/
altere25
/
.trash
/
wp-to-sanity-migration.12
/
/home/altere25/.trash/wp-to-sanity-migration.12
mkdir
upload
Name
Size
Mode
Actions
acf-json\.gitkeep
0
0644
edit
dl
rm
assets\css\admin.css
12113
0644
edit
dl
rm
assets\js\admin.js
52894
0644
edit
dl
rm
includes\class-ad-admin.php
10358
0644
edit
dl
rm
includes\class-ad-ai-client.php
10724
0644
edit
dl
rm
includes\class-ad-auth.php
9189
0644
edit
dl
rm
includes\class-ad-cli.php
8671
0644
edit
dl
rm
includes\class-ad-extractor.php
17237
0644
edit
dl
rm
includes\class-ad-mcp.php
6429
0644
edit
dl
rm
includes\class-ad-plugin-core.php
10252
0644
edit
dl
rm
includes\class-ad-progress.php
8022
0644
edit
dl
rm
includes\class-ad-rest.php
43443
0644
edit
dl
rm
includes\class-ad-uninstall.php
1966
0644
edit
dl
rm
includes\class-ad-webhook.php
24172
0644
edit
dl
rm
languages\.gitkeep
0
0644
edit
dl
rm
templates\admin\wizard.php
29414
0644
edit
dl
rm
wp-to-sanity-migration\acf-json\.gitkeep
0
0644
edit
dl
rm
wp-to-sanity-migration\assets\
0
0644
edit
dl
rm
wp-to-sanity-migration\assets\css\admin.css
12113
0644
edit
dl
rm
wp-to-sanity-migration\assets\js\admin.js
52894
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-admin.php
10358
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-ai-client.php
10724
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-auth.php
9189
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-cli.php
8671
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-extractor.php
17237
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-mcp.php
6429
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-plugin-core.php
10252
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-progress.php
8022
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-rest.php
43443
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-uninstall.php
1966
0644
edit
dl
rm
wp-to-sanity-migration\includes\class-ad-webhook.php
24172
0644
edit
dl
rm
wp-to-sanity-migration\languages\.gitkeep
0
0644
edit
dl
rm
wp-to-sanity-migration\package.json
220
0644
edit
dl
rm
wp-to-sanity-migration\readme.txt
8174
0644
edit
dl
rm
wp-to-sanity-migration\templates\
0
0644
edit
dl
rm
wp-to-sanity-migration\templates\admin\wizard.php
29414
0644
edit
dl
rm
wp-to-sanity-migration\uninstall.php
365
0644
edit
dl
rm
wp-to-sanity-migration\wp-to-sanity-migration.php
4418
0644
edit
dl
rm
Edit:
/home/altere25/.trash/wp-to-sanity-migration.12/includes\class-ad-cli.php
(8671B)
<?php /** * Altered Digital Migration — WP-CLI commands * * wp altered-digital export [--post-type=post,page] [--limit=500] [--include-drafts] * wp altered-digital analyze * wp altered-digital status [--post-id=123] * * The export command bypasses REST timeouts by driving the webhook directly * in-process — useful for large sites where the REST /export/bulk endpoint * would hit PHP's max_execution_time. * * @package AlteredDigitalMigration */ if (!defined('ABSPATH')) { exit; } // WP-CLI is optional — only register when the class exists. if (!class_exists('WP_CLI')) { return; } class AD_CLI { /** @var AD_Plugin_Core */ private $core; /** @var AD_Webhook */ private $webhook; /** @var AD_Extractor */ private $extractor; /** @var AD_Progress */ private $progress; /** @var AD_Auth|null */ private $auth; public function __construct(AD_Plugin_Core $core, AD_Webhook $webhook, AD_Extractor $extractor, AD_Progress $progress, ?AD_Auth $auth = null) { $this->core = $core; $this->webhook = $webhook; $this->extractor = $extractor; $this->progress = $progress; $this->auth = $auth; } /** * Bulk-export posts to Sanity via the webhook pipeline. * * ## OPTIONS * * [--post-type=<types>] * : Comma-separated post types to export. Default: post,page * * [--limit=<n>] * : Max posts to export per type. Default: 500 * * [--include-drafts] * : Include draft posts in the export. * * [--offset=<n>] * : Skip the first N posts (for resuming). Default: 0 * * ## EXAMPLES * * wp altered-digital export --post-type=post,page --limit=1000 * wp altered-digital export --include-drafts --limit=50 * * @param array $args * @param array $assoc_args */ public function export($args, $assoc_args): void { $post_types = isset($assoc_args['post-type']) ? array_filter(array_map('trim', explode(',', (string) $assoc_args['post-type']))) : $this->core->setting('post_types', ['post', 'page']); $limit = isset($assoc_args['limit']) ? absint($assoc_args['limit']) : 500; $include_drafts = isset($assoc_args['include-drafts']) || (bool) $this->core->setting('include_drafts', false); $offset = isset($assoc_args['offset']) ? absint($assoc_args['offset']) : 0; $webhook_url = $this->core->setting('webhook_url'); if (empty($webhook_url)) { WP_CLI::error('Webhook URL not configured. Configure it in the WP to Sanity wizard.'); } $total_exported = 0; $total_skipped = 0; foreach ($post_types as $pt) { $query_args = [ 'post_type' => $pt, 'post_status' => $include_drafts ? ['publish', 'draft', 'private'] : ['publish'], 'posts_per_page' => $limit, 'offset' => $offset, 'orderby' => 'ID', 'order' => 'ASC', 'no_found_rows' => false, ]; $query = new WP_Query($query_args); WP_CLI::log("Post type '{$pt}': {$query->found_posts} posts found (exporting up to {$limit})."); $progress = \WP_CLI\Utils\make_progress_bar("Exporting {$pt}", min($query->found_posts, $limit)); $exported = 0; $skipped = 0; foreach ($query->posts as $post) { $post = get_post($post); if (!$post) { $skipped++; continue; } try { $this->progress->log_pending($post->ID, 'export'); $this->webhook->trigger_export($post); $exported++; } catch (Throwable $e) { $skipped++; WP_CLI::warning("Post {$post->ID} ({$post->post_type}) failed: {$e->getMessage()}"); } $progress->tick(); } $progress->finish(); WP_CLI::log(" Exported: {$exported}, Skipped: {$skipped}"); $total_exported += $exported; $total_skipped += $skipped; } WP_CLI::success("Export complete. Total exported: {$total_exported}, skipped: {$total_skipped}."); } /** * Run a full-site analysis and print the summary. * * ## EXAMPLES * * wp altered-digital analyze * * @param array $args * @param array $assoc_args */ public function analyze($args, $assoc_args): void { $ai_url = $this->core->setting('ai_service_url'); if (empty($ai_url)) { WP_CLI::error('AI service URL not configured. Configure it in the WP to Sanity wizard.'); } WP_CLI::log('Building analysis payload…'); $payload = $this->extractor->build_analysis_payload(); WP_CLI::log(json_encode($payload, JSON_PRETTY_PRINT)); $site_url = site_url(); $jwt = ''; if ($this->auth) { $jwt = $this->auth->access_token() ?? ''; } if (empty($jwt)) { WP_CLI::warning('No AD account session found. Run the onboarding wizard to log in, then re-run analyze.'); } WP_CLI::log('Sending to AI service for analysis…'); $endpoint = rtrim($ai_url, '/') . '/analyze'; $response = wp_remote_post($endpoint, [ 'timeout' => 60, 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $jwt, ], 'body' => wp_json_encode([ 'wp_site_url' => $site_url, 'plugin_analysis_payload' => $payload, ]), ]); if (is_wp_error($response)) { WP_CLI::error('Analysis failed: ' . $response->get_error_message()); } $code = wp_remote_retrieve_response_code($response); $body = wp_remote_retrieve_body($response); if ($code < 200 || $code >= 300) { WP_CLI::error("AI service returned HTTP {$code}: {$body}"); } $decoded = json_decode($body, true); WP_CLI::success('Analysis complete:'); WP_CLI::log(json_encode($decoded, JSON_PRETTY_PRINT)); } /** * Show migration status (aggregate or per-post). * * ## OPTIONS * * [--post-id=<id>] * : Show history for a single post. * * ## EXAMPLES * * wp altered-digital status * wp altered-digital status --post-id=42 * * @param array $args * @param array $assoc_args */ public function status($args, $assoc_args): void { global $wpdb; $table = $wpdb->prefix . 'ad_migration_log'; if (isset($assoc_args['post-id'])) { $post_id = absint($assoc_args['post-id']); $rows = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$table} WHERE post_id = %d ORDER BY created_at DESC LIMIT 100", $post_id), ARRAY_A ); if (empty($rows)) { WP_CLI::log("No migration log entries for post {$post_id}."); return; } WP_CLI\Utils\format_items('table', $rows, ['id', 'post_id', 'action', 'status', 'sanity_id', 'error_message', 'created_at']); return; } $stats = $wpdb->get_row( "SELECT COUNT(*) as total, SUM(CASE WHEN status = 'success' THEN 1 ELSE 0 END) as success, SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) as pending, SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) as failed FROM {$table}", ARRAY_A ); $recent = $wpdb->get_results( "SELECT id, post_id, action, status, sanity_id, error_message, created_at FROM {$table} ORDER BY created_at DESC LIMIT 20", ARRAY_A ); WP_CLI::log('Migration status (local log):'); WP_CLI::log(" Total: {$stats['total']}"); WP_CLI::log(" Success: {$stats['success']}"); WP_CLI::log(" Pending: {$stats['pending']}"); WP_CLI::log(" Failed: {$stats['failed']}"); if (!empty($recent)) { WP_CLI::log(''); WP_CLI::log('Recent 20 entries:'); WP_CLI\Utils\format_items('table', $recent, ['id', 'post_id', 'action', 'status', 'sanity_id', 'error_message', 'created_at']); } } }
Save
cmd:
run