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

LogFileList.php « LogImporter « AutoLogImporter « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: defb51145b3aad6eef1ba21dd53084f08a0f7a80 (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
<?php
/**
 * Copyright (C) Piwik PRO - All rights reserved.
 *
 * Using this code requires that you first get a license from Piwik PRO.
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 *
 * @link http://piwik.pro
 */

namespace Piwik\Plugins\AutoLogImporter\LogImporter;

use Piwik\Db;
use Piwik\Filesystem;
use Piwik\Plugins\AutoLogImporter\Settings;

class LogFileList
{
    /**
     * @var Settings
     */
    private $settings;

    /**
     * @var File
     */
    private $file;

    public function __construct(Settings $settings, File $file)
    {
        $this->settings = $settings;
        $this->file = $file;
    }

    /**
     * @return string[]
     */
    public function findLogFiles()
    {
        $path = $this->settings->logFilesPath->getValue();
        $pattern = $this->settings->filePattern->getValue();

        if (!$this->settings->enabled->getValue()) {
            return array();
        }

        if (empty($path) || !file_exists($path) || !is_readable($path) || !is_dir($path)) {
            // case when plugin not configured yet
            return array();
        }

        if (empty($pattern)) {
            $pattern = '*';
        }

        return Filesystem::globr($path, $pattern);
    }

    public function findFilesHavingWrongHashFile()
    {
        $files = $this->findLogFiles();

        $wrong = array();
        foreach ($files as $file) {
            $hash = $this->file->getHash($file);

            if ($this->file->hasVerifyHash($file)
                && !$this->file->wasFileSuccessfullyCopiedViaFileSynchronizerPlugin($file, $hash)) {
                $wrong[] = array(
                    'file' => $file,
                    'hash' => $hash,
                    'verify_file' => $this->file->getPathToVerifyHashFile($file),
                    'verify_hash' => $this->file->getVerifyHash($file)
                );
            }
        }

        return $wrong;
    }
}