• I had an issue related to https://www.ads-software.com/support/topic/archive-process-cant-work/ ; reports had not been archived for months.

    When using the “Archive reports” button, the same errors as reported in the post linked above occurred, so I added the following snippet to wp-config.php as advised:

    
    if ( ! defined( 'MATOMO_SUPPORT_ASYNC_ARCHIVING' ) ) {
        define( 'MATOMO_SUPPORT_ASYNC_ARCHIVING', false );
    }
    

    At this point, instead of errors, the browser is outputting what seems to be raw HTML when using the “Archive reports” button (which reloads the page at https://sub.domain.tld/wp-admin/admin.php?page=matomo-systemreport&tab=troubleshooting).
    Looking into the response headers in the browser’s network inspector gave me a clue:

    
    Content-Type: application/json; charset=utf-8
    

    It seems that https://sub.domain.tld/wp-admin/admin.php?page=matomo-systemreport&tab=troubleshooting is reloaded as JSON after executing the operations behind the “Archive reports” button.

    I looked for application/json in the code base, and added the following at the start of Json::sendHeaderJSON() to get more information:

    
    $e = new \Exception;
    print_r( $e->getTraceAsString() );
    

    Sure enough, I could find the output of this code in the raw HTML, confirming Json::sendHeaderJSON() is called when using the “Archive reports” button.

    Changing application/json to text/html as a confirmation test in Json::sendHeaderJSON() results in the page being displayed correctly. It seems this method should not be called when using the “Archive reports” button, or at least that the output should be built differently.

    Resulting stack trace:

    
    #0 wp-content/plugins/matomo/app/plugins/API/Renderer/Json.php(80): Piwik\DataTable\Renderer\Json::sendHeaderJSON()
    #1 wp-content/plugins/matomo/app/core/API/ResponseBuilder.php(242): Piwik\Plugins\API\Renderer\Json->sendHeader()
    #2 wp-content/plugins/matomo/app/core/API/ResponseBuilder.php(89): Piwik\API\ResponseBuilder->sendHeaderIfEnabled()
    #3 wp-content/plugins/matomo/app/core/API/Request.php(272): Piwik\API\ResponseBuilder->getResponse()
    #4 wp-content/plugins/matomo/app/core/Context.php(28): Piwik\API\Request->Piwik\API\{closure}()
    #5 wp-content/plugins/matomo/app/core/API/Request.php(273): Piwik\Context::executeWithQueryParameters()
    #6 wp-content/plugins/matomo/plugins/WordPress/WordPress.php(236): Piwik\API\Request->process()
    #7 wp-content/plugins/matomo/app/core/Access.php(661): Piwik\Plugins\WordPress\WordPress->Piwik\Plugins\WordPress\{closure}()
    #8 wp-content/plugins/matomo/plugins/WordPress/WordPress.php(238): Piwik\Access::doAsSuperUser()
    #9 [internal function]: Piwik\Plugins\WordPress\WordPress->onSendHttpRequestBy()
    #10 wp-content/plugins/matomo/app/core/EventDispatcher.php(141): call_user_func_array()
    #11 wp-content/plugins/matomo/app/core/Piwik.php(845): Piwik\EventDispatcher->postEvent()
    #12 wp-content/plugins/matomo/app/core/Http.php(318): Piwik\Piwik::postEvent()
    #13 wp-content/plugins/matomo/app/core/CliMulti.php(412): Piwik\Http::sendHttpRequestBy()
    #14 wp-content/plugins/matomo/app/core/CliMulti.php(189): Piwik\CliMulti->executeNotAsyncHttp()
    #15 wp-content/plugins/matomo/app/core/CliMulti.php(172): Piwik\CliMulti->executeUrlCommand()
    #16 wp-content/plugins/matomo/app/core/CliMulti.php(448): Piwik\CliMulti->start()
    #17 wp-content/plugins/matomo/app/core/CliMulti.php(117): Piwik\CliMulti->requestUrls()
    #18 wp-content/plugins/matomo/app/core/CronArchive.php(468): Piwik\CliMulti->request()
    #19 wp-content/plugins/matomo/app/core/CronArchive.php(390): Piwik\CronArchive->launchArchivingFor()
    #20 wp-content/plugins/matomo/app/core/CronArchive.php(263): Piwik\CronArchive->run()
    #21 wp-content/plugins/matomo/app/core/Access.php(661): Piwik\CronArchive->Piwik\{closure}()
    #22 wp-content/plugins/matomo/app/core/CronArchive.php(269): Piwik\Access::doAsSuperUser()
    #23 wp-content/plugins/matomo/classes/WpMatomo/ScheduledTasks.php(332): Piwik\CronArchive->main()
    #24 wp-content/plugins/matomo/classes/WpMatomo/Admin/SystemReport.php(157): WpMatomo\ScheduledTasks->archive()
    #25 wp-content/plugins/matomo/classes/WpMatomo/Admin/SystemReport.php(222): WpMatomo\Admin\SystemReport->execute_troubleshoot_if_needed()
    #26 wp-includes/class-wp-hook.php(307): WpMatomo\Admin\SystemReport->show()
    #27 wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
    #28 wp-includes/plugin.php(476): WP_Hook->do_action()
    #29 wp-admin/admin.php(259): do_action()
    #30 {main}
    

    The same raw output issue occurs without MATOMO_SUPPORT_ASYNC_ARCHIVING being defined when WP_DEBUG is defined.
    If none of them is defined, the faulty behavior reported in https://www.ads-software.com/support/topic/archive-process-cant-work/ occurs.

    Please advise.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello @frogerme

    Can you post your system report? It’s available from the menu Matomo Analytics > Diagnostics.

    You should also have in the HTML content you get an error message which explain why this error occurs. Can you share this HTML with us?

    Kind regards

    Mat

    Thread Starter Alexandre Froger

    (@frogerme)

    Hi,

    Here is the system report:

    # Matomo
    
    * Matomo Plugin Version: 4.11.0
    * Config exists and is writable.: Yes ("$abs_path/wp-content/uploads/matomo/config/config.ini.php" )
    * JS Tracker exists and is writable.: Yes ("$abs_path/wp-content/uploads/matomo/matomo.js" )
    * Plugin directories: Yes ([{"pluginsPathAbsolute":"$abs_path\/wp-content\/plugins\/matomo\/plugins","webrootDirRelativeToMatomo":"..\/"}])
    * Tmp directory writable: Yes ($abs_path/wp-content/cache/matomo)
    * Matomo Version: 4.11.0
    * Matomo Blog idSite: 1
    * Matomo Install Version: 4.5.0 (Install date: 2021-12-05 00:22:18)
    * Upgrades outstanding: No
    * Upgrade in progress: No
    
    ## Endpoints
    
    * Matomo JavaScript Tracker URL:  ($site_url/wp-content/uploads/matomo/matomo.js)
    * Matomo JavaScript Tracker - WP Rest API:  ($site_url/wp-json/matomo/v1/hit/)
    * Matomo HTTP Tracking API:  ($site_url/wp-content/plugins/matomo/app/matomo.php)
    * Matomo HTTP Tracking API - WP Rest API:  ($site_url/wp-json/matomo/v1/hit/)
    
    ## Crons
    
    * Server time: 2022-08-15 23:36:04
    * Blog time: 2022-08-16 07:36:04 (Below dates are shown in blog timezone)
    * Sync users & sites: Next run: 2022-08-17 00:24:43 (16 hours 48 min) ( Last started: 2022-08-16 00:25:02 (-7 hours 11 min). Last ended: 2022-08-16 00:25:03 (-7 hours 11 min). Interval: daily)
    * Archive: Next run: 2022-08-16 08:31:52 (55 min 48s) ( Last started: 2022-08-16 07:32:02 (-4 min 2s). Last ended: 2022-08-16 07:32:02 (-4 min 2s). Interval: hourly)
    * Update GeoIP DB: Next run: 2022-09-01 00:23:06 (15 days 16 hours) ( Last started: 2022-08-02 00:24:02 (-14 days 7 hours). Last ended: 2022-08-02 00:24:12 (-14 days 7 hours). Interval: matomo_monthly)
    
    ## Mandatory checks
    
    * PHP version >= : ok 
    * PDO extension: ok 
    * PDO\MYSQL extension: ok 
    * MYSQLI extension: ok 
    * Other required extensions: ok 
    * Required functions: ok 
    * Required PHP configuration (php.ini): ok 
    * Directories with write access: ok 
    * Directories with write access for Tag Manager: ok 
    
    ## Optional checks
    
    * 64-bit PHP Binary: ok 
    * Tracker status: ok 
    * Memory limit: ok 
    * Time zone: ok 
    * Open URL: ok 
    * PageSpeed is turned off: ok 
    * GD > 2.x + FreeType (graphics): ok 
    * Other extensions: ok 
    * Other functions: ok 
    * Filesystem: ok 
    * Last Successful Archiving Completion: ok 
    * Database abilities: ok 
    * Max Packet Size: ok 
    * Geolocation: ok 
    * Update over HTTPS: ok 
    * Supports Async Archiving: No
    * Location provider ID: geoip2php
    * Location provider available: Yes
    * Location provider working: Yes
    * Had visit in last 5 days: Yes
    * Matomo URL: Yes ($site_url/wp-content/plugins/matomo/app)
    
    ## Matomo Settings
    
    * Track mode: tagmanager
    * Track codeposition: footer
    * Track api endpoint: default
    * Track js endpoint: default
    * Version history: 4.11.0, 4.10.0, 4.6.0, 4.5.0
    * Core version: 4.11.0
    * Last tracking settings update: 1639439720
    * Last settings update: 1639439720
    * Show get started page: 0
    * Track user id: uid
    * Mail history: 2022-08-15 22:32:03, 2022-08-15 00:32:06, 2022-08-08 22:23:46
    
    ## Logs
    
    * None: 
    
    # WordPress
    
    * Home URL: $site_url
    * Site URL: $site_url
    * WordPress Version: 6.0.1
    * Number of blogs: 1
    * Multisite Enabled: No
    * Network Enabled: No
    * WP_DEBUG: No
    * WP_DEBUG_DISPLAY: Yes
    * WP_DEBUG_LOG: No
    * DISABLE_WP_CRON: Yes
    * FORCE_SSL_ADMIN: Yes
    * WP_CACHE: No
    * CONCATENATE_SCRIPTS: -
    * COMPRESS_SCRIPTS: -
    * COMPRESS_CSS: -
    * ENFORCE_GZIP: -
    * WP_LOCAL_DEV: -
    * WP_CONTENT_URL: $site_url/wp-content
    * WP_CONTENT_DIR: $abs_path/wp-content
    * UPLOADS: -
    * BLOGUPLOADDIR: -
    * DIEONDBERROR: -
    * WPLANG: -
    * ALTERNATE_WP_CRON: -
    * WP_CRON_LOCK_TIMEOUT: 60
    * WP_DISABLE_FATAL_ERROR_HANDLER: -
    * MATOMO_SUPPORT_ASYNC_ARCHIVING: No
    * MATOMO_TRIGGER_BROWSER_ARCHIVING: -
    * MATOMO_ENABLE_TAG_MANAGER: -
    * MATOMO_SUPPRESS_DB_ERRORS: -
    * MATOMO_ENABLE_AUTO_UPGRADE: -
    * MATOMO_DEBUG: -
    * MATOMO_SAFE_MODE: -
    * MATOMO_GLOBAL_UPLOAD_DIR: -
    * MATOMO_LOGIN_REDIRECT: -
    * Permalink Structure: /%postname%/
    * Possibly uses symlink: No
    * Upload base url: $site_url/wp-content/uploads
    * Upload base dir: $abs_path/wp-content/uploads
    * Upload url: $site_url/wp-content/uploads/2022/08
    * Custom upload_path: 
    * Custom upload_url_path: 
    * Compatible content directory: Yes
    
    # WordPress Plugins
    
    ## MU Plugins
    
    * Health Check Troubleshooting Mode: 1.7.2
    
    ## Plugins
    
    * Matomo Analytics - Ethical Stats. Powerful Insights.: 4.11.0
    * WooCommerce: 6.8.0
    * Active Plugins: 2 (matomo woocommerce)
    * Theme: storefront (mobilestore)
    
    # Server
    
    * Server Info: Apache
    * PHP OS: Linux
    * PHP Version: 7.4.30
    * PHP SAPI: fpm-fcgi
    * PHP Binary Name: php-fpm7.4
    * PHP Error Reporting: 0 After bootstrap: 0
    * PHP Found Binary: php -q
    * Timezone: UTC
    * WP timezone: Asia/Shanghai
    * Locale: en_US
    * User Locale: en_US
    * Memory Limit: 4096M (At least 128MB recommended. Depending on your traffic 256MB or more may be needed.)
    * WP Memory Limit: 4096M
    * WP Max Memory Limit: 4096M
    * Timezone version: 0.system
    * Time: 1660606564
    * Max Execution Time: 300
    * Max Post Size: 1024M
    * Max Upload Size: 1073741824
    * Max Input Vars: 1000
    * Disabled PHP functions: Yes (pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,)
    * zlib.output_compression is off: Yes
    * Curl Version: 7.58.0, OpenSSL/1.1.1
    * Suhosin installed: No
    
    # Database
    
    * MySQL Version: 5.7.39
    * Mysqli Connect: Yes
    * Force MySQL over Mysqli: No
    * DB Prefix: wp_
    * DB CHARSET: utf8mb4
    * DB COLLATE: 
    * SHOW ERRORS: No
    * SUPPRESS ERRORS: No
    * Uses Socket: No
    * Uses IPv6: No
    * Matomo tables found: 131
    * DB tables exist: Yes
    * Matomo users found: 2
    * Matomo sites found: 1
    * Required permissions: OK
    
    # Browser
    
    * Browser:  (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36)
    * Language:

    You should also have in the HTML content you get an error message which explain why this error occurs. Can you share this HTML with us?

    When WP_DEBUG or MATOMO_SUPPORT_ASYNC_ARCHIVING is defined, in the HTML output as JSON, there is no error output on screen whatsoever, and the page is loaded with the wrong mime type.

    I also found out this mime type error seems to be related to WooCommerce ; if WP_DEBUG or MATOMO_SUPPORT_ASYNC_ARCHIVING is defined and Woocomerce is deactivated, Json::sendHeaderJSON() is still called (exact same stack trace), but the page is loaded as text/html as intended.
    However, if WP_DEBUG or MATOMO_SUPPORT_ASYNC_ARCHIVING is not defined and Woocomerce is deactivated, I get the following:

    Matomo Archive Warnings: 'Got invalid response from API request: ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=week&date=2022-08-15&format=json&trigger=archivephp. Response was \'<!DOCTYPE html>
    <html lang="en-US">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width">
    <meta name=\'robots\' content=\'max-image-preview:large, noindex, follow\' />
    <title>WordPress ? Error</title>
    <style type="text/css">
    html {
    background: #f1f1f1;
    }
    body {
    background: #fff;
    border: 1px solid #ccd0d4;
    color: #444;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin: 2em auto;
    padding: 1em 2em;
    max-width: 700px;
    -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
    box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
    }
    h1 {
    border-bottom: 1px solid #dadada;
    clear: both;
    color: #666;
    font-size: 24px;
    margin: 30px 0 0 0;
    padding: 0;
    padding-bottom: 7px;
    }
    #error-page {
    margin-top: 50px;
    }
    #error-page p,
    #error-page .wp-die-message {
    font-size: 14px;
    line-height: 1.5;
    margin: 25px 0 20px;
    }
    #error-page code {
    font-family: Consolas, Monaco, monospace;
    }
    ul li {
    margin-bottom: 10px;
    font-size: 14px ;
    }
    a {
    color: #0073aa;
    }
    a:hover,
    a:active {
    color: #006799;
    }
    a:focus {
    color: #124964;
    -webkit-box-shadow:
    0 0 0 1px #5b9dd9,
    0 0 2px 1px rgba(30, 140, 190, 0.8);
    box-shadow:
    0 0 0 1px #5b9dd9,
    0 0 2px 1px rgba(30, 140, 190, 0.8);
    outline: none;
    }
    .button {
    background: #f3f5f6;
    border: 1px solid #016087;
    color: #016087;
    display: inline-block;
    text-decoration: none;
    font-size: 13px;
    line-height: 2;
    height: 28px;
    margin: 0;
    padding: 0 10px 1px;
    cursor: pointer;
    -webkit-border-radius: 3px;
    -webkit-appearance: none;
    border-radius: 3px;
    white-space: nowrap;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    
    vertical-align: top;
    }
    
    .button.button-large {
    line-height: 2.30769231;
    min-height: 32px;
    padding: 0 12px;
    }
    
    .button:hover,
    .button:focus {
    background: #f1f1f1;
    }
    
    .button:focus {
    background: #f3f5f6;
    border-color: #007cba;
    -webkit-box-shadow: 0 0 0 1px #007cba;
    box-shadow: 0 0 0 1px #007cba;
    color: #016087;
    outline: 2px solid transparent;
    outline-offset: 0;
    }
    
    .button:active {
    background: #f3f5f6;
    border-color: #7e8993;
    -webkit-box-shadow: none;
    box-shadow: none;
    }
    
    </style>
    </head>
    <body id="error-page">
    <div class="wp-die-message"><h2>Missing plugins</h2><p>Some required plugins are not activated. If the problem persists, please contact an administrator.</p></div></body>
    </html>\''
    'Error unserializing the following response from ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=week&date=2022-08-15&format=json&trigger=archivephp: \'<!DOCTYPE html>
    <html lang="en-US">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width">
    <meta name=\'robots\' content=\'max-image-preview:large, noindex, follow\' />
    <title>WordPress ? Error</title>
    <style type="text/css">
    html {
    background: #f1f1f1;
    }
    body {
    background: #fff;
    border: 1px solid #ccd0d4;
    color: #444;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin: 2em auto;
    padding: 1em 2em;
    max-width: 700px;
    -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
    box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
    }
    h1 {
    border-bottom: 1px solid #dadada;
    clear: both;
    color: #666;
    font-size: 24px;
    margin: 30px 0 0 0;
    padding: 0;
    padding-bottom: 7px;
    }
    #error-page {
    margin-top: 50px;
    }
    #error-page p,
    #error-page .wp-die-message {
    font-size: 14px;
    line-height: 1.5;
    margin: 25px 0 20px;
    }
    #error-page code {
    font-family: Consolas, Monaco, monospace;
    }
    ul li {
    margin-bottom: 10px;
    font-size: 14px ;
    }
    a {
    color: #0073aa;
    }
    a:hover,
    a:active {
    color: #006799;
    }
    a:focus {
    color: #124964;
    -webkit-box-shadow:
    0 0 0 1px #5b9dd9,
    0 0 2px 1px rgba(30, 140, 190, 0.8);
    box-shadow:
    0 0 0 1px #5b9dd9,
    0 0 2px 1px rgba(30, 140, 190, 0.8);
    outline: none;
    }
    .button {
    background: #f3f5f6;
    border: 1px solid #016087;
    color: #016087;
    display: inline-block;
    text-decoration: none;
    font-size: 13px;
    line-height: 2;
    height: 28px;
    margin: 0;
    padding: 0 10px 1px;
    cursor: pointer;
    -webkit-border-radius: 3px;
    -webkit-appearance: none;
    border-radius: 3px;
    white-space: nowrap;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    
    vertical-align: top;
    }
    
    .button.button-large {
    line-height: 2.30769231;
    min-height: 32px;
    padding: 0 12px;
    }
    
    .button:hover,
    .button:focus {
    background: #f1f1f1;
    }
    
    .button:focus {
    background: #f3f5f6;
    border-color: #007cba;
    -webkit-box-shadow: 0 0 0 1px #007cba;
    box-shadow: 0 0 0 1px #007cba;
    color: #016087;
    outline: 2px solid transparent;
    outline-offset: 0;
    }
    
    .button:active {
    background: #f3f5f6;
    border-color: #7e8993;
    -webkit-box-shadow: none;
    box-shadow: none;
    }
    
    </style>
    </head>
    <body id="error-page">
    <div class="wp-die-message"><h2>Missing plugins</h2><p>Some required plugins are not activated. If the problem persists, please contact an administrator.</p></div></body>
    </html>\''
    'Got invalid response from API request: ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=year&date=2022-01-01&format=json&trigger=archivephp. Response was \'<!DOCTYPE html>
    <html lang="en-US">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width">
    <meta name=\'robots\' content=\'max-image-preview:large, noindex, follow\' />
    <title>WordPress ? Error</title>
    <style type="text/css">
    html {
    background: #f1f1f1;
    }
    body {
    background: #fff;
    border: 1px solid #ccd0d4;
    color: #444;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin: 2em auto;
    padding: 1em 2em;
    max-width: 700px;
    -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
    box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
    }
    h1 {
    border-bottom: 1px solid #dadada;
    clear: both;
    color: #666;
    font-size: 24px;
    margin: 30px 0 0 0;
    padding: 0;
    padding-bottom: 7px;
    }
    #error-page {
    margin-top: 50px;
    }
    #error-page p,
    #error-page .wp-die-message {
    font-size: 14px;
    line-height: 1.5;
    margin: 25px 0 20px;
    }
    #error-page code {
    font-family: Consolas, Monaco, monospace;
    }
    ul li {
    margin-bottom: 10px;
    font-size: 14px ;
    }
    a {
    color: #0073aa;
    }
    a:hover,
    a:active {
    color: #006799;
    }
    a:focus {
    color: #124964;
    -webkit-box-shadow:
    0 0 0 1px #5b9dd9,
    0 0 2px 1px rgba(30, 140, 190, 0.8);
    box-shadow:
    0 0 0 1px #5b9dd9,
    0 0 2px 1px rgba(30, 140, 190, 0.8);
    outline: none;
    }
    .button {
    background: #f3f5f6;
    border: 1px solid #016087;
    color: #016087;
    display: inline-block;
    text-decoration: none;
    font-size: 13px;
    line-height: 2;
    height: 28px;
    margin: 0;
    padding: 0 10px 1px;
    cursor: pointer;
    -webkit-border-radius: 3px;
    -webkit-appearance: none;
    border-radius: 3px;
    white-space: nowrap;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    
    vertical-align: top;
    }
    
    .button.button-large {
    line-height: 2.30769231;
    min-height: 32px;
    padding: 0 12px;
    }
    
    .button:hover,
    .button:focus {
    background: #f1f1f1;
    }
    
    .button:focus {
    background: #f3f5f6;
    border-color: #007cba;
    -webkit-box-shadow: 0 0 0 1px #007cba;
    box-shadow: 0 0 0 1px #007cba;
    color: #016087;
    outline: 2px solid transparent;
    outline-offset: 0;
    }
    
    .button:active {
    background: #f3f5f6;
    border-color: #7e8993;
    -webkit-box-shadow: none;
    box-shadow: none;
    }
    
    </style>
    </head>
    <body id="error-page">
    <div class="wp-die-message"><h2>Missing plugins</h2><p>Some required plugins are not activated. If the problem persists, please contact an administrator.</p></div></body>
    </html>\''
    'Error unserializing the following response from ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=year&date=2022-01-01&format=json&trigger=archivephp: \'<!DOCTYPE html>
    <html lang="en-US">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width">
    <meta name=\'robots\' content=\'max-image-preview:large, noindex, follow\' />
    <title>WordPress ? Error</title>
    <style type="text/css">
    html {
    background: #f1f1f1;
    }
    body {
    background: #fff;
    border: 1px solid #ccd0d4;
    color: #444;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    margin: 2em auto;
    padding: 1em 2em;
    max-width: 700px;
    -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
    box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
    }
    h1 {
    border-bottom: 1px solid #dadada;
    clear: both;
    color: #666;
    font-size: 24px;
    margin: 30px 0 0 0;
    padding: 0;
    padding-bottom: 7px;
    }
    #error-page {
    margin-top: 50px;
    }
    #error-page p,
    #error-page .wp-die-message {
    font-size: 14px;
    line-height: 1.5;
    margin: 25px 0 20px;
    }
    #error-page code {
    font-family: Consolas, Monaco, monospace;
    }
    ul li {
    margin-bottom: 10px;
    font-size: 14px ;
    }
    a {
    color: #0073aa;
    }
    a:hover,
    a:active {
    color: #006799;
    }
    a:focus {
    color: #124964;
    -webkit-box-shadow:
    0 0 0 1px #5b9dd9,
    0 0 2px 1px rgba(30, 140, 190, 0.8);
    box-shadow:
    0 0 0 1px #5b9dd9,
    0 0 2px 1px rgba(30, 140, 190, 0.8);
    outline: none;
    }
    .button {
    background: #f3f5f6;
    border: 1px solid #016087;
    color: #016087;
    display: inline-block;
    text-decoration: none;
    font-size: 13px;
    line-height: 2;
    height: 28px;
    margin: 0;
    padding: 0 10px 1px;
    cursor: pointer;
    -webkit-border-radius: 3px;
    -webkit-appearance: none;
    border-radius: 3px;
    white-space: nowrap;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    
    vertical-align: top;
    }
    
    .button.button-large {
    line-height: 2.30769231;
    min-height: 32px;
    padding: 0 12px;
    }
    
    .button:hover,
    .button:focus {
    background: #f1f1f1;
    }
    
    .button:focus {
    background: #f3f5f6;
    border-color: #007cba;
    -webkit-box-shadow: 0 0 0 1px #007cba;
    box-shadow: 0 0 0 1px #007cba;
    color: #016087;
    outline: 2px solid transparent;
    outline-offset: 0;
    }
    
    .button:active {
    background: #f3f5f6;
    border-color: #7e8993;
    -webkit-box-shadow: none;
    box-shadow: none;
    }
    
    </style>
    </head>
    <body id="error-page">
    <div class="wp-die-message"><h2>Missing plugins</h2><p>Some required plugins are not activated. If the problem persists, please contact an administrator.</p></div></body>
    </html>\''
    '4 total errors during this script execution, please investigate and try and fix these errors.'
    '4 total errors during this script execution, please investigate and try and fix these errors.'

    With these lines being the relevant bit, preventing me from troubleshooting further:

    
    <h2>Missing plugins</h2><p>Some required plugins are not activated. If the problem persists, please contact an administrator.</p>
    
    Thread Starter Alexandre Froger

    (@frogerme)

    More research, and a possible clue for a way to fix the issue.

    When WP_DEBUG is active, clicking the “Archive reports” button sets supportsAsync to false in Piwik\Plugins\WordPress\WordPress::supportsAsync().

    This down the execution stack triggers Piwik\Plugins\WordPress\WordPress::onSendHttpRequestBy(), and specifically this block:

    
            if ((strpos($url, 'module=API&method=API.get') !== false
                 && strpos($url, '&trigger=archivephp') !== false
                 && Url::isValidHost(parse_url($url, PHP_URL_HOST)))
                ||
                (strpos($url, 'module=API&method=CoreAdminHome.archiveReports') !== false
                 && strpos($url, '&trigger=archivephp') !== false
                 && Url::isValidHost(parse_url($url, PHP_URL_HOST)))
            ) {
                // archiving query... we avoid issueing an http request for many reasons...
                // eg user might be using self signed certificate and request fails
                // eg http requests may not be allowed
                // eg because the WP user wouldn't be logged in the auth wouldn't work
                // etc.
    
                \Piwik\Access::doAsSuperUser(function () use ($url, &$response) {
                	WordPress::$is_archiving = true;
                	// refs #118 because there is no actual user when archiving there is also no token etc
                    $urlQuery = parse_url($url, PHP_URL_QUERY);
                    $request = new Request($urlQuery, array('serialize' => 1));
                    $response = $request->process();
    	            WordPress::$is_archiving = false;
                });
                $status = 200;
                return;
            }
    

    The notable part is this:

    
    $urlQuery = parse_url($url, PHP_URL_QUERY);
    $request = new Request($urlQuery, array('serialize' => 1));
    $response = $request->process();
    

    In my case, the $urlQuery value is:

    
    module=API&method=CoreAdminHome.archiveReports&idSite=1&period=month&date=2022-08-01&format=json&trigger=archivephp&
    

    Note the presence of format=json ; this is assigned to a Piwik\API\Request object, then used in the Piwik\API\Request::process() method, which first uses the $urlQuery value to set the output format, and then instantiates a Piwik\API\ResponseBuilder object. The Piwik\API\ResponseBuilder::getResponse() method is then called, and it contains:

    
    $this->sendHeaderIfEnabled();
    

    This is where the JSON output come from.

    A way to avoid that (and here, I am unsure of the side effects it may cause, because I am unaware of all the cases in which this block is executed) would be to use format=original in $urlQuery, and use wp_json_encode() on the $response variable to bypass sending the content type headers.

    Here is an example of rewrite for the block mentioned above in Piwik\Plugins\WordPress\WordPress::onSendHttpRequestBy (see my added comments in all caps):

    
    if ((strpos($url, 'module=API&method=API.get') !== false
         && strpos($url, '&trigger=archivephp') !== false
         && Url::isValidHost(parse_url($url, PHP_URL_HOST)))
        ||
        (strpos($url, 'module=API&method=CoreAdminHome.archiveReports') !== false
         && strpos($url, '&trigger=archivephp') !== false
         && Url::isValidHost(parse_url($url, PHP_URL_HOST)))
    ) {
        // archiving query... we avoid issueing an http request for many reasons...
        // eg user might be using self signed certificate and request fails
        // eg http requests may not be allowed
        // eg because the WP user wouldn't be logged in the auth wouldn't work
        // etc.
    
        \Piwik\Access::doAsSuperUser(function () use ($url, &$response) {
        	WordPress::$is_archiving = true;
        	// refs #118 because there is no actual user when archiving there is also no token etc
            /** FORCING THE FORMAT TO ORIGINAL TO AVOID SENDING HEADERS **/
            $urlQuery = str_replace( 'format=json', 'format=original', parse_url($url, PHP_URL_QUERY) );
            $request = new Request($urlQuery);
            /** APPLYING ORIGINALLY INTENDED JSON FORMAT ON THE RESPONSE **/
            $response = wp_json_encode( $request->process() );
            WordPress::$is_archiving = false;
        });
        $status = 200;
        return;
    }
    

    Hello @frogerme

    Thank you for your research. We’ll study it.

    I guess that your normal configuration when you try to archive your blog data is without the constants defined and with woocommerce enabled, right?
    Do you have an error in this case when running manually the archiving process? I can’t see this case in your explanation.

    Kind regards

    Mat

    Thread Starter Alexandre Froger

    (@frogerme)

    I guess that your normal configuration when you try to archive your blog data is without the constants defined and with woocommerce enabled, right?

    If you mean in production environment, then that’s right: WP_DEBUG and MATOMO_SUPPORT_ASYNC_ARCHIVING are set to false.
    I briefly had to use MATOMO_SUPPORT_ASYNC_ARCHIVING in production at some point due to incompatibility with a third party (a plugin – legitimately – doing a wp_safe_redirect in an init action ; thankfully they did provide a filter for me to work around matomo and awkwardly check the value of $GLOBALS['matomo_is_archive_request'], but it’s something I’ll probably raise as a separate issue).
    At this stage, these constants are not defined in production ; it does not make it much less of an issue though because the staging environment we extensively use does use these constants.

    Do you have an error in this case when running manually the archiving process? I can’t see this case in your explanation.

    There is no such issue in production environment at this stage. Only with WP_DEBUG or MATOMO_SUPPORT_ASYNC_ARCHIVING in staging, both of which having the same influence on Piwik\Plugins\WordPress\WordPress::supportsAsync().

    Hello @frogerme

    I’ve created this issue.
    https://github.com/matomo-org/matomo-for-wordpress/issues/641

    From my understanding you don’t have anymore an archiving error, only this output error when running the archiving process manually.
    Do you still need further assistance or I can close this issue?

    Kind regards

    Mat

    Hello @frogerme

    Without any answer, I close this issue.
    Feel free to subscribe to the GitHub to get notification on its resolution.
    Kind regards

    Mat

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Diagnostics: Archive reports outputs as application/json’ is closed to new replies.