- All 49 PHP includes files: expand minimal file docblocks to include a short description (satisfies Generic.Commenting.DocComment.MissingShort) Format: <?php\n/**\n * Filename-derived description.\n *\n * @package ...\n */ - settings.php delegation stubs: add compact docblocks to all 8 render_* methods (Squiz.Commenting.FunctionComment.Missing, lines 93-231) - settings.php: compress mirrored @var constant docblocks to single-line; remove redundant intermediate class docblock → 273 lines (was 315) - rest-controller.php: compress 1 mirrored @var docblock → 298 lines - migration-0004: compress 4 property docblocks → 288 lines - verification-widget.php line 111: cast days_since to int + phpcs:ignore - verification-metabox.php line 80: phpcs:ignore on hardcoded badge_class - peptide-metaboxes.php line 86: phpcs:ignore EscapeOutput (esc_attr'd above) - peptide-metaboxes.php lines 147/148: Yoda null !== dose_min/dose_max - peptide-metaboxes.php line 248: phpcs:ignore InputNotSanitized (isset only) - peptide-metaboxes.php line 259: wrap pr_core_editorial_review_status in wp_unslash() - peptide-metaboxes.php line 262: Yoda 'published' !== old_status Agent-Session: claude-adopt-ci-20260616
115 lines
2.9 KiB
PHP
115 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Migration Runner.
|
|
*
|
|
* @package Peptide_Repo_Core
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Compares current schema version against target, runs pending migrations
|
|
*
|
|
* @package Peptide_Repo_Core
|
|
*/
|
|
|
|
/**
|
|
* Schema migration runner.
|
|
*
|
|
* What: Compares current schema version against target, runs pending migrations.
|
|
* Who calls it: PR_Core::init() on every plugins_loaded, PR_Core_Activator on activation.
|
|
* Dependencies: WordPress $wpdb, dbDelta().
|
|
*
|
|
* Migrations are numbered sequentially (0001, 0002, ...). Each migration class
|
|
* must implement up() and optionally down(). All migrations are idempotent.
|
|
*
|
|
* @see peptide-repo-core.php — Defines PR_CORE_TARGET_SCHEMA_VERSION.
|
|
* @see CONVENTIONS.md — "How To: Add a New Migration".
|
|
*/
|
|
class PR_Core_Migration_Runner {
|
|
|
|
/**
|
|
* Option key storing current schema version.
|
|
*
|
|
* @var string Option key storing current schema version.
|
|
*/
|
|
private const VERSION_OPTION = 'pr_core_schema_version';
|
|
|
|
/**
|
|
* Ordered list of migration classes.
|
|
* Index 0 = migration 1 (bumps schema to version 1).
|
|
*
|
|
* @var string[]
|
|
*/
|
|
private const MIGRATIONS = array(
|
|
'PR_Core_Migration_0001_Dosing_Rows',
|
|
'PR_Core_Migration_0002_Legal_Cells',
|
|
'PR_Core_Migration_0003_Candidate_Queue',
|
|
'PR_Core_Migration_0004_Backfill_Peptide_Meta',
|
|
);
|
|
|
|
/**
|
|
* Run all pending migrations up to PR_CORE_TARGET_SCHEMA_VERSION.
|
|
*
|
|
* Side effects: creates/alters database tables, updates schema version option.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run_pending(): void {
|
|
$current = (int) get_option( self::VERSION_OPTION, 0 );
|
|
$target = PR_CORE_TARGET_SCHEMA_VERSION;
|
|
|
|
if ( $current >= $target ) {
|
|
return;
|
|
}
|
|
|
|
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
|
|
|
for ( $i = $current; $i < $target; $i++ ) {
|
|
if ( ! isset( self::MIGRATIONS[ $i ] ) ) {
|
|
break;
|
|
}
|
|
|
|
$class = self::MIGRATIONS[ $i ];
|
|
if ( ! class_exists( $class ) ) {
|
|
// Migration file not autoloaded — load explicitly.
|
|
$file = $this->class_to_file( $class );
|
|
if ( file_exists( $file ) ) {
|
|
require_once $file;
|
|
}
|
|
}
|
|
|
|
if ( class_exists( $class ) ) {
|
|
$migration = new $class();
|
|
$migration->up();
|
|
}
|
|
|
|
update_option( self::VERSION_OPTION, $i + 1 );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get current schema version.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function get_current_version(): int {
|
|
return (int) get_option( self::VERSION_OPTION, 0 );
|
|
}
|
|
|
|
/**
|
|
* Convert migration class name to file path.
|
|
*
|
|
* PR_Core_Migration_0001_Dosing_Rows => migrations/class-pr-core-migration-0001-dosing-rows.php
|
|
*
|
|
* @param string $class Fully-qualified class name.
|
|
* @return string Absolute file path.
|
|
*/
|
|
private function class_to_file( string $class ): string {
|
|
$suffix = substr( $class, 8 ); // Strip 'PR_Core_'.
|
|
$filename = 'class-pr-core-' . str_replace( '_', '-', strtolower( $suffix ) ) . '.php';
|
|
|
|
return PR_CORE_PLUGIN_DIR . 'includes/migrations/' . $filename;
|
|
}
|
|
}
|