ActionScheduler_HybridStore::set_autoincrement()publicWC 1.0

When the actions table is created, set its autoincrement value to be one higher than the posts table to ensure that there are no ID collisions.

Method of the class: ActionScheduler_HybridStore{}

No Hooks.

Return

null. Nothing (null).

Usage

$ActionScheduler_HybridStore = new ActionScheduler_HybridStore();
$ActionScheduler_HybridStore->set_autoincrement( $table_name, $table_suffix );
$table_name(string) (required)
-
$table_suffix(string) (required)
-

ActionScheduler_HybridStore::set_autoincrement() code WC 8.7.0

public function set_autoincrement( $table_name, $table_suffix ) {
	if ( ActionScheduler_StoreSchema::ACTIONS_TABLE === $table_suffix ) {
		if ( empty( $this->demarkation_id ) ) {
			$this->demarkation_id = $this->set_demarkation_id();
		}
		/** @var \wpdb $wpdb */
		global $wpdb;
		/**
		 * A default date of '0000-00-00 00:00:00' is invalid in MySQL 5.7 when configured with 
		 * sql_mode including both STRICT_TRANS_TABLES and NO_ZERO_DATE.
		 */
		$default_date = new DateTime( 'tomorrow' );
		$null_action  = new ActionScheduler_NullAction();
		$date_gmt     = $this->get_scheduled_date_string( $null_action, $default_date );
		$date_local   = $this->get_scheduled_date_string_local( $null_action, $default_date );

		$row_count = $wpdb->insert(
			$wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
			[
				'action_id'            => $this->demarkation_id,
				'hook'                 => '',
				'status'               => '',
				'scheduled_date_gmt'   => $date_gmt,
				'scheduled_date_local' => $date_local,
				'last_attempt_gmt'     => $date_gmt,
				'last_attempt_local'   => $date_local,
			]
		);
		if ( $row_count > 0 ) {
			$wpdb->delete(
				$wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
				[ 'action_id' => $this->demarkation_id ]
			);
		}
	}
}