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