Skip to content

Commit 4b4b4b2

Browse files
authored
Fix form notification update command (#25)
1 parent 11d5418 commit 4b4b4b2

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

includes/class-gf-cli-form-notification.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,35 +391,48 @@ function duplicate( $args, $assoc_args ) {
391391
* <form-id>
392392
* : The Form ID
393393
*
394+
* [<notification-id>]
395+
* : The ID of the notification to updated.
396+
*
394397
* --notification-json=<notification-json>
395-
* : The JSON representation of the form
398+
* : The JSON representation of the notification.
396399
*
397400
* ## EXAMPLES
398401
*
399402
* wp gf form notification update 1 --notification-json='{snip}'
403+
* wp gf form notification update 1 abc1 --notification-json='{snip}'
400404
*
401-
* @synopsis <form-id> --notification-json=<notification-json>
405+
* @synopsis <form-id> [<notification-id>] --notification-json=<notification-json>
402406
*/
403407
function update( $args, $assoc_args ) {
404408
$form_id = $args[0];
409+
$form = GFAPI::get_form( $form_id );
405410

406-
$notification_id = $args[1];
407-
408-
$form = GFAPI::get_form( $form_id );
409411
if ( empty( $form ) ) {
410412
WP_CLI::error( 'Form not found' );
411413
}
412414

413-
$notifications = $form['notifications'];
414-
415-
$json_config = $assoc_args['notification-json'];
416-
415+
$json_config = $assoc_args['notification-json'];
417416
$new_notification = json_decode( $json_config, ARRAY_A );
418417

419418
if ( empty( $new_notification ) ) {
420419
WP_CLI::error( 'Notification not valid' );
421420
}
422421

422+
$notification_id = rgar( $args, 1 );
423+
424+
if ( empty( $notification_id ) ) {
425+
if ( empty( $new_notification['id'] ) ) {
426+
WP_CLI::error( 'Please specify the ID of the notification to be updated' );
427+
} else {
428+
$notification_id = $new_notification['id'];
429+
}
430+
} else {
431+
$new_notification['id'] = $notification_id;
432+
}
433+
434+
$notifications = $form['notifications'];
435+
423436
$found = false;
424437
foreach ( $notifications as $key => $notification ) {
425438
if ( $notification['id'] == $notification_id ) {

0 commit comments

Comments
 (0)