Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CronArchivingCheck.php « Diagnostic « Diagnostics « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad2520377cf5249368d1e4808280eaef5ff22a36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */
namespace Piwik\Plugins\Diagnostics\Diagnostic;

use Piwik\ArchiveProcessor\Rules;
use Piwik\CliMulti;
use Piwik\Config;
use Piwik\CronArchive;
use Piwik\Date;
use Piwik\Http;
use Piwik\Metrics\Formatter;
use Piwik\Option;
use Piwik\SettingsPiwik;
use Piwik\Translation\Translator;
use Piwik\Url;

/**
 * Check if cron archiving can run through CLI.
 */
class CronArchivingCheck implements Diagnostic
{
    /**
     * @var Translator
     */
    private $translator;

    public function __construct(Translator $translator)
    {
        $this->translator = $translator;
    }

    public function execute()
    {
        $label = $this->translator->translate('Installation_SystemCheckCronArchiveProcess') . ' (' .
            $this->translator->translate('Installation_FasterReportLoading') . ')';

        if (SettingsPiwik::isMatomoInstalled()) {
            $isBrowserTriggerEnabled = Rules::isBrowserTriggerEnabled();
            if ($isBrowserTriggerEnabled) {
                $comment = $this->translator->translate('Diagnostics_BrowserTriggeredArchivingEnabled', [
                    '<a href="https://matomo.org/docs/setup-auto-archiving/" target="_blank" rel="noreferrer noopener">', '</a>']);
                $result[] = DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment);

                $archiveLastStarted = Option::get(CronArchive::OPTION_ARCHIVING_STARTED_TS);
                $thirtySixHoursAgoInSeconds = 36 * 3600;
                if ($archiveLastStarted && $archiveLastStarted > (time() - $thirtySixHoursAgoInSeconds)) {
                    // auto archive was used recently... if they maybe only once ran core:archive then eventually it will correct
                    // itself and no longer show this
                    $formatter = new Formatter();
                    $lastStarted = $formatter->getPrettyTimeFromSeconds(time() - $archiveLastStarted, true);
                    $label = $this->translator->translate('Diagnostics_BrowserAndAutoArchivingEnabledLabel');
                    $comment = $this->translator->translate('Diagnostics_BrowserAndAutoArchivingEnabledComment', [
                        '<a href="https://matomo.org/docs/setup-auto-archiving/" target="_blank" rel="noreferrer noopener">', '</a>', $lastStarted]);
                    $result[] = DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment);
                }
            }
        }

        $comment = '';

        $process = new CliMulti();
        if ($process->supportsAsync()) {
            $comment .= $this->translator->translate('General_Ok');
            $status = DiagnosticResult::STATUS_OK;
        } else {
            $reasons = CliMulti\Process::isSupportedWithReason();
            if (empty($reasons)) {
                $reasonText = $this->translator->translate('General_Unknown');
            } else {
                $reasonText = implode(', ', $reasons);
            }
            $comment .= $this->translator->translate('Installation_NotSupported')
                . ' ' . $this->translator->translate('Goals_Optional')
                . ' (' . $this->translator->translate('General_Reasons') . ': ' . $reasonText . ')'
                . $this->translator->translate('General_LearnMore', [' <a target="_blank" href="https://matomo.org/faq/troubleshooting/how-to-make-the-diagnostic-managing-processes-via-cli-to-display-ok/">', '</a>']);
            $status = DiagnosticResult::STATUS_INFORMATIONAL;
        }

        $label = $this->translator->translate('Installation_SystemCheckCronArchiveProcess') . ' - '
            . $this->translator->translate('Installation_SystemCheckCronArchiveProcessCLI');
        $result[] = DiagnosticResult::singleResult($label, $status, $comment);

        return $result;
    }
}