Skip to content

Commit 03e5c00

Browse files
committed
Update matomo to 5.1.2
1 parent 32fc67d commit 03e5c00

File tree

34 files changed

+808
-241
lines changed

34 files changed

+808
-241
lines changed

www/config/global.ini.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
; Matomo should work correctly without this setting but we recommend to have a charset set.
4646
charset = utf8
4747

48+
; In some database setups the collation used for queries and creating tables can have unexpected
49+
; values, or change after a database version upgrade.
50+
; If you encounter "Illegal mix of collation" errors, setting this config to the value matching
51+
; your existing database tables can help.
52+
; This setting will only be used if "charset" is also set.
53+
; Matomo should work correctly without this setting but we recommend to have a collation set.
54+
collation =
55+
4856
; Database error codes to ignore during updates
4957
;
5058
;ignore_error_codes[] = 1105
@@ -84,6 +92,7 @@
8492
type = InnoDB
8593
schema = Mysql
8694
charset = utf8mb4
95+
collation = utf8mb4_general_ci
8796
enable_ssl = 0
8897
ssl_ca =
8998
ssl_cert =

www/config/manifest.inc.php

Lines changed: 33 additions & 32 deletions
Large diffs are not rendered by default.

www/core/Db.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public static function createReaderDatabaseObject($dbConfig = null)
183183
$dbConfig['type'] = $masterDbConfig['type'];
184184
$dbConfig['tables_prefix'] = $masterDbConfig['tables_prefix'];
185185
$dbConfig['charset'] = $masterDbConfig['charset'];
186+
$dbConfig['collation'] = $masterDbConfig['collation'] ?? null;
186187

187188
$db = @Adapter::factory($dbConfig['adapter'], $dbConfig);
188189

www/core/Db/Schema.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ private function getSchema(): SchemaInterface
8989
return $this->schema;
9090
}
9191

92+
/**
93+
* Returns the default collation for a charset.
94+
*
95+
* @param string $charset
96+
* @return string
97+
*/
98+
public function getDefaultCollationForCharset(string $charset): string
99+
{
100+
return $this->getSchema()->getDefaultCollationForCharset($charset);
101+
}
102+
103+
/**
104+
* Get the table options to use for a CREATE TABLE statement.
105+
*
106+
* @return string
107+
*/
108+
public function getTableCreateOptions(): string
109+
{
110+
return $this->getSchema()->getTableCreateOptions();
111+
}
112+
92113
/**
93114
* Get the SQL to create a specific Piwik table
94115
*

www/core/Db/Schema/Mysql.php

Lines changed: 101 additions & 41 deletions
Large diffs are not rendered by default.

www/core/Db/Schema/Tidb.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,44 @@ public function supportsComplexColumnUpdates(): bool
2525
return false;
2626
}
2727

28+
public function getDefaultCollationForCharset(string $charset): string
29+
{
30+
$collation = parent::getDefaultCollationForCharset($charset);
31+
32+
if ('utf8mb4' === $charset && 'utf8mb4_bin' === $collation) {
33+
// replace the TiDB default "utf8mb4_bin" with a better default
34+
return 'utf8mb4_0900_ai_ci';
35+
}
36+
37+
return $collation;
38+
}
39+
2840
public function getDefaultPort(): int
2941
{
3042
return 4000;
3143
}
44+
45+
public function getTableCreateOptions(): string
46+
{
47+
$engine = $this->getTableEngine();
48+
$charset = $this->getUsedCharset();
49+
$collation = $this->getUsedCollation();
50+
$rowFormat = $this->getTableRowFormat();
51+
52+
if ('utf8mb4' === $charset && '' === $collation) {
53+
$collation = 'utf8mb4_0900_ai_ci';
54+
}
55+
56+
$options = "ENGINE=$engine DEFAULT CHARSET=$charset";
57+
58+
if ('' !== $collation) {
59+
$options .= " COLLATE=$collation";
60+
}
61+
62+
if ('' !== $rowFormat) {
63+
$options .= " $rowFormat";
64+
}
65+
66+
return $options;
67+
}
3268
}

www/core/Db/SchemaInterface.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,26 @@ public function addMaxExecutionTimeHintToQuery(string $sql, float $limit): strin
125125
*/
126126
public function supportsComplexColumnUpdates(): bool;
127127

