Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow disabling async archiving via advanced setting #896

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions classes/WpMatomo/Admin/AdvancedSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace WpMatomo\Admin;

use Piwik\CliMulti\Process;
use Piwik\IP;
use WpMatomo\Bootstrap;
use WpMatomo\Capabilities;
Expand Down Expand Up @@ -68,8 +69,10 @@ public function show_settings() {
}

Bootstrap::do_bootstrap();
$matomo_detected_ip = IP::getIpFromHeader();
$matomo_delete_all_data = $this->settings->should_delete_all_data_on_uninstall();
$matomo_detected_ip = IP::getIpFromHeader();
$matomo_delete_all_data = $this->settings->should_delete_all_data_on_uninstall();
$matomo_disable_async_archiving = $this->settings->is_async_archiving_disabled_by_option();
$matomo_async_archiving_supported = $this->settings->is_async_archiving_supported();

include dirname( __FILE__ ) . '/views/advanced_settings.php';
}
Expand All @@ -93,14 +96,16 @@ public function can_user_manage() {
}

private function apply_settings() {
$changes = [
Settings::DISABLE_ASYNC_ARCHIVING_OPTION_NAME => ! empty( $_POST['matomo']['disable_async_archiving'] ),
];

if ( ! defined( 'MATOMO_REMOVE_ALL_DATA' ) ) {
$this->settings->apply_changes(
[
Settings::DELETE_ALL_DATA_ON_UNINSTALL => ! empty( $_POST['matomo']['delete_all_data'] ),
]
);
$changes[ Settings::DELETE_ALL_DATA_ON_UNINSTALL ] = ! empty( $_POST['matomo']['delete_all_data'] );
}

$this->settings->apply_changes( $changes );

$client_headers = [];
if ( ! empty( $_POST[ self::FORM_NAME ]['proxy_client_header'] ) ) {
$client_header = sanitize_text_field( wp_unslash( $_POST[ self::FORM_NAME ]['proxy_client_header'] ) );
Expand Down
7 changes: 6 additions & 1 deletion classes/WpMatomo/Admin/SystemReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,12 @@ private function get_matomo_info() {
'comment' => '',
];

$rows[] = [
diosmosis marked this conversation as resolved.
Show resolved Hide resolved
'name' => 'Async Archiving Disabled in Setting',
'value' => $this->settings->is_async_archiving_disabled_by_option(),
'comment' => '',
];

$location_provider = LocationProvider::getCurrentProvider();
if ( $location_provider ) {
$rows[] = [
Expand Down Expand Up @@ -1069,7 +1075,6 @@ private function get_wordpress_info() {
'WP_CRON_LOCK_TIMEOUT',
'WP_DISABLE_FATAL_ERROR_HANDLER',
'MATOMO_SUPPORT_ASYNC_ARCHIVING',
'MATOMO_TRIGGER_BROWSER_ARCHIVING',
'MATOMO_ENABLE_TAG_MANAGER',
'MATOMO_SUPPRESS_DB_ERRORS',
'MATOMO_ENABLE_AUTO_UPGRADE',
Expand Down
19 changes: 19 additions & 0 deletions classes/WpMatomo/Admin/views/advanced_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@
</td>
</tr>
<?php } ?>
<tr>
<th width="20%" scope="row">
<label for="matomo[disable_async_archiving]"><?php esc_html_e( 'Enable archiving via HTTP requests', 'matomo' ); ?>:</label>
</th>
<td>
<span style="white-space:nowrap;display: inline-block;">
<input type="checkbox" <?php echo ! empty( $matomo_disable_async_archiving ) || empty( $matomo_async_archiving_supported ) ? 'checked="checked" ' : ''; ?> value="1" name="matomo[disable_async_archiving]"
id="matomo[disable_async_archiving]" <?php echo ! empty( $matomo_async_archiving_supported ) ? '' : 'disabled="disabled"'; ?>
/>
</span>
</td>
<td width="50%">
<?php
echo ! empty( $matomo_async_archiving_supported )
? esc_html_e( 'If you are experiencing trouble with archiving (as in, report generation), enabling this option may solve the issue.', 'matomo' )
: esc_html_e( 'CLI archiving (aka async archiving) is not supported for your server, so archiving via HTTP requests is always enabled.', 'matomo' );
?>
</td>
</tr>
<tr>
<td colspan="3"><p class="submit"><input name="Submit" type="submit" class="button-primary"
value="<?php esc_attr_e( 'Save Changes', 'matomo' ); ?>"/></p></td>
Expand Down
11 changes: 11 additions & 0 deletions classes/WpMatomo/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace WpMatomo;

use Piwik\CliMulti\Process;
use WpMatomo\Admin\CookieConsent;
use WpMatomo\Admin\TrackingSettings;

Expand All @@ -33,6 +34,7 @@ class Settings {
const DELETE_ALL_DATA_ON_UNINSTALL = 'delete_all_data_uninstall';
const SITE_CURRENCY = 'site_currency';
const NETWORK_CONFIG_OPTIONS = 'config_options';
const DISABLE_ASYNC_ARCHIVING_OPTION_NAME = 'matomo_disable_async_archiving';

public static $is_doing_action_tracking_related = false;
/**
Expand Down Expand Up @@ -107,6 +109,7 @@ class Settings {
'force_protocol' => 'disabled',
'maxmind_license_key' => '',
self::SHOW_GET_STARTED_PAGE => 1,
self::DISABLE_ASYNC_ARCHIVING_OPTION_NAME => false,
];

/**
Expand Down Expand Up @@ -486,4 +489,12 @@ public function track_search_enabled() {
public function set_assume_is_network_enabled_in_tests( $network_enabled = true ) {
$this->assume_is_network_enabled_in_tests = $network_enabled;
}

public function is_async_archiving_supported() {
return Process::isSupported() && ( ! defined( 'MATOMO_SUPPORT_ASYNC_ARCHIVING' ) || MATOMO_SUPPORT_ASYNC_ARCHIVING );
}

public function is_async_archiving_disabled_by_option() {
return (bool) $this->get_global_option( self::DISABLE_ASYNC_ARCHIVING_OPTION_NAME );
}
}
11 changes: 10 additions & 1 deletion plugins/WordPress/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Piwik\API\Request;
use Piwik\Common;
use Piwik\FrontController;
use Piwik\Option;
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugin\Manager;
Expand All @@ -21,6 +22,7 @@
use Piwik\Url;
use Piwik\Widget\WidgetsList;
use WpMatomo\Bootstrap;
use WpMatomo\Settings;

if (!defined( 'ABSPATH')) {
exit; // if accessed directly
Expand Down Expand Up @@ -158,7 +160,8 @@ public function supportsAsync(&$supportsAsync)
|| (defined('WP_DEBUG') && WP_DEBUG)
|| !empty($_SERVER['MATOMO_WP_ROOT_PATH'])
|| !matomo_has_compatible_content_dir()
|| (defined( 'MATOMO_SUPPORT_ASYNC_ARCHIVING') && !MATOMO_SUPPORT_ASYNC_ARCHIVING)
|| (defined( 'MATOMO_SUPPORT_ASYNC_ARCHIVING') && !MATOMO_SUPPORT_ASYNC_ARCHIVING)
|| $this->isAsyncArchivingDisabledBySetting()
) {
// console wouldn't really work in multi site mode... therefore we prefer to archive in the same request
// WP_DEBUG also breaks things since it's logging things to stdout and then safe unserialise doesn't work
Expand All @@ -168,6 +171,12 @@ public function supportsAsync(&$supportsAsync)
}
}

private function isAsyncArchivingDisabledBySetting()
{
$settings = \WpMatomo::$settings;
return $settings->is_async_archiving_disabled_by_option();
}

public function onHeader(&$out)
{
$out .= '<style type="text/css">#header_message {display:none !important; }</style>';
Expand Down