matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.87k stars 2.65k forks source link

/misc/cron/archive.php ignoring PIWIK_USER_PATH set in /bootstrap.php #20327

Open Cangoo opened 1 year ago

Cangoo commented 1 year ago

I use to define my own PIWIK_USER_PATH in /bootstrap.php to alter the path of the config.ini.php-file. But when calling /misc/cron/archive.php PIWIK_USER_PATH is already set BEFORE /bootstrap.php is called.

Expected Behavior

/bootstrap.php should be called before PIWIK_USER_PATH is set in /misc/cron/archive.php

Current Behavior

/bootstrap.php is called AFTER PIWIK_USER_PATH is already set in /misc/cron/archive.php

Possible Solution

/misc/cron/archive.php

if (!defined('PIWIK_DOCUMENT_ROOT')) {
    define('PIWIK_DOCUMENT_ROOT', realpath(dirname(__FILE__) . "/../.."));
}

// Added
if (file_exists(PIWIK_DOCUMENT_ROOT . '/bootstrap.php')) {
    require_once PIWIK_DOCUMENT_ROOT . '/bootstrap.php';
}
// /Added

if (!defined('PIWIK_INCLUDE_PATH')) {
    define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT);
}

if (!defined('PIWIK_USER_PATH')) {
    define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH);
}

Steps to Reproduce (for Bugs)

Create a /bootstrap.php-file with this content: define('PIWIK_USER_PATH', $_SERVER['DOCUMENT_ROOT'].'/my-new-path-to-matomo-config/');

Move config.ini.php to $_SERVER['DOCUMENT_ROOT'].'/my-new-path-to-matomo-config/'

call /misc/cron/archive.php

=> Warning: Constant PIWIK_USER_PATH already defined in ...\matomo\bootstrap.php on line 1 => cron-job is not working, instead the installation-page is shown

Context

I'm moving the config-file to another location, because I want to use matomo on different servers and don't want to override the config.ini.php on updates.

sgiehl commented 1 year ago

Hi @Cangoo. Thanks for this report. It seems the archive.php current does not even try to include a custom bootstrap file.

@tsteur Do you know any reason why we don't include a custom bootstrap file there?

MatomoForumNotifications commented 1 year ago

This issue has been mentioned on Matomo forums. There might be relevant details there:

https://forum.matomo.org/t/web-cron-your-browser-was-unable-to-load-the-scripts-of-this-page/49619/3