PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.4
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.4
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.4, at modules/logs/classes/class-log-install.php

155 lines 4.2 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.8'; // 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 object_id varchar(20) NOT NULL DEFAULT '',
84 item text NOT NULL,
85 user_id int(11) unsigned NOT NULL DEFAULT '0',
86 action varchar(100) NOT NULL,
87 context varchar(100) NOT NULL,
88 connector varchar(100) NOT NULL,
89 state tinyint(1) unsigned NULL,
90 created int(11) NOT NULL DEFAULT 0,
91 duration float(11,4) NOT NULL DEFAULT '0',
92 dismiss tinyint(1) NOT NULL DEFAULT 0,
93 KEY site_id (site_id),
94 KEY user_id (user_id),
95 KEY created (created),
96 KEY duration (duration),
97 KEY context (context),
98 KEY connector (connector),
99 KEY action (action),
100 KEY state (state)";
101
102 if ( empty( $currentVersion ) ) {
103 $tbl .= ',
104 PRIMARY KEY (log_id)';
105 }
106 $tbl .= ') ' . $charset_collate;
107 $sql[] = $tbl;
108
109 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_logs_meta' ) . ' (
110 meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
111 meta_log_id bigint(20) unsigned NOT NULL,
112 meta_key varchar(200) NOT NULL,
113 meta_value mediumtext NOT NULL,
114 KEY meta_log_id (meta_log_id),
115 KEY meta_key (meta_key(191))';
116
117 if ( empty( $currentVersion ) ) {
118 $tbl .= ',
119 PRIMARY KEY (`meta_id`) ';
120 }
121
122 $tbl .= ') ' . $charset_collate;
123 $sql[] = $tbl;
124
125 require_once ABSPATH . 'wp-admin/includes/upgrade.php'; // NOSONAR - WP compatible.
126
127 global $wpdb;
128
129 if ( MainWP_Utility::instance()->is_disabled_functions( 'error_log' ) || ! function_exists( '\error_log' ) ) {
130 error_reporting(0); // phpcs:ignore -- try to disabled the error_log somewhere in WP.
131 }
132
133 $suppress = $wpdb->suppress_errors();
134 foreach ( $sql as $query ) {
135 dbDelta( $query );
136 }
137 $wpdb->suppress_errors( $suppress );
138
139 MainWP_Utility::update_option( $this->log_db_option_key, $this->log_db_version );
140
141 $this->update_log_db( $currentVersion );
142 }
143
144 /**
145 * Method update module log tables.
146 *
147 * @param string $currentVersion Current db version.
148 */
149 public function update_log_db( $currentVersion ) {
150 if ( version_compare( $currentVersion, '1.0.1.7', '<' ) ) { // NOSONAR - non-ip.
151 $this->wpdb->query( 'ALTER TABLE ' . $this->table_name( 'wp_logs' ) . ' ADD INDEX index_site_object_id (site_id, object_id)' ); //phpcs:ignore -- ok.
152 }
153 }
154 }
155