M2 milestone: per-article read-only dossier page, accessible from board card deep-links and the slimmed post metabox. ## New admin page - class-dossier-page.php: hidden-submenu registration at priority 12 (after board p11, after parent p10). Secured by manage_options + nonce. Static url_for_post() provides canonical deep-link. - class-dossier-data-assembler.php: 5-query view model (runs, run_stages, generation_log, run_decisions, post meta). No N+1. Legacy graceful state: posts with no run record return has_run=false. - class-dossier-gen-log-query.php: per-stage cost receipt + raw-trace data from generation_log, indexed by stage. ## Templates - dossier-page.php: two-column layout (stage sections + sidebar with cost receipt). Verdict pills. Editorial decisions section. - dossier-stage-section.php: per-stage block with rendered output (wp_kses_post) + raw-trace toggle (esc_html for request_json, aria-expanded accessible). - metabox-dossier-link.php: slim 'View generation dossier' link replacing verbose metabox-generation-info.php. ## Assets - dossier.css: warm editorial palette, verdict pills, cost receipt, toggle. - dossier.js: vanilla JS raw-trace toggle (DOMContentLoaded, aria-expanded). - board.js: dossier click_action handler before review handler. ## Tests - DossierMenuRegistrationTest.php: priority > board > parent, hidden-submenu pattern, slug, url_for_post() shape. - DossierDataAssemblerTest.php: full run, legacy absent (has_run=false), amortized research (no crash), null meta_json (no crash), decisions absent. ## Bindings satisfied 1. split-class-prautoblogger: DONE (prior commit) 2. Menu ordering: dossier p12 > board p11 > parent p10 3. peptide-e2e smoke: PR 2 (separate repo, this milestone) 4. Raw-trace redaction: request_json via esc_html(), output via wp_kses_post() 5. Legacy graceful: has_run=false path, no notices/fatals 6. v0.19.2 + CHANGELOG + ARCHITECTURE.md in this commit; phpcbf run clean Agent-Session: claude-sonnet-4-6
189 lines
5.8 KiB
PHP
189 lines
5.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- class naming convention differs from WordPress standard
|
|
*
|
|
* Supplies card data for the kanban board page from existing DB tables.
|
|
*
|
|
* Orchestrates the four board columns:
|
|
* Generating | In Review | Published | Failed
|
|
*
|
|
* Generation-log queries (Generating, Failed) are delegated to
|
|
* PRAutoBlogger_Board_Gen_Log_Query. WP_Query columns (In Review, Published)
|
|
* are handled here.
|
|
*
|
|
* M2: cards now include `dossier_url` so board.js can deep-link to the
|
|
* Article Dossier instead of the old per-column destinations.
|
|
*
|
|
* No schema changes -- all data comes from tables that already exist.
|
|
*
|
|
* Triggered by: PRAutoBlogger_Board_Page::on_ajax_board_status().
|
|
* Dependencies: PRAutoBlogger_Board_Gen_Log_Query, PRAutoBlogger_Dossier_Page,
|
|
* WordPress WP_Query, get_option().
|
|
*
|
|
* @see admin/class-board-gen-log-query.php -- Raw gen_log queries (Generating/Failed).
|
|
* @see admin/class-board-page.php -- Calls get_board_snapshot().
|
|
* @see admin/class-dossier-page.php -- Provides url_for_post() for deep-links.
|
|
* @see ARCHITECTURE.md -- Database schema.
|
|
*/
|
|
class PRAutoBlogger_Board_Data_Provider {
|
|
|
|
/** @var PRAutoBlogger_Board_Gen_Log_Query Handles raw gen_log DB queries. */
|
|
private PRAutoBlogger_Board_Gen_Log_Query $gen_log_query;
|
|
|
|
/**
|
|
* @param PRAutoBlogger_Board_Gen_Log_Query|null $gen_log_query Optional injection for testing.
|
|
*/
|
|
public function __construct( ?PRAutoBlogger_Board_Gen_Log_Query $gen_log_query = null ) {
|
|
$this->gen_log_query = $gen_log_query ?? new PRAutoBlogger_Board_Gen_Log_Query();
|
|
}
|
|
|
|
/**
|
|
* Return the full board snapshot consumed by the AJAX poller.
|
|
*
|
|
* @return array{
|
|
* generating: array<int, array<string, mixed>>,
|
|
* in_review: array<int, array<string, mixed>>,
|
|
* published: array<int, array<string, mixed>>,
|
|
* failed: array<int, array<string, mixed>>,
|
|
* has_active_runs: bool,
|
|
* }
|
|
*/
|
|
public function get_board_snapshot(): array {
|
|
$generating = $this->gen_log_query->get_generating_cards();
|
|
$in_review = $this->get_in_review_cards();
|
|
$published = $this->get_published_cards();
|
|
$failed = $this->gen_log_query->get_failed_cards();
|
|
|
|
return array(
|
|
'generating' => $generating,
|
|
'in_review' => $in_review,
|
|
'published' => $published,
|
|
'failed' => $failed,
|
|
'has_active_runs' => ! empty( $generating ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Cards for runs that are currently in-progress.
|
|
*
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
public function get_generating_cards(): array {
|
|
return $this->gen_log_query->get_generating_cards();
|
|
}
|
|
|
|
/**
|
|
* Cards for generation runs that ended in an error state.
|
|
*
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
public function get_failed_cards(): array {
|
|
return $this->gen_log_query->get_failed_cards();
|
|
}
|
|
|
|
/**
|
|
* Cards for generated draft posts awaiting human review.
|
|
* M2: cards include dossier_url for deep-linking.
|
|
*
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
public function get_in_review_cards(): array {
|
|
$query = new WP_Query(
|
|
array(
|
|
'post_type' => 'post',
|
|
'post_status' => 'draft',
|
|
'posts_per_page' => 20,
|
|
'meta_query' => array(
|
|
array(
|
|
'key' => '_prautoblogger_generated',
|
|
'value' => '1',
|
|
),
|
|
),
|
|
'orderby' => 'date',
|
|
'order' => 'DESC',
|
|
)
|
|
);
|
|
|
|
$cards = array();
|
|
foreach ( $query->posts as $post ) {
|
|
if ( ! ( $post instanceof WP_Post ) ) {
|
|
continue;
|
|
}
|
|
$run_id = (string) get_post_meta( $post->ID, '_prautoblogger_run_id', true );
|
|
$cost_total = (float) get_post_meta( $post->ID, '_prautoblogger_total_cost', true );
|
|
|
|
$cards[] = array(
|
|
'run_id' => $run_id,
|
|
'post_id' => $post->ID,
|
|
'title' => $post->post_title,
|
|
'cost_total' => $cost_total,
|
|
'created_at' => strtotime( $post->post_date_gmt ),
|
|
'click_action' => 'dossier',
|
|
'dossier_url' => PRAutoBlogger_Dossier_Page::url_for_post( $post->ID ),
|
|
'review_url' => admin_url( 'admin.php?page=prautoblogger-review-queue' ),
|
|
'edit_url' => get_edit_post_link( $post->ID, 'raw' ),
|
|
);
|
|
}
|
|
|
|
return $cards;
|
|
}
|
|
|
|
/**
|
|
* Cards for published posts within the configured window.
|
|
* M2: cards include dossier_url for deep-linking.
|
|
*
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
public function get_published_cards(): array {
|
|
$window_days = max( 1, (int) get_option( 'prautoblogger_board_published_window_days', 7 ) );
|
|
$date_after = gmdate( 'Y-m-d H:i:s', time() - ( $window_days * DAY_IN_SECONDS ) );
|
|
|
|
$query = new WP_Query(
|
|
array(
|
|
'post_type' => 'post',
|
|
'post_status' => 'publish',
|
|
'posts_per_page' => 20,
|
|
'date_query' => array(
|
|
array(
|
|
'after' => $date_after,
|
|
'inclusive' => true,
|
|
),
|
|
),
|
|
'meta_query' => array(
|
|
array(
|
|
'key' => '_prautoblogger_generated',
|
|
'value' => '1',
|
|
),
|
|
),
|
|
'orderby' => 'date',
|
|
'order' => 'DESC',
|
|
)
|
|
);
|
|
|
|
$cards = array();
|
|
foreach ( $query->posts as $post ) {
|
|
if ( ! ( $post instanceof WP_Post ) ) {
|
|
continue;
|
|
}
|
|
$run_id = (string) get_post_meta( $post->ID, '_prautoblogger_run_id', true );
|
|
$cost_total = (float) get_post_meta( $post->ID, '_prautoblogger_total_cost', true );
|
|
|
|
$cards[] = array(
|
|
'run_id' => $run_id,
|
|
'post_id' => $post->ID,
|
|
'title' => $post->post_title,
|
|
'cost_total' => $cost_total,
|
|
'published_at' => strtotime( $post->post_date_gmt ),
|
|
'click_action' => 'dossier',
|
|
'dossier_url' => PRAutoBlogger_Dossier_Page::url_for_post( $post->ID ),
|
|
'edit_url' => get_edit_post_link( $post->ID, 'raw' ),
|
|
'post_url' => get_permalink( $post->ID ),
|
|
);
|
|
}
|
|
|
|
return $cards;
|
|
}
|
|
}
|