suppress_errors(true); try { foreach(Schema::pilotOperations($wpdb) as $table=>$sql){ if($table===\ABeCe\Booking\Infrastructure\Database\Tables::name( $wpdb, 'booking_series' )){ if(!$wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s',$wpdb->esc_like($table)))){dbDelta($sql);$this->check($wpdb);} }else{ $columns=$wpdb->get_col($wpdb->prepare('SHOW COLUMNS FROM %i',$table));$this->check($wpdb); if($table===\ABeCe\Booking\Infrastructure\Database\Tables::name( $wpdb, 'resource_blocks' )){ $field=$wpdb->get_row($wpdb->prepare("SHOW COLUMNS FROM %i WHERE Field='resource_id'",$table));if($field&&$field->Null==='NO'){$wpdb->query($wpdb->prepare('ALTER TABLE %i MODIFY resource_id bigint unsigned DEFAULT NULL',$table));$this->check($wpdb);}} $indexes=$wpdb->get_col($wpdb->prepare('SHOW INDEX FROM %i',$table),2);$this->check($wpdb);$changes=[]; foreach(explode("\n",$sql) as $line){$line=trim($line," \t\r,"); if(preg_match('/^(series_id|series_occurrence_key|series_is_exception|group_uuid|public_title|note) (.+)$/',$line,$m)&&!in_array($m[1],$columns,true))$changes[]='ADD '.$line; if(preg_match('/^(?:UNIQUE )?KEY (uq_asb_booking_occurrence|idx_asb_group_uuid) /',$line,$m)&&!in_array($m[1],$indexes,true))$changes[]='ADD '.$line; } if($changes){$wpdb->query($wpdb->prepare('ALTER TABLE %i '.implode(', ',$changes),$table));$this->check($wpdb);} } Schema::verify($wpdb,$table,$sql); } }finally{$wpdb->suppress_errors($old);} } private function check(\wpdb $wpdb):void{if($wpdb->last_error)throw new RuntimeException(__('ABeCe Booking database migration failed. Existing data has been retained.','abece-booking'));} }