refactor: Cleanup git state - commit all staged changes
Major refactoring cleanup: - Add new controller architecture (class-controller-*.php) - Add new settings-v2 UI (views/settings-v2/) - Add new CSS architecture (agentic-sidebar.css, tokens) - Add esbuild build pipeline (scripts/build.js, package.json) - Add composer dependencies (vendor/) - Add frontend src directory (assets/js/src/index.jsx) - Add documentation files - Remove old/obsolete files (class-settings.php, old CSS) This commits all pending changes from previous refactoring efforts.
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
* @package WP_Agentic_Writer
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
if (!defined("ABSPATH")) {
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -14,13 +14,14 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
*
|
||||
* @since 0.1.4
|
||||
*/
|
||||
function wpaw_create_conversations_table() {
|
||||
global $wpdb;
|
||||
function wpaw_create_conversations_table()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . 'wpaw_conversations';
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
$table_name = $wpdb->prefix . "wpaw_conversations";
|
||||
$charset_collate = $wpdb->get_charset_collate();
|
||||
|
||||
$sql = "CREATE TABLE IF NOT EXISTS {$table_name} (
|
||||
$sql = "CREATE TABLE IF NOT EXISTS {$table_name} (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
session_id VARCHAR(32) NOT NULL UNIQUE,
|
||||
user_id BIGINT NOT NULL,
|
||||
@@ -37,14 +38,19 @@ function wpaw_create_conversations_table() {
|
||||
INDEX idx_session_id (session_id)
|
||||
) {$charset_collate};";
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
||||
dbDelta( $sql );
|
||||
require_once ABSPATH . "wp-admin/includes/upgrade.php";
|
||||
dbDelta($sql);
|
||||
|
||||
// Store conversation table migration version (don't override main db version)
|
||||
$existing_version = get_option( 'wpaw_conversations_db_version', '0' );
|
||||
if ( version_compare( $existing_version, '0.1.4', '<' ) ) {
|
||||
update_option( 'wpaw_conversations_db_version', '0.1.4' );
|
||||
}
|
||||
// Migrate session_id column width for UUID support (UUID v4 is 36 chars vs old MD5 32)
|
||||
$wpdb->query(
|
||||
"ALTER TABLE {$table_name} MODIFY session_id VARCHAR(36) NOT NULL",
|
||||
);
|
||||
|
||||
// Store conversation table migration version (don't override main db version)
|
||||
$existing_version = get_option("wpaw_conversations_db_version", "0");
|
||||
if (version_compare($existing_version, "0.1.4", "<")) {
|
||||
update_option("wpaw_conversations_db_version", "0.1.4");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,11 +58,12 @@ function wpaw_create_conversations_table() {
|
||||
*
|
||||
* @since 0.1.4
|
||||
*/
|
||||
function wpaw_drop_conversations_table() {
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'wpaw_conversations';
|
||||
$wpdb->query( "DROP TABLE IF EXISTS {$table_name}" );
|
||||
delete_option( 'wpaw_conversations_db_version' );
|
||||
function wpaw_drop_conversations_table()
|
||||
{
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . "wpaw_conversations";
|
||||
$wpdb->query("DROP TABLE IF EXISTS {$table_name}");
|
||||
delete_option("wpaw_conversations_db_version");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,12 +71,17 @@ function wpaw_drop_conversations_table() {
|
||||
*
|
||||
* @since 0.1.4
|
||||
*/
|
||||
function wpaw_run_migrations() {
|
||||
$current_version = get_option( 'wpaw_conversations_db_version', '0' );
|
||||
function wpaw_run_migrations()
|
||||
{
|
||||
$current_version = get_option("wpaw_conversations_db_version", "0");
|
||||
|
||||
if ( version_compare( $current_version, '0.1.4', '<' ) ) {
|
||||
wpaw_create_conversations_table();
|
||||
}
|
||||
if (version_compare($current_version, "0.1.4", "<")) {
|
||||
wpaw_create_conversations_table();
|
||||
}
|
||||
|
||||
if (version_compare($current_version, "0.2.0", "<")) {
|
||||
wpaw_add_edit_lock_column();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,22 +90,48 @@ function wpaw_run_migrations() {
|
||||
*
|
||||
* @since 0.1.4
|
||||
*/
|
||||
function wpaw_cleanup_old_sessions() {
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'wpaw_conversations';
|
||||
function wpaw_cleanup_old_sessions()
|
||||
{
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . "wpaw_conversations";
|
||||
|
||||
// Archive sessions with no post_id and inactive for 30 days
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"UPDATE {$table_name} SET status = 'archived' WHERE status = 'active' AND post_id = 0 AND updated_at < %s",
|
||||
date( 'Y-m-d H:i:s', strtotime( '-30 days' ) )
|
||||
)
|
||||
);
|
||||
// Archive sessions with no post_id and inactive for 30 days
|
||||
$wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"UPDATE {$table_name} SET status = 'archived' WHERE status = 'active' AND post_id = 0 AND updated_at < %s",
|
||||
date("Y-m-d H:i:s", strtotime("-30 days")),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add edit_lock column to conversations table.
|
||||
*
|
||||
* @since 0.2.0
|
||||
*/
|
||||
function wpaw_add_edit_lock_column()
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$table_name = $wpdb->prefix . "wpaw_conversations";
|
||||
|
||||
// Check if column already exists (idempotent).
|
||||
$column_exists = $wpdb->get_results(
|
||||
$wpdb->prepare("SHOW COLUMNS FROM {$table_name} LIKE %s", "edit_lock"),
|
||||
);
|
||||
|
||||
if (empty($column_exists)) {
|
||||
$wpdb->query(
|
||||
"ALTER TABLE {$table_name} ADD COLUMN edit_lock VARCHAR(64) DEFAULT NULL",
|
||||
);
|
||||
}
|
||||
|
||||
update_option("wpaw_conversations_db_version", "0.2.0");
|
||||
}
|
||||
|
||||
// Register cron job for cleanup
|
||||
add_action( 'wpaw_cleanup_old_sessions', 'wpaw_cleanup_old_sessions' );
|
||||
add_action("wpaw_cleanup_old_sessions", "wpaw_cleanup_old_sessions");
|
||||
|
||||
if ( ! wp_next_scheduled( 'wpaw_cleanup_old_sessions' ) ) {
|
||||
wp_schedule_event( time(), 'daily', 'wpaw_cleanup_old_sessions' );
|
||||
}
|
||||
if (!wp_next_scheduled("wpaw_cleanup_old_sessions")) {
|
||||
wp_schedule_event(time(), "daily", "wpaw_cleanup_old_sessions");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user