| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\Db; |
|
|
| use Piwik\Config; |
| use Piwik\Singleton; |
|
|
| |
| |
| |
| |
| |
| class Schema extends Singleton |
| { |
| public const DEFAULT_SCHEMA = 'Mysql'; |
|
|
| |
| |
| |
| |
| |
| private $schema = null; |
|
|
| |
| |
| |
| |
| |
| private static function getSchemaClassName($schemaName): string |
| { |
| |
| if ( |
| strtolower($schemaName) == 'myisam' |
| || empty($schemaName) |
| ) { |
| $schemaName = self::DEFAULT_SCHEMA; |
| } |
|
|
| $class = str_replace(' ', '\\', ucwords(str_replace('_', ' ', strtolower($schemaName)))); |
| return '\Piwik\Db\Schema\\' . $class; |
| } |
|
|
| |
| |
| |
| public static function getDefaultPortForSchema(string $schemaName): int |
| { |
| $schemaClassName = self::getSchemaClassName($schemaName); |
| |
| $schemaClass = new $schemaClassName(); |
| return $schemaClass->getDefaultPort(); |
| } |
|
|
| |
| |
| |
| private function loadSchema(): void |
| { |
| $config = Config::getInstance(); |
| $dbInfos = $config->database; |
| $schemaName = trim($dbInfos['schema']); |
|
|
| $className = self::getSchemaClassName($schemaName); |
| $this->schema = new $className(); |
| } |
|
|
| |
| |
| |
| private function getSchema(): SchemaInterface |
| { |
| if ($this->schema === null) { |
| $this->loadSchema(); |
| } |
|
|
| return $this->schema; |
| } |
|
|
| |
| |
| |
| public function unsetSchema(): void |
| { |
| $this->schema = null; |
| } |
|
|
| |
| |
| |
| public function getDefaultCollationForCharset(string $charset): string |
| { |
| return $this->getSchema()->getDefaultCollationForCharset($charset); |
| } |
|
|
| |
| |
| |
| public function getTableCreateOptions(): string |
| { |
| return $this->getSchema()->getTableCreateOptions(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getTableCreateSql($tableName) |
| { |
| return $this->getSchema()->getTableCreateSql($tableName); |
| } |
|
|
| |
| |
| |
| |
| |
| public function getTablesCreateSql() |
| { |
| return $this->getSchema()->getTablesCreateSql(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function createTable($nameWithoutPrefix, $createDefinition) |
| { |
| $this->getSchema()->createTable($nameWithoutPrefix, $createDefinition); |
| } |
|
|
| |
| |
| |
| |
| |
| public function createDatabase($dbName = null) |
| { |
| $this->getSchema()->createDatabase($dbName); |
| } |
|
|
| |
| |
| |
| public function dropDatabase($dbName = null) |
| { |
| $this->getSchema()->dropDatabase($dbName); |
| } |
|
|
| |
| |
| |
| public function createTables(): void |
| { |
| $this->getSchema()->createTables(); |
| } |
|
|
| |
| |
| |
| public function createAnonymousUser(): void |
| { |
| $this->getSchema()->createAnonymousUser(); |
| } |
|
|
| |
| |
| |
| public function recordInstallVersion(): void |
| { |
| $this->getSchema()->recordInstallVersion(); |
| } |
|
|
| |
| |
| |
| public function getInstallVersion() |
| { |
| return $this->getSchema()->getInstallVersion(); |
| } |
|
|
| |
| |
| |
| public function truncateAllTables(): void |
| { |
| $this->getSchema()->truncateAllTables(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getTablesNames() |
| { |
| return $this->getSchema()->getTablesNames(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function getTablesInstalled($forceReload = true) |
| { |
| return $this->getSchema()->getTablesInstalled($forceReload); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| public function getTableColumns($tableName) |
| { |
| return $this->getSchema()->getTableColumns($tableName); |
| } |
|
|
| |
| |
| |
| |
| |
| public function hasTables() |
| { |
| return $this->getSchema()->hasTables(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function addMaxExecutionTimeHintToQuery(string $sql, float $limit): string |
| { |
| return $this->getSchema()->addMaxExecutionTimeHintToQuery($sql, $limit); |
| } |
|
|
| |
| |
| |
| public function supportsComplexColumnUpdates(): bool |
| { |
| return $this->getSchema()->supportsComplexColumnUpdates(); |
| } |
|
|
| |
| |
| |
| public function isOptimizeInnoDBSupported(): bool |
| { |
| return $this->getSchema()->isOptimizeInnoDBSupported(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public function optimizeTables(array $tables, bool $force = false): bool |
| { |
| return $this->getSchema()->optimizeTables($tables, $force); |
| } |
|
|
| |
| |
| |
| |
| public function supportsRankingRollupWithoutExtraSorting(): bool |
| { |
| return $this->getSchema()->supportsRankingRollupWithoutExtraSorting(); |
| } |
|
|
| |
| |
| |
| public function supportsSortingInSubquery(): bool |
| { |
| return $this->getSchema()->supportsSortingInSubquery(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function getSupportedReadIsolationTransactionLevel(): string |
| { |
| return $this->getSchema()->getSupportedReadIsolationTransactionLevel(); |
| } |
|
|
| |
| |
| |
| public function getDatabaseType(): string |
| { |
| return $this->getSchema()->getDatabaseType(); |
| } |
|
|
| |
| |
| |
| public function getVersion(): string |
| { |
| return $this->getSchema()->getVersion(); |
| } |
|
|
| |
| |
| |
| public function getMinimumSupportedVersion(): string |
| { |
| return $this->getSchema()->getMinimumSupportedVersion(); |
| } |
|
|
| |
| |
| |
| public function hasReachedEOL(): string |
| { |
| return $this->getSchema()->hasReachedEOL(); |
| } |
| } |
|
|