*/ public function list_jobs(): array { $job_objects = array(); foreach ( JobId::cases() as $job ) { $job_objects[] = $this->presenter->present( $job, $this->store->load( $job ) ); } return $job_objects; } /** * @param WP_REST_Request> $job_request * @return JobObject|WP_Error */ public function change_job( WP_REST_Request $job_request ): array|WP_Error { $job_id = $job_request->get_param( 'id' ); $job = is_string( $job_id ) ? JobId::tryFrom( $job_id ) : null; if ( null === $job ) { return new WP_Error( self::NOT_FOUND_CODE, __( 'This job does not exist.', 'aiplaz-link-checkup' ), array( 'status' => self::NOT_FOUND_STATUS ) ); } $state = $this->store->load( $job ); $changes = (array) $job_request->get_json_params(); $changed = $this->job_change->apply( $job, $state, $changes ); if ( $changed instanceof WP_Error ) { return $changed; } $this->store->save( $job, $changed ); if ( ! $changed->has_same_schedule( $state ) ) { $this->scheduler->reschedule( $job, $changed ); } return $this->presenter->present( $job, $changed ); } /** @return list */ public function run_jobs(): array { spawn_cron(); return $this->list_jobs(); } }