this->table_name} ADD COLUMN job_id VARCHAR(255) NULL default '' AFTER is_mobile " ); } if ( ! $queuename_column_exists ) { $created &= $this->get_db()->query( "ALTER TABLE {$this->table_name} ADD COLUMN queue_name VARCHAR(255) NULL default '' AFTER job_id " ); } if ( ! $status_column_exists ) { $created &= $this->get_db()->query( "ALTER TABLE {$this->table_name} ADD COLUMN status VARCHAR(255) NULL default '' AFTER queue_name " ); } return $this->is_success( $created ); } /** * Make status column as index. * * @return bool */ protected function make_status_column_index() { $queuename_column_exists = $this->column_exists( 'queue_name' ); if ( ! $queuename_column_exists ) { return $this->is_success( false ); } if ( $this->index_exists( 'queue_name_index' ) ) { return $this->is_success( true ); } $index_added = $this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX `queue_name_index` (`queue_name`) " ); return $this->is_success( $index_added ); } /** * Add hash column and index * * @return bool */ protected function add_hash_column() { $hash_column_exists = $this->column_exists( 'hash' ); $created = true; if ( ! $hash_column_exists ) { $created &= $this->get_db()->query( "ALTER TABLE {$this->table_name} ADD COLUMN hash VARCHAR(32) NULL default '' AFTER css, ADD KEY hash (hash) " ); } return $this->is_success( $created ); } /** * Make status column as index. * * @return bool */ protected function make_status_column_index_instead_queue_name() { $queuename_column_exists = $this->column_exists( 'status' ); if ( ! $queuename_column_exists ) { return $this->is_success( false ); } if ( $this->index_exists( 'status_index' ) ) { return $this->is_success( true ); } if ( $this->index_exists( 'queue_name_index' ) ) { if ( ! $this->get_db()->query( "ALTER TABLE {$this->table_name} DROP INDEX `queue_name_index`" ) ) { return $this->is_success( false ); } } $index_added = $this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX `status_index` (`status`(191)) " ); return $this->is_success( $index_added ); } /** * Remove all completed rows. * * @return bool|int */ public function remove_all_completed_rows() { // Get the database interface. $db = $this->get_db(); // Bail if no database interface is available. if ( empty( $db ) ) { return false; } $prefixed_table_name = $this->apply_prefix( $this->table_name ); return $db->query( "DELETE FROM `$prefixed_table_name` WHERE status IN ( 'failed', 'completed' )" ); } /** * Returns name from table. * * @return string */ public function get_name() { return $this->apply_prefix( $this->table_name ); } /** * Trigger recreation of cache table if not exist. * * @return void */ public function maybe_trigger_recreate_table() { if ( $this->exists() ) { return; } delete_option( $this->db_version_key ); } /** * Add error columns * * @return bool */ protected function add_error_columns() { return $this->add_error_message_column() && $this->add_error_code_column() && $this->make_error_code_column_index(); } /** * Add error_message column and index * * @return bool */ private function add_error_message_column() { $error_message_column_exists = $this->column_exists( 'error_message' ); $created = true; if ( ! $error_message_column_exists ) { $created &= $this->get_db()->query( "ALTER TABLE `{$this->table_name}` ADD COLUMN error_message longtext NULL default NULL AFTER hash" ); } return $this->is_success( $created ); } /** * Add error_code column and index * * @return bool */ private function add_error_code_column() { $error_code_column_exists = $this->column_exists( 'error_code' ); $created = true; if ( ! $error_code_column_exists ) { $created &= $this->get_db()->query( "ALTER TABLE `{$this->table_name}` ADD COLUMN error_code VARCHAR(32) NULL default NULL AFTER hash" ); } return $this->is_success( $created ); } /** * Make status column as index. * * @return bool */ private function make_error_code_column_index() { $error_code_column_exists = $this->column_exists( 'error_code' ); if ( ! $error_code_column_exists ) { return $this->is_success( false ); } if ( $this->index_exists( 'error_code_index' ) ) { return $this->is_success( true ); } $index_added = $this->get_db()->query( "ALTER TABLE {$this->table_name} ADD INDEX `error_code_index` (`error_code`) " ); return $this->is_success( $index_added ); } }