ActionScheduler_LoggerSchema::update_schema_3_0()
Update the logs table schema, allowing datetime fields to be NULL.
This is needed because the NOT NULL constraint causes a conflict with some versions of MySQL configured with sql_mode=NO_ZERO_DATE, which can for instance lead to tables not being created.
Most other schema updates happen via ActionScheduler_Abstract_Schema::update_table(), however that method relies on dbDelta() and this change is not possible when using that function.
Method of the class: ActionScheduler_LoggerSchema{}
No Hooks.
Return
null
. Nothing (null).
Usage
$ActionScheduler_LoggerSchema = new ActionScheduler_LoggerSchema(); $ActionScheduler_LoggerSchema->update_schema_3_0( $table, $db_version );
- $table(string) (required)
- Name of table being updated.
- $db_version(string) (required)
- The existing schema version of the table.
ActionScheduler_LoggerSchema::update_schema_3_0() ActionScheduler LoggerSchema::update schema 3 0 code WC 9.6.1
public function update_schema_3_0( $table, $db_version ) { global $wpdb; if ( 'actionscheduler_logs' !== $table || version_compare( $db_version, '3', '>=' ) ) { return; } // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared $table_name = $wpdb->prefix . 'actionscheduler_logs'; $table_list = $wpdb->get_col( "SHOW TABLES LIKE '{$table_name}'" ); $default_date = ActionScheduler_StoreSchema::DEFAULT_DATE; if ( ! empty( $table_list ) ) { $query = " ALTER TABLE {$table_name} MODIFY COLUMN log_date_gmt datetime NULL default '{$default_date}', MODIFY COLUMN log_date_local datetime NULL default '{$default_date}' "; $wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared } // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared }