$row Synthetic row; see the target applier's own docblock for its expected keys. * @return array{ok:bool,refusalMessage:string|null,refusalReason:string,appliedFreeDefaults:array} `appliedFreeDefaults` names each stored option the applier wrote in its Free form, with the reason. */ protected function callApplier( string $tool, array $row ): array { try { $applier = ContentReviewApplierFactory::forTool( $tool ); $ok = $applier->apply( $row ); return array( 'ok' => $ok, 'refusalMessage' => null, 'refusalReason' => '', 'appliedFreeDefaults' => $applier instanceof ReportsAppliedFreeDefaults ? $applier->appliedFreeDefaults() : array(), ); } catch ( ContentReviewApplyRefusedException $e ) { return array( 'ok' => false, 'refusalMessage' => $e->getMessage(), 'refusalReason' => $e->reason(), 'appliedFreeDefaults' => array() ); } catch ( \Throwable $e ) { return array( 'ok' => false, 'refusalMessage' => null, 'refusalReason' => '', 'appliedFreeDefaults' => array() ); } } /** * Whether a refusal happened before any write for a transient reason * (the product save lock, or a license check that could not be verified), * so repeating the same apply may succeed. * * @param array $outcome {@see callApplier()} result. * @return bool */ protected function isRetryableRefusal( array $outcome ): bool { $reason = (string) ( $outcome['refusalReason'] ?? '' ); return 'lock_unavailable' === $reason || PlanDenial::isVerificationUnavailable( $reason ); } /** * The four blueprint-attribution synthetic-row keys from an apply * `$context` ({@see ResultApplier}'s `blueprintId`/`blueprintName`/ * `blueprintRevision`/`blueprintBuiltin`), for a subclass to merge into * the synthetic row it builds for {@see callApplier()}. The downstream * `ContentReviewApplier` reads these the same way whether the row is * real (from `aipt_content_review`) or synthetic — see * `BlueprintSnapshotFieldsTrait`. Zero/empty defaults for a * custom-prompts context, which carries none of these keys. * * @param array $context Apply context (see ApplyAdapterInterface). * @return array{blueprint_id:int,blueprint_name:string,blueprint_revision:int,blueprint_builtin:bool} */ protected function blueprintRowFields( array $context ): array { return array( 'blueprint_id' => isset( $context['blueprintId'] ) ? (int) $context['blueprintId'] : 0, 'blueprint_name' => isset( $context['blueprintName'] ) ? (string) $context['blueprintName'] : '', 'blueprint_revision' => isset( $context['blueprintRevision'] ) ? (int) $context['blueprintRevision'] : 0, 'blueprint_builtin' => ! empty( $context['blueprintBuiltin'] ), ); } /** * Flip the named fields' 'written' entry to 'failed' — used when ONE * applier call covering only those fields did not land, without * touching a sibling field/subject whose own call already succeeded. * Callers dispatch one {@see callApplier()} call per field/subject * precisely so this can stay scoped instead of a blanket mark-all-failed * that would misreport a write that actually landed. * * @param array $fields Field entries. * @param array $field_names Field names this call covered. * @return array */ protected function markFieldsFailed( array $fields, array $field_names ): array { foreach ( $fields as $index => $field ) { if ( in_array( $field['field'] ?? '', $field_names, true ) && 'written' === ( $field['outcome'] ?? '' ) ) { $fields[ $index ]['outcome'] = 'failed'; } } return $fields; } }