From fef22c1ff8bcaaca61f0b596de2e2f245b75fc9f Mon Sep 17 00:00:00 2001 From: Vladimir Bryzgalov Date: Fri, 17 Apr 2026 22:49:25 +0500 Subject: [PATCH] feat(activator): create queue table, schedule cron, guard PHP/WP versions --- includes/class-activator.php | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 includes/class-activator.php diff --git a/includes/class-activator.php b/includes/class-activator.php new file mode 100644 index 0000000..22b1037 --- /dev/null +++ b/includes/class-activator.php @@ -0,0 +1,76 @@ +prefix . 'cf7stg_queue'; + $charset_collate = $wpdb->get_charset_collate(); + + $sql = "CREATE TABLE {$table} ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + flamingo_post_id BIGINT UNSIGNED NULL, + form_id BIGINT UNSIGNED NULL, + source_key VARCHAR(40) NOT NULL DEFAULT 'cf7', + payload_json LONGTEXT NOT NULL, + label VARCHAR(10) NOT NULL DEFAULT 'unclear', + is_retro TINYINT(1) NOT NULL DEFAULT 0, + status VARCHAR(20) NOT NULL DEFAULT 'pending', + attempts SMALLINT UNSIGNED NOT NULL DEFAULT 0, + last_error TEXT NULL, + next_try_at DATETIME NULL, + created_at DATETIME NOT NULL, + sent_at DATETIME NULL, + PRIMARY KEY (id), + KEY idx_status_next (status, next_try_at), + UNIQUE KEY uq_flamingo (flamingo_post_id, is_retro) + ) {$charset_collate};"; + + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; + dbDelta($sql); + update_option(self::DB_VERSION_OPTION, self::DB_VERSION); + } + + private static function schedule_events(): void + { + if (!wp_next_scheduled('cf7stg_dispatch')) { + wp_schedule_event(time() + 60, 'cf7stg_every_minute', 'cf7stg_dispatch'); + } + if (!wp_next_scheduled('cf7stg_cleanup')) { + wp_schedule_event(time() + 3600, 'daily', 'cf7stg_cleanup'); + } + } +}