runs = $runs; $this->reports = $reports; $this->builder = $builder; $this->contacts = $contacts; $this->client = $client; $this->operations = $operations; } /** * @param list $selected_refs Explicit local Finding references. * @return array{payload:array,digest:string,bytes:int,data_classes:list} */ public function preview( string $run_uuid, string $scope, array $selected_refs, string $idempotency_key, string $name, string $email, string $message ): array { $prepared = $this->prepare( $run_uuid, $scope, $selected_refs, $idempotency_key, $name, $email, $message ); return array( 'payload' => $prepared['payload'], 'digest' => $prepared['digest'], 'bytes' => $prepared['bytes'], 'data_classes' => $prepared['data_classes'], ); } /** * @param list $selected_refs Explicit local Finding references. * @return array{request_id:string,deletion_url:string,retention_until:string} */ public function submit( string $run_uuid, string $scope, array $selected_refs, string $idempotency_key, string $name, string $email, string $message, string $preview_digest, int $actor_id ): array { if ( $actor_id < 1 || 1 !== preg_match( '/^[a-f0-9]{64}$/D', $preview_digest ) ) { throw new InvalidArgumentException( 'review_confirmation_invalid' ); } $prepared = $this->prepare( $run_uuid, $scope, $selected_refs, $idempotency_key, $name, $email, $message ); if ( ! hash_equals( $prepared['digest'], $preview_digest ) ) { throw new InvalidArgumentException( 'review_preview_changed' ); } $run = $this->runs->get_by_uuid( $run_uuid ); if ( null === $run || RunStatus::COMPLETED !== $run->status() ) { throw new StorageException( 'run_not_found' ); } $operation_uuid = $this->operations->begin( $run->id(), 'wp_content_review_request', ReviewPayloadBuilder::DISCLOSURE_VERSION, $prepared['data_classes'], $actor_id, $prepared['digest'] ); try { $response = $this->client->submit( $prepared['json'] ); $this->operations->complete( $operation_uuid, 'succeeded', $response['request_id'] ); } catch ( \Throwable $exception ) { try { $this->operations->complete( $operation_uuid, 'failed' ); } catch ( \Throwable $ignored ) { unset( $ignored ); } throw $exception; } return $response; } /** * @param list $selected_refs Explicit local Finding references. * @return array{payload:array,json:string,digest:string,bytes:int,data_classes:list} */ private function prepare( string $run_uuid, string $scope, array $selected_refs, string $idempotency_key, string $name, string $email, string $message ): array { $run = $this->runs->get_by_uuid( $run_uuid ); if ( null === $run || RunStatus::COMPLETED !== $run->status() ) { throw new StorageException( 'run_not_found' ); } $summary = $this->runs->summary( $run_uuid ); if ( null === $summary ) { throw new StorageException( 'run_not_found' ); } return $this->builder->prepare( $summary, $this->reports->view( $run ), $this->contacts->sanitize( $name, $email, $message ), $scope, $selected_refs, $idempotency_key ); } }