id = $id; $this->remote_workflow_uuid = $remote_workflow_uuid; $this->remote_execution_uuid = $remote_execution_uuid; $this->context_json = $context_json; $this->execution_json = $execution_json; $this->run_at = $run_at; $this->status = $status; $this->created_at = $created_at; } /** * Create from database row. * * @param object $row Database row. * @return self */ public static function fromRow( object $row ): self { return new self( (int) $row->id, (string) ( $row->remote_workflow_uuid ?? '' ), (string) ( $row->remote_execution_uuid ?? '' ), (string) ( $row->context_json ?? '' ), (string) ( $row->execution_json ?? '' ), (string) ( $row->run_at ?? '' ), (string) ( $row->status ?? 'pending' ), (string) ( $row->created_at ?? '' ) ); } /** * Local WordPress workflow post ID from context (local queue jobs only). * * @return int */ public function getLocalWorkflowId(): int { $ctx = $this->getContext(); return isset( $ctx['workflow_id'] ) ? absint( $ctx['workflow_id'] ) : 0; } /** * Get the remote workflow UUID. * * @return string */ public function getRemoteWorkflowUuid(): string { return $this->remote_workflow_uuid; } /** * Get the remote execution UUID. * * @return string */ public function getRemoteExecutionUuid(): string { return $this->remote_execution_uuid; } /** * Get the run at datetime. * * @return string */ public function getRunAt(): string { return $this->run_at; } /** * Get the status. * * @return string */ public function getStatus(): string { return $this->status; } /** * Get decoded context as array. * * @return array */ public function getContext(): array { $decoded = json_decode( $this->context_json, true ); return is_array( $decoded ) ? $decoded : array(); } /** * Get the created at datetime. * * @return string */ public function getCreatedAt(): string { return $this->created_at; } /** * Get decoded execution results as array. * * @param bool $indexed Whether to index the results by step_index and type. * @return array */ public function getExecutionResults($indexed = false): array { $decoded = json_decode( $this->execution_json, true ); $results = is_array( $decoded ) ? $decoded : array(); if ( false === $indexed ) { return $results; } $indexed_results = array(); foreach ( $results as $i => $result ) { if (empty($result['step_index'])) { $result['step_index'] = -1 * ($i + 1); } $indexed_results["{$result['step_index']}_{$result['type']}"] = $result; } return $indexed_results; } }