128+
/**
129+
* Returns the default collation for a charset used by this database engine.
130+
*
131+
* @param string $charset
132+
*
133+
* @return string
134+
*/
135+
public function getDefaultCollationForCharset(string $charset): string;
136+
128137
/**
129138
* Return the default port used by this database engine
130139
*
131140
* @return int
132141
*/
133142
public function getDefaultPort(): int;
143+
144+
/**
145+
* Return the table options to use for a CREATE TABLE statement.
146+
*
147+
* @return string
148+
*/
149+
public function getTableCreateOptions(): string;
134150
}

www/core/Db/Settings.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public function getUsedCharset()
3333
return strtolower($this->getDbSetting('charset'));
3434
}
3535

36+
public function getUsedCollation()
37+
{
38+
return strtolower($this->getDbSetting('collation') ?? '');
39+
}
40+
3641
public function getRowFormat()
3742
{
3843
return $this->getUsedCharset() === 'utf8mb4' ? 'ROW_FORMAT=DYNAMIC' : '';

www/core/DbHelper.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public static function tableHasIndex($table, $indexName)
210210
* @return string
211211
* @throws Tracker\Db\DbException
212212
*/
213-
public static function getDefaultCharset()
213+
public static function getDefaultCharset(): string
214214
{
215215
$result = Db::get()->fetchRow("SHOW CHARACTER SET LIKE 'utf8mb4'");
216216

@@ -233,6 +233,19 @@ public static function getDefaultCharset()
233233
return 'utf8mb4';
234234
}
235235

236+
/**
237+
* Returns the default collation for a charset.
238+
*
239+
* @param string $charset
240+
*
241+
* @return string
242+
* @throws Exception
243+
*/
244+
public static function getDefaultCollationForCharset(string $charset): string
245+
{
246+
return Schema::getInstance()->getDefaultCollationForCharset($charset);
247+
}
248+
236249
/**
237250
* Returns sql queries to convert all installed tables to utf8mb4
238251
*

www/core/Period/Range.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,13 @@ protected function generate()
264264
if (strpos($strDateEnd, '-') === false) {
265265
$timezone = $this->timezone;
266266
}
267+
267268
$endDate = Date::factory($strDateEnd, $timezone)->setTime("00:00:00");
269+
$maxAllowedEndDate = Date::factory(self::getMaxAllowedEndTimestamp());
270+
271+
if ($endDate->isLater($maxAllowedEndDate)) {
272+
$endDate = $maxAllowedEndDate;
273+
}
268274
} else {
269275
throw new Exception($this->translator->translate('General_ExceptionInvalidDateRange', array($this->strDate, ' \'lastN\', \'previousN\', \'YYYY-MM-DD,YYYY-MM-DD\'')));
270276
}
@@ -587,4 +593,19 @@ public function getParentPeriodLabel()
587593
{
588594
return null;
589595
}
596+
597+
/**
598+
* Returns the max allowed end timestamp for a range. If an enddate after this timestamp is provided, Matomo will
599+
* automatically lower the end date to the date returned by this method.
600+
* The max supported timestamp is always set to end of the current year plus 10 years.
601+
*
602+
* @return int
603+
* @api
604+
*/
605+
public static function getMaxAllowedEndTimestamp(): int
606+
{
607+
return strtotime(
608+
date('Y-12-31 00:00:00', strtotime('+10 year', Date::getNowTimestamp()))
609+
);
610+
}
590611
}

0 commit comments

Comments
 (0)