Commit da2095c2 authored by Pieter Frenssen's avatar Pieter Frenssen
Browse files

Fix fatal error when retrieving status report without configuring Matomo server URL.

parent 960b12be
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
<?php

use Drupal\matomo_reporting_api\Exception\MissingMatomoServerUrlException;
use GuzzleHttp\Exception\ConnectException;

/**
@@ -16,7 +17,13 @@ use GuzzleHttp\Exception\ConnectException;
 */
function matomo_reporting_api_get_api_version() {
  /** @var \Matomo\ReportingApi\QueryResult $result */
  try {
    $query = \Drupal::service('matomo.query_factory')->getQuery('API.getMatomoVersion');
  }
  catch (MissingMatomoServerUrlException $e) {
    return FALSE;
  }

  try {
    $result = $query->execute();
    if (!$result->hasError() && $result->parameterExists('value')) {
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@ interface MatomoQueryFactoryInterface {
   * @return \Matomo\ReportingApi\QueryInterface
   *   The Matomo reporting API query object.
   *
   * @throws \Drupal\matomo_reporting_api\Exception\MissingMatomoServerUrlException
   *   Thrown when the Matomo server URL has not been configured.
   *
   * @see https://developer.matomo.org/api-reference/reporting-api#api-method-list
   */
  public function getQuery($method);
@@ -26,6 +29,9 @@ interface MatomoQueryFactoryInterface {
   *
   * @return \Matomo\ReportingApi\QueryFactoryInterface
   *   The query factory.
   *
   * @throws \Drupal\matomo_reporting_api\Exception\MissingMatomoServerUrlException
   *   Thrown when the Matomo server URL has not been configured.
   */
  public function getQueryFactory();