Spaces:
Paused

File size: 2,643 Bytes
bf8c0ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Tests\Fixtures;

use Piwik\Changes\Model as ChangesModel;
use Piwik\Common;
use Piwik\Date;
use Piwik\Db;
use Piwik\Tests\Framework\Fixture;

class CreateChanges extends Fixture
{
    private $idSite = 1;

    public function setUp(): void
    {
        parent::setUp();
        Fixture::createSuperUser();
        if (!self::siteCreated($idSite = $this->idSite)) {
            self::createWebsite('2021-01-01');
        }
        $this->trackVisits();
        $this->createChanges();
    }

    private function createChanges()
    {
        // Manually insert a change that is older than 6 months
        Db::query(
            "INSERT INTO `" . Common::prefixTable('changes') . "`
                   (`idchange`, `created_time`, `plugin_name`, `version`, `title`, `description`, `link_name`, `link`)
               VALUES
                   (1, '2021-12-17 12:46:04', 'ExamplePlugin', '4.0.1', 'New feature y added', 'Now you can do c with d like this.', NULL, NULL);"
        );


        $changes = [
            [
             'version' => '4.6.0b5',
             'title' => 'New feature x added',
             'description' => 'Now you can do a with b like this',
             'link_name' => 'For more information go here',
             'link' => 'https://www.matomo.org',
             'plugin' => 'CoreHome',
            ],
            [
             'version' => '4.5.0',
             'title' => 'New feature y added',
             'description' => 'Now you can do c with d like this',
             'plugin' => 'CustomAlerts',
            ],
            [
             'version' => '4.4.0',
             'title' => 'New feature z added',
             'description' => 'Now you can do e with f like this',
             'link_name' => 'For more information go here',
             'link' => 'https://www.matomo.org',
             'plugin' => 'CustomDimensions',
            ],
        ];

        $changes = array_reverse($changes);
        $changesModel = new ChangesModel(); // Intentionally not using the FakeChangesModel, we want these changes added
        foreach ($changes as $change) {
            $changesModel->addChange($change['plugin'], $change);
        }
    }

    private function trackVisits()
    {
        $dateTime = Date::today()->toString();
        $t = self::getTracker($this->idSite, $dateTime, $defaultInit = true);

        $t->setUrl('http://example.org/index.htm');
        self::checkResponse($t->doTrackPageView('0'));
    }
}