LogQueryBuilder
3 months ago
Actions.php
6 months ago
ArchiveSelector.php
1 month ago
ArchiveTableCreator.php
1 month ago
ArchiveTableDao.php
1 month ago
ArchiveWriter.php
1 month ago
ArchivingDbAdapter.php
1 year ago
LogAggregator.php
1 month ago
LogQueryBuilder.php
6 months ago
LogTableTemporary.php
2 years ago
Model.php
1 month ago
RawLogDao.php
6 months ago
TableMetadata.php
1 year ago
TableMetadata.php
51 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\DataAccess; |
| 10 | |
| 11 | use Piwik\Db; |
| 12 | /** |
| 13 | * Data Access Object that can be used to get metadata information about |
| 14 | * the MySQL tables Piwik uses. |
| 15 | */ |
| 16 | class TableMetadata |
| 17 | { |
| 18 | /** |
| 19 | * Returns the list of column names for a table. |
| 20 | * |
| 21 | * @param string $table Prefixed table name. |
| 22 | * @return string[] List of column names.. |
| 23 | */ |
| 24 | public function getColumns($table) |
| 25 | { |
| 26 | $table = str_replace("`", "", $table); |
| 27 | $columns = Db::fetchAll("SHOW COLUMNS FROM `" . $table . "`"); |
| 28 | $columnNames = array(); |
| 29 | foreach ($columns as $column) { |
| 30 | $columnNames[] = $column['Field']; |
| 31 | } |
| 32 | return $columnNames; |
| 33 | } |
| 34 | /** |
| 35 | * Returns the list of idaction columns in a table. A column is |
| 36 | * assumed to be an idaction reference if it has `"idaction"` in its |
| 37 | * name (eg, `"idaction_url"` or `"idaction_content_name"`. |
| 38 | * |
| 39 | * @param string $table Prefixed table name. |
| 40 | * @return string[] |
| 41 | */ |
| 42 | public function getIdActionColumnNames($table) |
| 43 | { |
| 44 | $columns = $this->getColumns($table); |
| 45 | $columns = array_filter($columns, function ($columnName) { |
| 46 | return strpos($columnName, 'idaction') !== \false; |
| 47 | }); |
| 48 | return array_values($columns); |
| 49 | } |
| 50 | } |
| 51 |