PluginProbe
Float menu – awesome floating side menu / 6.1
Float menu – awesome floating side menu v6.1
7.2.5 trunk 2.1 2.2 3.0.1 3.1 3.2.2 3.3.1 3.5 3.5.1 3.5.2 3.5.3. 3.5.4 4.0 4.1 4.1.1 4.2 4.3 4.3.1 4.3.2 5.0 5.0.1 5.0.2 5.0.3 5.1 All 57 releases
float-menu / classes / Update / UpdateDB.php

UpdateDB.php in Float menu – awesome floating side menu 6.1, at classes/Update/UpdateDB.php

153 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 * Class UpdateDB
5 *
6 * Contains methods for updating the database structure and data
7 *
8 * @package FloatMenuLite
9 * @subpackage Update
10 * @author Dmytro Lobov <dev@wow-company.com>, Wow-Company
11 * @copyright 2024 Dmytro Lobov
12 * @license GPL-2.0+
13 *
14 */
15
16 namespace FloatMenuLite\Update;
17
18 use FloatMenuLite\Admin\DBManager;
19 use FloatMenuLite\WOWP_Plugin;
20
21 class UpdateDB {
22
23 public static function init(): void {
24 $current_db_version = get_site_option( WOWP_Plugin::PREFIX . '_db_version' );
25
26 if ( $current_db_version && version_compare( $current_db_version, '6.0', '>=' ) ) {
27 return;
28 }
29
30 self::start_update();
31
32 update_site_option( WOWP_Plugin::PREFIX . '_db_version', '6.0' );
33 }
34
35 public static function start_update(): void {
36 self::update_database();
37 self::update_options();
38 self::update_fields();
39 }
40
41 public static function update_database(): void {
42
43 global $wpdb;
44 $table = $wpdb->prefix . WOWP_Plugin::PREFIX;
45 $charset_collate = $wpdb->get_charset_collate();
46
47 $columns = "
48 id mediumint(9) NOT NULL AUTO_INCREMENT,
49 title VARCHAR(200) DEFAULT '' NOT NULL,
50 param longtext DEFAULT '' NOT NULL,
51 status boolean DEFAULT 0 NOT NULL,
52 mode boolean DEFAULT 0 NOT NULL,
53 tag text DEFAULT '' NOT NULL,
54 PRIMARY KEY (id)
55 ";
56
57 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
58
59 $sql = "CREATE TABLE $table ($columns) $charset_collate;";
60 dbDelta( $sql );
61 }
62
63 public static function update_options(): void {
64
65 $license = get_option( 'wow_license_key_fmp' );
66 $status = get_option( 'wow_license_status_fmp' );
67 if ( $license !== false ) {
68 update_option( 'wow_license_key_' . WOWP_Plugin::PREFIX, $license );
69 }
70
71 if ( $status !== false ) {
72 update_option( 'wow_license_status_' . WOWP_Plugin::PREFIX, $status );
73 }
74 }
75
76 public static function update_fields(): void {
77 $results = DBManager::get_all_data();
78
79 if ( empty( $results ) || ! is_array( $results ) ) {
80 return;
81 }
82 foreach ( $results as $result ) {
83 $param = maybe_unserialize( $result->param );
84 $status = ! empty( $param['menu_status'] ) ? 0 : 1;
85 $test_mode = ! empty( $param['test_mode'] ) ? 1 : 0;
86
87 $param = self::update_param( $param );
88
89 $data = [
90 'param' => maybe_serialize( $param ),
91 'status' => absint( $status ),
92 'mode' => absint( $test_mode ),
93 'tag' => '',
94 ];
95
96 $where = [ 'id' => $result->id ];
97
98 $data_formats = [ '%s', '%d', '%d', '%s' ];
99
100 DBManager::update( $data, $where, $data_formats );
101
102 }
103 }
104
105 public static function update_param( $param ) {
106 // Responsive
107 if ( ! isset( $param['mobile_on'] ) ) {
108 $param['mobile_on'] = $param['include_mobile'] ?? 0;
109 }
110 if ( ! isset( $param['mobile'] ) ) {
111 $param['mobile'] = $param['screen'] ?? 768;
112 }
113 if ( ! isset( $param['desktop_on'] ) ) {
114 $param['desktop_on'] = $param['include_more_screen'] ?? 0;
115 }
116 if ( ! isset( $param['desktop'] ) ) {
117 $param['desktop'] = $param['screen_more'] ?? 480;
118 }
119 if ( ! isset( $param['mobile_rules_on'] ) ) {
120 $param['mobile_rules_on'] = $param['mobile_rules'] ?? 0;
121 $param['mobile_rules'] = $param['mobile_screen'] ?? 768;
122 }
123
124 if ( ! isset( $param['fontawesome'] ) ) {
125 $param['fontawesome'] = $param['disable_fontawesome'] ?? 0;
126 }
127
128
129 // Show
130 if ( ! is_array( $param['show'] ) ) {
131 $show_old = ! empty( $param['show'] ) ? $param['show'] : 'shortcode';
132
133 $param['show'] = [];
134 $param['operator'] = [];
135 $param['page_type'] = [];
136 $param['ids'] = [];
137
138 $param['show'][0] = 'shortcode';
139 $param['operator'][0] = '1';
140 $param['page_type'][0] = 'is_front_page';
141 $param['ids'][0] = '';
142
143 switch ( $show_old ) {
144 case 'all':
145 $param['show'][0] = 'everywhere';
146 break;
147 }
148 }
149
150 return $param;
151 }
152
153 }