Skip to content

Commit

Permalink
fix: resolve missing EntryUser to [] instead of throwing UserError
Browse files Browse the repository at this point in the history
  • Loading branch information
justlevine committed Jan 9, 2022
1 parent 3150b66 commit 3285225
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Mutations/SubmitForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function mutate_and_get_payload() : callable {
$source_page = $input['sourcePage'] ?? 0;
$save_as_draft = $input['saveAsDraft'] ?? false;
$ip = empty( $this->form['personalData']['preventIP'] ) ? GFUtils::get_ip( $input['ip'] ?? '' ) : '';
$created_by = isset( $input['createdBy'] ) ? absint( $input['createdBy'] ) : null;
$created_by = ! empty( $input['createdBy'] ) ? absint( $input['createdBy'] ) : null;
$source_url = $input['sourceUrl'] ?? '';

// Initialize $_FILES with fileupload inputs.
Expand Down Expand Up @@ -213,8 +213,11 @@ private function update_entry_properties( array $submission, string $ip, string
}
}

if ( null !== $created_by ) {
if ( ! empty( $created_by ) ) {
$is_updated = GFAPI::update_entry_property( $submission['entry_id'], 'created_by', $created_by );
// Leave for testing.
graphql_debug( $created_by );

if ( false === $is_updated ) {
throw new UserError( __( 'Unable to update the entry createdBy id.', 'wp-graphql-gravity-forms' ) );
}
Expand Down
2 changes: 1 addition & 1 deletion src/Types/Entry/EntryUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function register_field() : void {
$user = isset( $entry['createdById'] ) ? get_userdata( $entry['createdById'] ) : null;

if ( ! $user instanceof WP_User ) {
throw new UserError( __( 'The user who created this entry could not be found.', 'wp-graphql-gravity-forms' ) );
return [];
}

return [
Expand Down

0 comments on commit 3285225

Please sign in to comment.