Skip to content

Commit

Permalink
Merge pull request #880 from matomo-org/835-system-report-safeties
Browse files Browse the repository at this point in the history
Surround more functionality in the System Report with try-catches.
  • Loading branch information
diosmosis authored Oct 24, 2023
2 parents 8026336 + 59f65a6 commit c6b7308
Showing 1 changed file with 102 additions and 51 deletions.
153 changes: 102 additions & 51 deletions classes/WpMatomo/Admin/SystemReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,10 @@ private function get_matomo_info() {
];
} catch ( Exception $e ) {
$rows[] = [
'name' => esc_html__( 'Matomo System Check', 'matomo' ),
'value' => 'Failed to run Matomo system check.',
'comment' => $e->getMessage(),
'name' => esc_html__( 'Matomo System Check', 'matomo' ),
'value' => 'Failed to run Matomo system check.',
'comment' => $e->getMessage(),
'is_error' => true,
];
}
}
Expand Down Expand Up @@ -664,14 +665,23 @@ private function get_matomo_info() {
];
$rows = $this->add_diagnostic_results( $rows, $report->getOptionalDiagnosticResults() );

$cli_multi = new CliMulti();
$suports_async = $cli_multi->supportsAsync();
try {
$cli_multi = new CliMulti();
$suports_async = $cli_multi->supportsAsync();

$rows[] = [
'name' => 'Supports Async Archiving',
'value' => $suports_async,
'comment' => '',
];
$rows[] = [
'name' => esc_html__( 'Supports Async Archiving', 'matomo' ),
'value' => $suports_async,
'comment' => '',
];
} catch ( \Exception $e ) {
$rows[] = [
'name' => esc_html__( 'Supports Async Archiving', 'matomo' ),
'value' => 'Could not check if async archiving is supported.',
'comment' => $e->getMessage(),
'is_error' => true,
];
}

