PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.1.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.1.0
5.13.0 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 / Db / Schema.php
matomo / app / core / Db Last commit date
Adapter 2 years ago Schema 2 years ago Adapter.php 2 years ago AdapterInterface.php 2 years ago BatchInsert.php 2 years ago Schema.php 2 years ago SchemaInterface.php 2 years ago Settings.php 2 years ago TransactionLevel.php 2 years ago
Schema.php
219 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\Db;
10
11 use Piwik\Config;
12 use Piwik\Singleton;
13 /**
14 * Schema abstraction
15 *
16 * @method static \Piwik\Db\Schema getInstance()
17 */
18 class Schema extends Singleton
19 {
20 public const DEFAULT_SCHEMA = 'Mysql';
21 /**
22 * Type of database schema
23 *
24 * @var SchemaInterface
25 */
26 private $schema = null;
27 /**
28 * Get schema class name
29 *
30 * @param string $schemaName
31 * @return string
32 */
33 private static function getSchemaClassName($schemaName) : string
34 {
35 // Upgrade from pre 2.0.4
36 if (strtolower($schemaName) == 'myisam' || empty($schemaName)) {
37 $schemaName = self::DEFAULT_SCHEMA;
38 }
39 $class = str_replace(' ', '\\', ucwords(str_replace('_', ' ', strtolower($schemaName))));
40 return '\\Piwik\\Db\\Schema\\' . $class;
41 }
42 /**
43 * Return the default port for the provided database schema
44 *
45 * @param string $schemaName
46 * @return int
47 */
48 public static function getDefaultPortForSchema(string $schemaName) : int
49 {
50 $schemaClassName = self::getSchemaClassName($schemaName);
51 /** @var SchemaInterface $schemaClass */
52 $schemaClass = new $schemaClassName();
53 return $schemaClass->getDefaultPort();
54 }
55 /**
56 * Load schema
57 */
58 private function loadSchema() : void
59 {
60 $config = Config::getInstance();
61 $dbInfos = $config->database;
62 $schemaName = trim($dbInfos['schema']);
63 $className = self::getSchemaClassName($schemaName);
64 $this->schema = new $className();
65 }
66 /**
67 * Returns an instance that subclasses Schema
68 *
69 * @return SchemaInterface
70 */
71 private function getSchema() : \Piwik\Db\SchemaInterface
72 {
73 if ($this->schema === null) {
74 $this->loadSchema();
75 }
76 return $this->schema;
77 }
78 /**
79 * Get the SQL to create a specific Piwik table
80 *
81 * @param string $tableName name of the table to create
82 * @return string SQL
83 */
84 public function getTableCreateSql($tableName)
85 {
86 return $this->getSchema()->getTableCreateSql($tableName);
87 }
88 /**
89 * Get the SQL to create Piwik tables
90 *
91 * @return array array of strings containing SQL
92 */
93 public function getTablesCreateSql()
94 {
95 return $this->getSchema()->getTablesCreateSql();
96 }
97 /**
98 * Creates a new table in the database.
99 *
100 * @param string $nameWithoutPrefix The name of the table without any prefix.
101 * @param string $createDefinition The table create definition
102 */
103 public function createTable($nameWithoutPrefix, $createDefinition)
104 {
105 $this->getSchema()->createTable($nameWithoutPrefix, $createDefinition);
106 }
107 /**
108 * Create database
109 *
110 * @param null|string $dbName database name to create
111 */
112 public function createDatabase($dbName = null)
113 {
114 $this->getSchema()->createDatabase($dbName);
115 }
116 /**
117 * Drop database
118 */
119 public function dropDatabase($dbName = null)
120 {
121 $this->getSchema()->dropDatabase($dbName);
122 }
123 /**
124 * Create all tables
125 */
126 public function createTables() : void
127 {
128 $this->getSchema()->createTables();
129 }
130 /**
131 * Creates an entry in the User table for the "anonymous" user.
132 */
133 public function createAnonymousUser() : void
134 {
135 $this->getSchema()->createAnonymousUser();
136 }
137 /**
138 * Records the Matomo version a user used when installing this Matomo for the first time
139 */
140 public function recordInstallVersion() : void
141 {
142 $this->getSchema()->recordInstallVersion();
143 }
144 /**
145 * Returns which Matomo version was used to install this Matomo for the first time.
146 */
147 public function getInstallVersion()
148 {
149 return $this->getSchema()->getInstallVersion();
150 }
151 /**
152 * Truncate all tables
153 */
154 public function truncateAllTables() : void
155 {
156 $this->getSchema()->truncateAllTables();
157 }
158 /**
159 * Names of all the prefixed tables in Matomo
160 * Doesn't use the DB
161 *
162 * @return array Table names
163 */
164 public function getTablesNames()
165 {
166 return $this->getSchema()->getTablesNames();
167 }
168 /**
169 * Get list of tables installed
170 *
171 * @param bool $forceReload Invalidate cache
172 * @return array installed tables
173 */
174 public function getTablesInstalled($forceReload = true)
175 {
176 return $this->getSchema()->getTablesInstalled($forceReload);
177 }
178 /**
179 * Get list of installed columns in a table
180 *
181 * @param string $tableName The name of a table.
182 *
183 * @return array Installed columns indexed by the column name.
184 */
185 public function getTableColumns($tableName)
186 {
187 return $this->getSchema()->getTableColumns($tableName);
188 }
189 /**
190 * Returns true if Matomo tables exist
191 *
192 * @return bool True if tables exist; false otherwise
193 */
194 public function hasTables()
195 {
196 return $this->getSchema()->hasTables();
197 }
198 /**
199 * Adds a MAX_EXECUTION_TIME hint into a SELECT query if $limit is bigger than 0
200 *
201 * @param string $sql query to add hint to
202 * @param float $limit time limit in seconds
203 * @return string
204 */
205 public function addMaxExecutionTimeHintToQuery(string $sql, float $limit) : string
206 {
207 return $this->getSchema()->addMaxExecutionTimeHintToQuery($sql, $limit);
208 }
209 /**
210 * Returns if the schema support complex column updates
211 *
212 * @return bool
213 */
214 public function supportsComplexColumnUpdates() : bool
215 {
216 return $this->getSchema()->supportsComplexColumnUpdates();
217 }
218 }
219