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

161 lines 3.6 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';
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 === self::$instance ) {
54 self::$instance = new self();
55 }
56 return self::$instance;
57 }
58
59 /**
60 * Class constructor
61 */
62 public function __construct() { // phpcs:ignore -- overrided.
63 parent::__construct();
64 }
65
66 /**
67 * Method handle to install module log tables.
68 */
69 public function install() {
70
71 global $wpdb;
72
73 // get_site_option is multisite aware!
74 $currentVersion = get_site_option( $this->log_db_option_key );
75
76 $rslt = $this->query( "SHOW TABLES LIKE '" . $this->table_name( 'wp_logs' ) . "'" );
77 if ( empty( self::num_rows( $rslt ) ) ) {
78 $currentVersion = false;
79 }
80
81 if ( $currentVersion === $this->log_db_version ) {
82 return;
83 }
84
85 $charset_collate = $wpdb->get_charset_collate();
86
87 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_logs' ) . " (
88 log_id bigint(20) NOT NULL auto_increment,
89 site_id bigint(20) unsigned NULL,
90 item text NOT NULL,
91 user_id int(11) unsigned NOT NULL DEFAULT '0',
92 action varchar(100) NOT NULL,
93 context varchar(100) NOT NULL,
94 connector varchar(100) NOT NULL,
95 state tinyint(1) unsigned NULL,
96 created int(11) NOT NULL DEFAULT 0,
97 duration float(11,4) NOT NULL DEFAULT '0',
98 KEY site_id (site_id),
99 KEY user_id (user_id),
100 KEY created (created),
101 KEY duration (duration),
102 KEY context (context),
103 KEY connector (connector),
104 KEY action (action),
105 KEY state (state)";
106
107 if ( empty( $currentVersion ) ) {
108 $tbl .= ',
109 PRIMARY KEY (log_id)';
110 }
111 $tbl .= ') ' . $charset_collate;
112 $sql[] = $tbl;
113
114 $tbl = 'CREATE TABLE ' . $this->table_name( 'wp_logs_meta' ) . ' (
115 meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
116 meta_log_id bigint(20) unsigned NOT NULL,
117 meta_key varchar(200) NOT NULL,
118 meta_value mediumtext NOT NULL,
119 KEY meta_log_id (meta_log_id),
120 KEY meta_key (meta_key(191))';
121
122 if ( empty( $currentVersion ) ) {
123 $tbl .= ',
124 PRIMARY KEY (`meta_id`) ';
125 }
126
127 $tbl .= ') ' . $charset_collate;
128 $sql[] = $tbl;
129
130 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
131
132 global $wpdb;
133
134 if ( MainWP_Utility::instance()->is_disabled_functions( 'error_log' ) || ! function_exists( '\error_log' ) ) {
135 error_reporting(0); // phpcs:ignore -- try to disabled the error_log somewhere in WP.
136 }
137
138 $this->update_check_modify( $currentVersion );
139
140 $suppress = $wpdb->suppress_errors();
141 foreach ( $sql as $query ) {
142 dbDelta( $query );
143 }
144 $wpdb->suppress_errors( $suppress );
145
146 MainWP_Utility::update_option( $this->log_db_option_key, $this->log_db_version );
147 }
148
149 /**
150 * Method handle update db tables and data.
151 *
152 * @param string $currentVersion current version.
153 */
154 public function update_check_modify( $currentVersion ) {
155
156 if ( empty( $currentVersion ) ) {
157 return;
158 }
159 }
160 }
161