PluginProbe
Redirection / 2.3.5
Redirection v2.3.5
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / models / database.php

database.php in Redirection 2.3.5, at models/database.php

268 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class A_Redirector_URL {
4 }
5
6 class Redirector_Login {
7 }
8
9 class Redirector_LuckyDip {
10 }
11
12 class Redirector_Random {
13 }
14
15 class Redirector_Referrer {
16 }
17
18 class RE_Database {
19 function get_charset() {
20 global $wpdb;
21
22 $charset_collate = '';
23 if ( ! empty($wpdb->charset) )
24 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
25
26 if ( ! empty($wpdb->collate) )
27 $charset_collate .= " COLLATE $wpdb->collate";
28
29 return $charset_collate;
30 }
31
32 function install() {
33 global $wpdb;
34
35 $charset_collate = $this->get_charset();
36
37 $create = array(
38 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_items`(
39 `id` int(11) unsigned NOT NULL auto_increment,
40 `url` mediumtext NOT NULL,
41 `regex` int(11) unsigned NOT NULL default '0',
42 `position` int(11) unsigned NOT NULL default '0',
43 `last_count` int(10) unsigned NOT NULL default '0',
44 `last_access` datetime NOT NULL,
45 `group_id` int(11) NOT NULL default '0',
46 `status` enum('enabled','disabled' ) NOT NULL default 'enabled',
47 `action_type` varchar(20) NOT NULL,
48 `action_code` int(11) unsigned NOT NULL,
49 `action_data` mediumtext,
50 `match_type` varchar(20) NOT NULL,
51 `title` varchar(50) NULL,
52 PRIMARY KEY ( `id`),
53 KEY `url` (`url`(200)),
54 KEY `status` (`status`),
55 KEY `regex` (`regex`),
56 KEY `group_idpos` (`group_id`,`position`),
57 KEY `group` (`group_id`)
58 ) $charset_collate",
59
60 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_groups`(
61 `id` int(11) NOT NULL auto_increment,
62 `name` varchar(50) NOT NULL,
63 `tracking` int(11) NOT NULL default '1',
64 `module_id` int(11) unsigned NOT NULL default '0',
65 `status` enum('enabled','disabled' ) NOT NULL default 'enabled',
66 `position` int(11) unsigned NOT NULL default '0',
67 PRIMARY KEY ( `id`),
68 KEY `module_id` (`module_id`),
69 KEY `status` (`status`)
70 ) $charset_collate",
71
72 "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_logs`(
73 `id` int(11) unsigned NOT NULL auto_increment,
74 `created` datetime NOT NULL,
75 `url` mediumtext NOT NULL,
76 `sent_to` mediumtext,
77 `agent` mediumtext NOT NULL,
78 `referrer` mediumtext,
79 `redirection_id` int(11) unsigned default NULL,
80 `ip` varchar(17) NOT NULL default '',
81 `module_id` int(11) unsigned NOT NULL,
82 `group_id` int(11) unsigned default NULL,
83 PRIMARY KEY ( `id`),
84 KEY `created` (`created`),
85 KEY `redirection_id` (`redirection_id`),
86 KEY `ip` (`ip`),
87 KEY `group_id` (`group_id`),
88 KEY `module_id` (`module_id`)
89 ) $charset_collate",
90
91 "CREATE TABLE `{$wpdb->prefix}redirection_modules`(
92 `id` int(11) unsigned NOT NULL auto_increment,
93 `type` varchar(20) NOT NULL default '',
94 `name` varchar(50) NOT NULL default '',
95 `options` mediumtext,
96 PRIMARY KEY ( `id`),
97 KEY `name` (`name`),
98 KEY `type` (`type`)
99 ) $charset_collate",
100
101 "CREATE TABLE `{$wpdb->prefix}redirection_404` (
102 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
103 `created` datetime NOT NULL,
104 `url` varchar(255) NOT NULL DEFAULT '',
105 `agent` varchar(255) DEFAULT NULL,
106 `referrer` varchar(255) DEFAULT NULL,
107 `ip` int(10) unsigned NOT NULL,
108 PRIMARY KEY (`id`),
109 KEY `created` (`created`),
110 KEY `url` (`url`),
111 KEY `ip` (`ip`),
112 KEY `referrer` (`referrer`)
113 ) $charset_collate;"
114 );
115
116 foreach ( $create AS $sql ) {
117 if ( $wpdb->query( $sql ) === false )
118 return false;
119 }
120
121 // Modules
122 if ( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_modules" ) == 0 ) {
123 $wpdb->insert( $wpdb->prefix.'redirection_modules', array( 'type' => 'wp', 'name' => __( 'WordPress', 'redirection' ), 'options' => '' ) );
124 $wpdb->insert( $wpdb->prefix.'redirection_modules', array( 'type' => 'apache', 'name' => __( 'Apache', 'redirection' ), 'options' => '' ) );
125 }
126
127 // Groups
128 if ( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups" ) == 0 ) {
129 $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Redirections' ), 'module_id' => 1, 'position' => 0 ) );
130 $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Modified Posts' ), 'module_id' => 1, 'position' => 1 ) );
131
132 $options = get_option( 'redirection_options' );
133 $options['monitor_post'] = 2;
134 $options['monitor_category'] = 2;
135
136 update_option( 'redirection_options', $options );
137 }
138 }
139
140 function upgrade( $current, $target ) {
141 global $wpdb;
142
143 $wpdb->show_errors();
144
145 // No previous version? Install the DB tables
146 if ( $current === false )
147 $success = $this->install();
148 else {
149 // Try and upgrade from a previous version
150 if ( $current == '2.0' )
151 $this->upgrade_from_20();
152 elseif ( $current == '2.0.1' )
153 $this->upgrade_from_21();
154 elseif ( $current == '2.0.2' )
155 $this->upgrade_from_22();
156
157 if ( version_compare( $current, '2.1.16' ) == -1 )
158 $this->upgrade_to_216();
159
160 if ( version_compare( $current, '2.2' ) == -1 )
161 $this->upgrade_to_220();
162
163 if ( version_compare( $current, '2.3.1' ) == -1 )
164 $this->upgrade_to_231();
165
166 $success = true;
167 }
168
169 // Set our current version
170 update_option( 'redirection_version', $target );
171
172 $wpdb->hide_errors();
173 return $success;
174 }
175
176 function upgrade_to_231() {
177 global $wpdb;
178
179 $charset_collate = $this->get_charset();
180
181 $wpdb->query( "DELETE FROM {$wpdb->prefix}redirection_modules WHERE type='404'" );
182 $wpdb->query( "UPDATE {$wpdb->prefix}redirection_groups SET module_id=1 WHERE module_id=3" );
183
184 $wpdb->query( "CREATE TABLE `{$wpdb->prefix}redirection_404` (
185 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
186 `created` datetime NOT NULL,
187 `url` varchar(255) NOT NULL DEFAULT '',
188 `agent` varchar(255) DEFAULT NULL,
189 `referrer` varchar(255) DEFAULT NULL,
190 `ip` int(10) unsigned NOT NULL,
191 PRIMARY KEY (`id`),
192 KEY `created` (`created`),
193 KEY `url` (`url`),
194 KEY `ip` (`ip`,`id`),
195 KEY `referrer` (`referrer`)
196 ) $charset_collate;" );
197 }
198
199 function upgrade_from_20() {
200 global $wpdb;
201
202 $this->upgrade_from_21();
203 $this->upgrade_from_22();
204 }
205
206 function upgrade_from_21() {
207 global $wpdb;
208
209 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD `title` varchar(50) NULL" );
210
211 $this->upgrade_from_22();
212 }
213
214 function upgrade_from_22() {
215 global $wpdb;
216
217 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` CHANGE `title` `title` varchar(50) NULL" );
218 }
219
220 function upgrade_to_216() {
221 global $wpdb;
222
223 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_groups` ADD INDEX(module_id)" );
224 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_groups` ADD INDEX(status)" );
225 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX(url(200))" );
226 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX(status)" );
227 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX(regex)" );
228 }
229
230 function upgrade_to_220() {
231 global $wpdb;
232
233 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX `group_idpos` (`group_id`,`position`)" );
234 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX `group` (`group_id`)" );
235
236 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `group` (`group_id`)" );
237 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `redirection_id` (`redirection_id`)" );
238 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `created` (`created`)" );
239 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `ip` (`ip`)" );
240 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `group_id` (`group_id`)" );
241 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `module_id` (`module_id`)" );
242
243 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_modules` ADD INDEX `name` (`name`)" );
244 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_modules` ADD INDEX `type` (`type`)" );
245 }
246
247 function remove( $plugin ) {
248 global $wpdb;
249
250 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection;" );
251 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_items;" );
252 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_logs;" );
253 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_groups;" );
254 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_modules;" );
255 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_404;" );
256
257 delete_option( 'redirection_lookup' );
258 delete_option( 'redirection_post' );
259 delete_option( 'redirection_root' );
260 delete_option( 'redirection_index' );
261 delete_option( 'redirection_version' );
262
263 $current = get_option( 'active_plugins' );
264 array_splice( $current, array_search( basename( dirname( $plugin ) ).'/'.basename( $plugin ), $current ), 1 );
265 update_option( 'active_plugins', $current );
266 }
267 }
268