ActionScheduler_StoreSchema::update_schema_5_0()publicWC 1.0

Update the actions 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.

Метод класса: ActionScheduler_StoreSchema{}

Хуков нет.


null. Ничего (null).


$ActionScheduler_StoreSchema = new ActionScheduler_StoreSchema();
$ActionScheduler_StoreSchema->update_schema_5_0( $table, $db_version );
$table(строка) (обязательный)
Name of table being updated.
$db_version(строка) (обязательный)
The existing schema version of the table.

Код ActionScheduler_StoreSchema::update_schema_5_0() WC 8.9.0

public function update_schema_5_0( $table, $db_version ) {
	global $wpdb;

	if ( 'actionscheduler_actions' !== $table || version_compare( $db_version, '5', '>=' ) ) {

	// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	$table_name   = $wpdb->prefix . 'actionscheduler_actions';
	$table_list   = $wpdb->get_col( "SHOW TABLES LIKE '{$table_name}'" );
	$default_date = self::DEFAULT_DATE;

	if ( ! empty( $table_list ) ) {
		$query = "
			ALTER TABLE {$table_name}
			MODIFY COLUMN scheduled_date_gmt datetime NULL default '{$default_date}',
			MODIFY COLUMN scheduled_date_local datetime NULL default '{$default_date}',
			MODIFY COLUMN last_attempt_gmt datetime NULL default '{$default_date}',
			MODIFY COLUMN last_attempt_local datetime NULL default '{$default_date}'
		$wpdb->query( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
	// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared