Settings.php
6 years ago
WordPress.php
6 years ago
WordPressDbStatement.php
6 years ago
WordPressTracker.php
6 years ago
Settings.php
97 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 | * @package matomo |
| 8 | */ |
| 9 | |
| 10 | namespace WpMatomo\Db; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; // if accessed directly |
| 14 | } |
| 15 | |
| 16 | class Settings { |
| 17 | |
| 18 | /** |
| 19 | * This feature can be used to read data from matomo tables without needing to bootstrap matomo |
| 20 | * |
| 21 | * @param string $table_name_to_prefix |
| 22 | * |
| 23 | * @return string |
| 24 | * @api |
| 25 | */ |
| 26 | public function prefix_table_name( $table_name_to_prefix ) { |
| 27 | global $wpdb; |
| 28 | |
| 29 | return $wpdb->prefix . MATOMO_DATABASE_PREFIX . $table_name_to_prefix; |
| 30 | } |
| 31 | |
| 32 | public function get_installed_matomo_tables() { |
| 33 | global $wpdb; |
| 34 | |
| 35 | $table_names = array(); |
| 36 | $tables = $wpdb->get_results( 'SHOW TABLES LIKE "' . $wpdb->prefix . str_replace( '_', '\_', MATOMO_DATABASE_PREFIX ) . '%"', ARRAY_N ); |
| 37 | foreach ( $tables as $table_name_to_look_for ) { |
| 38 | $table_names[] = array_shift( $table_name_to_look_for ); |
| 39 | } |
| 40 | |
| 41 | // we need to hard code them unfortunately for tests cause there are temporary tables used and we can't find a |
| 42 | // list of existing temp tables |
| 43 | $table_names_to_look_for = array( |
| 44 | 'access', |
| 45 | 'brute_force_log', |
| 46 | 'goal', |
| 47 | 'locks', |
| 48 | 'log_action', |
| 49 | 'log_conversion', |
| 50 | 'log_conversion_item', |
| 51 | 'log_link_visit_action', |
| 52 | 'log_profiling', |
| 53 | 'log_visit', |
| 54 | 'logger_message', |
| 55 | 'option', |
| 56 | 'plugin_setting', |
| 57 | 'privacy_logdata_anonymizations', |
| 58 | 'report', |
| 59 | 'report_subscriptions', |
| 60 | 'segment', |
| 61 | 'sequence', |
| 62 | 'session', |
| 63 | 'site', |
| 64 | 'site_setting', |
| 65 | 'site_url', |
| 66 | 'tagmanager_container', |
| 67 | 'tagmanager_container_release', |
| 68 | 'tagmanager_container_version', |
| 69 | 'tagmanager_tag', |
| 70 | 'tagmanager_trigger', |
| 71 | 'tagmanager_variable', |
| 72 | 'tracking_failure', |
| 73 | 'twofactor_recovery_code', |
| 74 | 'user', |
| 75 | 'user_dashboard', |
| 76 | 'user_language', |
| 77 | ); |
| 78 | foreach ( range( 2010, gmdate( 'Y' ) + 1 ) as $year ) { |
| 79 | foreach ( range( 1, 12 ) as $month ) { |
| 80 | $table_names_to_look_for[] = 'archive_numeric_' . $year . '_' . str_pad( $month, 2, '0' ); |
| 81 | $table_names_to_look_for[] = 'archive_blob_' . $year . '_' . str_pad( $month, 2, '0' ); |
| 82 | } |
| 83 | } |
| 84 | $table_names_to_look_for = apply_filters( 'matomo_install_tables', $table_names_to_look_for ); |
| 85 | |
| 86 | foreach ( $table_names_to_look_for as $table_name_to_look_for ) { |
| 87 | $table_name_to_test = $this->prefix_table_name($table_name_to_look_for); |
| 88 | if ( ! in_array( $table_name_to_test, $table_names, true ) ) { |
| 89 | $table_names[] = $table_name_to_test; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return $table_names; |
| 94 | } |
| 95 | |
| 96 | } |
| 97 |