PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.14.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.14.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Updater / Migration / Db / Sql.php
matomo / app / core / Updater / Migration / Db Last commit date
AddColumn.php 5 years ago AddColumns.php 5 years ago AddIndex.php 5 years ago AddPrimaryKey.php 5 years ago AddUniqueKey.php 5 years ago BatchInsert.php 5 years ago BoundSql.php 5 years ago ChangeColumn.php 5 years ago ChangeColumnType.php 5 years ago ChangeColumnTypes.php 5 years ago CreateTable.php 4 years ago DropColumn.php 5 years ago DropColumns.php 4 years ago DropIndex.php 5 years ago DropPrimaryKey.php 5 years ago DropTable.php 5 years ago Factory.php 5 years ago Insert.php 5 years ago Sql.php 3 years ago
Sql.php
103 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 */
8 namespace Piwik\Updater\Migration\Db;
9 use Piwik\Common;
10 use Piwik\Config;
11 use Piwik\Db;
12 use Piwik\Updater\Migration\Db as DbMigration;
13
14 /**
15 * Executes a given SQL query.
16 *
17 * @see Factory::sql()
18 * @ignore
19 */
20 class Sql extends DbMigration
21 {
22
23 /**
24 * @var string
25 */
26 protected $sql;
27
28 /**
29 * @var false|int|array
30 */
31 private $errorCodesToIgnore;
32
33 /**
34 * Sql constructor.
35 *
36 * @param string $sql
37 * @param int|int[] $errorCodesToIgnore If no error should be ignored use an empty array.
38 */
39 public function __construct($sql, $errorCodesToIgnore)
40 {
41 if (!is_array($errorCodesToIgnore)) {
42 $errorCodesToIgnore = array($errorCodesToIgnore);
43 }
44
45 $this->sql = $sql;
46 $globalErrorCodesToIgnore = Config::getInstance()->database['ignore_error_codes'] ?? [];
47 $this->errorCodesToIgnore = array_merge($errorCodesToIgnore, (is_array($globalErrorCodesToIgnore) ? $globalErrorCodesToIgnore : []));
48 }
49
50 public function shouldIgnoreError($exception)
51 {
52 if (empty($this->errorCodesToIgnore)) {
53 return false;
54 }
55
56 foreach ($this->errorCodesToIgnore as $code) {
57 if (Db::get()->isErrNo($exception, $code)) {
58 return true;
59 }
60 }
61
62 return false;
63 }
64
65 /**
66 * @internal
67 * @param int $errorCode
68 * @return $this
69 */
70 public function addErrorCodeToIgnore($errorCode)
71 {
72 $this->errorCodesToIgnore[] = $errorCode;
73
74 return $this;
75 }
76
77 /**
78 * @internal
79 */
80 public function getErrorCodesToIgnore()
81 {
82 return $this->errorCodesToIgnore;
83 }
84
85 public function __toString()
86 {
87 $sql = $this->sql;
88
89 if (!empty($sql) && !Common::stringEndsWith($sql, ';')) {
90 $sql .= ';';
91 }
92
93 return $sql;
94 }
95
96 public function exec()
97 {
98 if (!empty($this->sql)) {
99 Db::exec($this->sql);
100 }
101 }
102 }
103