Spaces:
Sleeping
Sleeping
| defined( 'ABSPATH' ) || exit; | |
| class SA_Orch_Link { | |
| public static function write( array $args ) { | |
| global $wpdb; | |
| $arbitration_id = isset( $args['arbitration_id'] ) ? (int) $args['arbitration_id'] : 0; | |
| $plan_surface = isset( $args['plan_surface'] ) ? trim( (string) $args['plan_surface'] ) : ''; | |
| $plan_ref = isset( $args['plan_ref'] ) ? trim( (string) $args['plan_ref'] ) : ''; | |
| $link_kind = isset( $args['link_kind'] ) ? trim( (string) $args['link_kind'] ) : 'derived'; | |
| if ( $arbitration_id === 0 ) { | |
| return new WP_Error( 'missing_arbitration_id', 'arbitration_id is required' ); | |
| } | |
| if ( $plan_surface === '' || $plan_ref === '' ) { | |
| return new WP_Error( 'missing_plan_ref', 'plan_surface and plan_ref are required' ); | |
| } | |
| $created_at = current_time( 'mysql', true ); | |
| $table = $wpdb->prefix . SA_ORCH_DB_PREFIX . 'arbitration_plan_link'; | |
| $ok = $wpdb->insert( $table, [ | |
| 'arbitration_id' => $arbitration_id, | |
| 'plan_surface' => $plan_surface, | |
| 'plan_ref' => $plan_ref, | |
| 'link_kind' => $link_kind, | |
| 'created_at' => $created_at, | |
| ] ); | |
| if ( $ok === false ) { | |
| return new WP_Error( 'db_insert_failed', $wpdb->last_error ); | |
| } | |
| return (int) $wpdb->insert_id; | |
| } | |
| } | |