File size: 6,063 Bytes
f1bab00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?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\Plugins\CoreAdminHome\tests\Fixture;

use Piwik\Common;
use Piwik\Db;
use Piwik\Tests\Framework\Fixture;

/**
 * Fixture that adds log table rows that use duplicate actions.
 */
class DuplicateActions extends Fixture
{
    public const DUMMY_IDVISITOR = 'c1d2a36653fd88e2';

    private static $dataToInsert = array(
        'log_action' => array(
            array('name' => 'action1', 'type' => 1),
            array('name' => 'action1', 'type' => 1),
            array('name' => 'action1', 'type' => 1),

            array('name' => 'action2', 'type' => 2),
            array('name' => 'ACTION2', 'type' => 1),
            array('name' => 'action4', 'type' => 3),
            array('name' => 'ACTION2', 'type' => 1),
            array('name' => 'action5', 'type' => 2),

            array('name' => 'action2', 'type' => 2),
            array('name' => 'action4', 'type' => 3),
            array('name' => 'ACTION2', 'type' => 1),
            array('name' => 'action4', 'type' => 3),
        ),
        'log_link_visit_action' => array(
            array(
                'idsite' => 1,
                'idvisitor' => self::DUMMY_IDVISITOR,
                'idvisit' => 1,
                'server_time' => '2012-01-01 00:00:00',
                'time_spent_ref_action' => 100,
                'idaction_url_ref' => 1,
                'idaction_name_ref' => 2,
                'idaction_name' => 3,
                'idaction_url' => 4,
                'idaction_event_action' => 5,
                'idaction_event_category' => 6,
                'idaction_content_interaction' => 7,
                'idaction_content_name' => 8,
                'idaction_content_piece' => 9,
                'idaction_content_target' => 10,
            ),
            array(
                'idsite' => 2,
                'idvisitor' => self::DUMMY_IDVISITOR,
                'idvisit' => 2,
                'server_time' => '2013-01-01 00:00:00',
                'time_spent_ref_action' => 120,
                'idaction_url_ref' => 2,
                'idaction_name_ref' => 3,
                'idaction_name' => 5,
                'idaction_url' => 7,
                'idaction_event_action' => 9,
                'idaction_event_category' => 10,
                'idaction_content_interaction' => 11,
                'idaction_content_name' => 11,
                'idaction_content_piece' => 12,
                'idaction_content_target' => 12,
            ),
        ),
        'log_conversion' => array(
            array(
                'idvisit' => 1,
                'idsite' => 1,
                'idvisitor' => self::DUMMY_IDVISITOR,
                'server_time' => '2012-02-01 00:00:00',
                'idgoal' => 1,
                'buster' => 1,
                'url' => 'http://example.com/',
                'location_country' => 'nz',
                'visitor_count_visits' => 1,
                'visitor_returning' => 1,
                'visitor_seconds_since_order' => 1,
                'visitor_seconds_since_first' => 1,
                'idaction_url' => 4,
            ),

            array(
                'idvisit' => 2,
                'idsite' => 2,
                'idvisitor' => self::DUMMY_IDVISITOR,
                'server_time' => '2012-03-01 00:00:00',
                'idgoal' => 2,
                'buster' => 2,
                'url' => 'http://example.com/',
                'location_country' => 'nz',
                'visitor_count_visits' => 1,
                'visitor_returning' => 1,
                'visitor_seconds_since_order' => 1,
                'visitor_seconds_since_first' => 1,
                'idaction_url' => 7,
            ),
        ),
        'log_conversion_item' => array(
            array(
                'idsite' => 1,
                'idvisitor' => self::DUMMY_IDVISITOR,
                'server_time' => '2012-02-01 00:00:00',
                'idvisit' => 1,
                'idorder' => 1,
                'price' => 10,
                'quantity' => 2,
                'deleted' => 0,
                'idaction_sku' => 1,
                'idaction_name' => 2,
                'idaction_category' => 3,
                'idaction_category2' => 4,
                'idaction_category3' => 5,
                'idaction_category4' => 6,
                'idaction_category5' => 7,
            ),
            array(
                'idsite' => 2,
                'idvisitor' => self::DUMMY_IDVISITOR,
                'server_time' => '2012-01-09 00:00:00',
                'idvisit' => 2,
                'idorder' => 2,
                'price' => 10,
                'quantity' => 1,
                'deleted' => 1,
                'idaction_sku' => 2,
                'idaction_name' => 3,
                'idaction_category' => 5,
                'idaction_category2' => 7,
                'idaction_category3' => 8,
                'idaction_category4' => 9,
                'idaction_category5' => 10,
            ),
        ),
    );

    public function setUp(): void
    {
        parent::setUp();

        foreach (self::$dataToInsert as $table => $rows) {
            self::insertRowData($table, $rows);
        }
    }

    private static function insertRowData($unprefixedTable, $rows)
    {
        $table = Common::prefixTable($unprefixedTable);
        foreach ($rows as $row) {
            if ($unprefixedTable == 'log_action') {
                $row['hash'] = crc32($row['name']);
            }

            if (isset($row['idvisitor'])) {
                $row['idvisitor'] = pack("H*", $row['idvisitor']);
            }

            $placeholders = array_map(function () {
                return "?";
            }, $row);
            $sql = "INSERT INTO $table (" . implode(',', array_keys($row)) . ") VALUES (" . implode(',', $placeholders) . ")";
            Db::query($sql, array_values($row));
        }
    }
}