PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.1
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / modules / logs / classes / class-log-install.php

class-log-install.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.1, at modules/logs/classes/class-log-install.php

140 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 * This file handles all interactions with the Log DB.
5 *
6 * @package MainWP/Dashboard
7 */
8
9 namespace MainWP\Dashboard\Module\Log;
10
11 use MainWP\Dashboard\MainWP_Install;
12 use MainWP\Dashboard\MainWP_Utility;
13
14 /**
15 * Class Log_Install
16 *
17 * @package MainWP\Dashboard
18 */
19 class Log_Install extends MainWP_Install {
20
21 /**
22 * Protected variable to hold the database version info.
23 *
24 * @var string DB version info.
25 */
26 protected $log_db_version = '1.0.1.2'; // NOSONAR - no IP.
27
28 /**
29 * Protected variable to hold the database option name.
30 *
31 * @var string DB version info.
32 */
33 protected $log_db_option_key = 'mainwp_module_log_db_version';
34
35 /**
36 * Private static variable to hold the single instance of the class.
37 *
38 * @static
39 *
40 * @var mixed Default null
41 */
42 private static $instance = null;
43
44 /**
45 * Method instance()
46 *
47 * Return public static instance.
48 *
49 * @static
50 * @return instance of class.
51 */
52 public static function instance() {
53 if ( null === static::$instance ) {
54 static::$instance = new self();
55 }
56 return static::$instance;
57 }
58
59 /**
60 * Method handle to install module log tables.
61 */
62 public function install() {
63
64 global $wpdb;
65
66 // get_site_option is multisite aware!
67 $currentVersion = get_site_option( $this->log_db_option_key );
68
69 $rslt = $this->query( "SHOW TABLES LIKE '" . $this->table_name( 'wp_logs' ) . "'" );
70 if ( empty( static::num_rows( $rslt ) ) ) {
71 $currentVersion = false;
72 }
73
74 if ( $currentVersion === $this->log_db_version ) {
75 return;
76 }
77
78 $charset_collate = $wpdb->get_charset_collate();
79
80 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_logs' ) . " (
81 log_id bigint(20) NOT NULL auto_increment,
82 site_id bigint(20) unsigned NULL,
83 item text NOT NULL,
84 user_id int(11) unsigned NOT NULL DEFAULT '0',
85 action varchar(100) NOT NULL,
86 context varchar(100) NOT NULL,
87 connector varchar(100) NOT NULL,
88 state tinyint(1) unsigned NULL,
89 created int(11) NOT NULL DEFAULT 0,
90 duration float(11,4) NOT NULL DEFAULT '0',
91 KEY site_id (site_id),
92 KEY user_id (user_id),
93 KEY created (created),
94 KEY duration (duration),
95 KEY context (context),
96 KEY connector (connector),
97 KEY action (action),
98 KEY state (state)";
99
100 if ( empty( $currentVersion ) ) {
101 $tbl .= ',
102 PRIMARY KEY (log_id)';
103 }
104 $tbl .= ') ' . $charset_collate;
105 $sql[] = $tbl;
106
107 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_logs_meta' ) . ' (
108 meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
109 meta_log_id bigint(20) unsigned NOT NULL,
110 meta_key varchar(200) NOT NULL,
111 meta_value mediumtext NOT NULL,
112 KEY meta_log_id (meta_log_id),
113 KEY meta_key (meta_key(191))';
114
115 if ( empty( $currentVersion ) ) {
116 $tbl .= ',
117 PRIMARY KEY (`meta_id`) ';
118 }
119
120 $tbl .= ') ' . $charset_collate;
121 $sql[] = $tbl;
122
123 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; // NOSONAR - WP compatible.
124
125 global $wpdb;
126
127 if ( MainWP_Utility::instance()->is_disabled_functions( 'error_log' ) || ! function_exists( '\error_log' ) ) {
128 error_reporting(0); // phpcs:ignore -- try to disabled the error_log somewhere in WP.
129 }
130
131 $suppress = $wpdb->suppress_errors();
132 foreach ( $sql as $query ) {
133 dbDelta( $query );
134 }
135 $wpdb->suppress_errors( $suppress );
136
137 MainWP_Utility::update_option( $this->log_db_option_key, $this->log_db_version );
138 }
139 }
140