diff --git a/uw_wcms_tools.drupal.modules.inc b/uw_wcms_tools.drupal.modules.inc index b3697bde965a1c7656c043ea403f84134adf6a9e..7ab08e8c14cb16b847485438c4a1fc7b33e73374 100644 --- a/uw_wcms_tools.drupal.modules.inc +++ b/uw_wcms_tools.drupal.modules.inc @@ -105,6 +105,10 @@ function uw_wcms_tools_create_module_update_tickets($module, $version, $depended require_once 'uw_wcms_tools.jira.inc'; uw_wcms_tools_create_jira_for_rt($id, $links); + + if (!isset($jira_ticket->key)) { + drupal_set_message(t('Failed to create corresponding Jira ticket.'), 'error'); + } } else { throw new Exception('Failed to create RT ticket.'); diff --git a/uw_wcms_tools.jira.inc b/uw_wcms_tools.jira.inc index bf45bd11cca6f00ae4d86405932c2540a754ca38..42920ca8bd4615889cdf09f97309f1cdaf135648 100644 --- a/uw_wcms_tools.jira.inc +++ b/uw_wcms_tools.jira.inc @@ -49,7 +49,7 @@ function uw_wcms_tools_jira_api_query($path, stdClass $data = NULL, $method = 'P } $url = 'https://' . $jira_username . ':' . $jira_password . '@jira.uwaterloo.ca/rest/api/2/' . $path; - $results = @file_get_contents($url, FALSE, $context); + $results = file_get_contents($url, FALSE, $context); if ($results) { return json_decode($results); } @@ -63,8 +63,11 @@ function uw_wcms_tools_jira_api_query($path, stdClass $data = NULL, $method = 'P * documentation. */ function uw_wcms_tools_jira_api_ticket_create(stdClass $jira_ticket) { - foreach (uw_wcms_tools_jira_api_query('issue', $jira_ticket) as $key => $value) { - $jira_ticket->$key = $value; + $result = uw_wcms_tools_jira_api_query('issue', $jira_ticket); + if (is_array($result)) { + foreach ($result as $key => $value) { + $jira_ticket->$key = $value; + } } } @@ -117,7 +120,9 @@ function uw_wcms_tools_create_jira_for_rt($id, array $links = []) { uw_wcms_tools_jira_api_ticket_create($jira_ticket); // Add to the RT ticket a link to the new Jira ticket. - $links['ReferredToBy'] = UW_WCMS_TOOLS_JIRA_URL_PREFIX . $jira_ticket->key; + if (isset($jira_ticket->key)) { + $links['ReferredToBy'] = UW_WCMS_TOOLS_JIRA_URL_PREFIX . $jira_ticket->key; + } foreach ($links as $relationship => $target) { $rt->addTicketLink($id, $relationship, $target); diff --git a/uw_wcms_tools.tickets.inc b/uw_wcms_tools.tickets.inc index edb915a11c76ca72d5f79f664a2f9eaa7ade50ce..4e4a323b497f89bc395eb8019ce1ebb27c22dc09 100644 --- a/uw_wcms_tools.tickets.inc +++ b/uw_wcms_tools.tickets.inc @@ -69,7 +69,7 @@ function uw_wcms_tools_ticket_create_form_submit(array $form, array &$form_state case 'RT': $jira = uw_wcms_tools_create_jira_for_rt($ticket_id); - $copy_id = $jira->key; + $copy_id = $jira->key ?? NULL; break; } @@ -77,7 +77,12 @@ function uw_wcms_tools_ticket_create_form_submit(array $form, array &$form_state '!copy' => uw_wcms_tools_get_ticket_link($copy_id), '!original' => uw_wcms_tools_get_ticket_link($ticket_id), ]; - drupal_set_message(t('Created !copy for !original.', $args)); + if ($copy_id) { + drupal_set_message(t('Created !copy for !original.', $args)); + } + else { + drupal_set_message(t('Failed to create corresponding ticket for !original.', $args), 'error'); + } } /**