prefix . 'r2clouder_jobs'; } /** * Creates or updates the jobs table. * * The schema deliberately avoids FULLTEXT indexes and any MySQL-only * construct, so it works on the SQLite backend as well. * * @return void */ public static function create_tables(): void { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $table = self::jobs_table(); $collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE {$table} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, attachment_id bigint(20) unsigned NOT NULL DEFAULT 0, job_type varchar(32) NOT NULL DEFAULT '', status varchar(16) NOT NULL DEFAULT 'pending', priority smallint(6) NOT NULL DEFAULT 10, attempts smallint(6) NOT NULL DEFAULT 0, available_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', claimed_at datetime DEFAULT NULL, finished_at datetime DEFAULT NULL, last_error text NULL, payload longtext NULL, created_at datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id), KEY status_available (status, available_at), KEY attachment (attachment_id, job_type) ) {$collate};"; dbDelta( $sql ); update_option( 'r2clouder_db_version', self::DB_VERSION, false ); } /** * Registers the queue cron event when it is not already scheduled. * * @return void */ public static function schedule(): void { if ( ! wp_next_scheduled( self::CRON_HOOK ) ) { wp_schedule_event( time() + MINUTE_IN_SECONDS, self::CRON_SCHEDULE, self::CRON_HOOK ); } } /** * Removes the queue cron event. * * @return void */ public static function unschedule(): void { wp_clear_scheduled_hook( self::CRON_HOOK ); } /** * Returns every site id on the network, capped to keep activation bounded. * * @return int[] */ private static function site_ids(): array { if ( ! is_multisite() ) { return array( get_current_blog_id() ); } return get_sites( array( 'fields' => 'ids', 'number' => 0, 'update_site_meta_cache' => false, ) ); } }