$rows[] = [
'name' => 'Async Archiving Disabled in Setting',
Expand All @@ -681,21 +691,33 @@ private function get_matomo_info() {

$location_provider = LocationProvider::getCurrentProvider();
if ( $location_provider ) {
$rows[] = [
'name' => 'Location provider ID',
'value' => $location_provider->getId(),
'comment' => '',
];
$rows[] = [
'name' => 'Location provider available',
'value' => $location_provider->isAvailable(),
'comment' => '',
];
$rows[] = [
'name' => 'Location provider working',
'value' => $location_provider->isWorking(),
'comment' => '',
];
try {
$location_provider = LocationProvider::getCurrentProvider();
if ( $location_provider ) {
$rows[] = [
'name' => 'Location provider ID',
'value' => $location_provider->getId(),
'comment' => '',
];
$rows[] = [
'name' => 'Location provider available',
'value' => $location_provider->isAvailable(),
'comment' => '',
];
$rows[] = [
'name' => 'Location provider working',
'value' => $location_provider->isWorking(),
'comment' => '',
];
}
} catch ( \Exception $e ) {
$rows[] = [
'name' => 'Location provider ID',
'value' => 'Failed to get the configured Location Provider.',
'comment' => $e->getMessage(),
'is_error' => true,
];
}
}

if ( ! WpMatomo::is_safe_mode() ) {
Expand All @@ -714,19 +736,32 @@ private function get_matomo_info() {
}
}
}
$incompatible_plugins = Plugin\Manager::getInstance()->getIncompatiblePlugins( Version::VERSION );
if ( ! empty( $incompatible_plugins ) ) {
$rows[] = [
'section' => esc_html__( 'Incompatible Matomo plugins', 'matomo' ),
];
foreach ( $incompatible_plugins as $plugin ) {

try {
$incompatible_plugins = Plugin\Manager::getInstance()->getIncompatiblePlugins( Version::VERSION );
if ( ! empty( $incompatible_plugins ) ) {
$rows[] = [
'name' => 'Plugin has missing dependencies',
'value' => $plugin->getPluginName(),
'is_error' => true,
'comment' => sprintf( esc_html__( '%s If the plugin requires a different Matomo version you may need to update it. If you no longer use it consider uninstalling it.', 'matomo' ), $plugin->getMissingDependenciesAsString( Version::VERSION ) ),
'section' => esc_html__( 'Incompatible Matomo plugins', 'matomo' ),
];
foreach ( $incompatible_plugins as $plugin ) {
$rows[] = [
'name' => 'Plugin has missing dependencies',
'value' => $plugin->getPluginName(),
'is_error' => true,
'comment' => sprintf( esc_html__( '%s If the plugin requires a different Matomo version you may need to update it. If you no longer use it consider uninstalling it.', 'matomo' ), $plugin->getMissingDependenciesAsString( Version::VERSION ) ),
];
}
}
} catch ( \Exception $e ) {
$rows[] = [
'section' => esc_html__( 'Incompatible Matomo plugins', 'matomo' ),
];
$rows[] = [
'name' => 'Incompatible Matomo plugin check',
'value' => 'Failed to check for incompatible Matomo plugins.',
'is_error' => true,
'comment' => $e->getMessage(),
];
}
}

Expand All @@ -750,12 +785,22 @@ private function get_matomo_info() {

if ( ! WpMatomo::is_safe_mode() ) {
Bootstrap::do_bootstrap();
$matomo_url = SettingsPiwik::getPiwikUrl();
$rows[] = [
'name' => 'Matomo URL',
'comment' => $matomo_url,
'value' => ! empty( $matomo_url ),
];

try {
$matomo_url = SettingsPiwik::getPiwikUrl();
$rows[] = [
'name' => 'Matomo URL',
'comment' => $matomo_url,
'value' => ! empty( $matomo_url ),
];
} catch ( \Exception $e ) {
$rows[] = [
'name' => 'Matomo URL',
'comment' => $e->getMessage(),
'value' => 'Failed to fetch the Matomo URL.',
'is_error' => true,
];
}
}

// check that yml files are not accessible
Expand Down Expand Up @@ -970,8 +1015,12 @@ private function convert_time_to_date( $time, $in_blog_timezone, $print_diff = f
}

if ( $print_diff && class_exists( '\Piwik\Metrics\Formatter' ) ) {
$formatter = new \Piwik\Metrics\Formatter();
$date .= ' (' . $formatter->getPrettyTimeFromSeconds( $time - time(), true, false ) . ')';
try {
$formatter = new \Piwik\Metrics\Formatter();
$date .= ' (' . $formatter->getPrettyTimeFromSeconds( $time - time(), true, false ) . ')';
} catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
// empty
}
}

return $date;
Expand Down Expand Up @@ -1013,19 +1062,16 @@ private function add_diagnostic_results( $rows, $results ) {
}

private function get_wordpress_info() {
$is_multi_site = is_multisite();
$num_blogs = 1;
$is_network_enabled = false;
$matomo_id_sites_number = 1;
$is_multi_site = is_multisite();
$num_blogs = 1;
$is_network_enabled = false;

if ( $is_multi_site ) {
if ( function_exists( 'get_blog_count' ) ) {
$num_blogs = get_blog_count();
}
$settings = new Settings();
$is_network_enabled = $settings->is_network_enabled();
} else {
$sites_manager_model = new Model();
$matomo_id_sites_number = count( $sites_manager_model->getSitesId() );
}

$rows = [];
Expand Down Expand Up @@ -1389,7 +1435,12 @@ private function get_browser_info() {
}
}
} catch ( Exception $e ) {
$this->logger->log( $e->getMessage() );
$rows[] = [
'name' => 'Browser Compatibility',
'is_error' => true,
'value' => 'Failed to use Device Detector.',
'comment' => $e->getMessage(),
];
}

$rows[] = [
Expand Down

0 comments on commit c6b7308

Please sign in to comment.