PluginProbe
Redirection / 4.0
Redirection v4.0
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 / database / schema / 400.php

400.php in Redirection 4.0, at database/schema/400.php

32 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Red_Database_400 extends Red_Database_Upgrader {
4 public function get_stages() {
5 return [
6 'add_match_url_400' => 'Add a matched URL column',
7 'add_redirect_data_400' => 'Add column to store new flags',
8 'convert_existing_urls_400' => 'Convert existing URLs to new format',
9 ];
10 }
11
12 protected function add_match_url_400( $wpdb ) {
13 $this->do_query( $wpdb, "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD `match_url` VARCHAR(2000) NULL DEFAULT NULL AFTER `url`" );
14 return $this->do_query( $wpdb, "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX `match_url` (`match_url`)" );
15 }
16
17 protected function add_redirect_data_400( $wpdb ) {
18 return $this->do_query( $wpdb, "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD `match_data` TEXT NULL DEFAULT NULL AFTER `match_url`" );
19 }
20
21 protected function convert_existing_urls_400( $wpdb ) {
22 // All regex get match_url=regex
23 $this->do_query( $wpdb, "UPDATE `{$wpdb->prefix}redirection_items` SET match_url='regex' WHERE regex=1" );
24
25 // Lowercase, trim trailing, and remove query params
26 $this->do_query( $wpdb, "UPDATE `{$wpdb->prefix}redirection_items` SET match_url=TRIM(TRAILING '/' FROM SUBSTRING_INDEX(LOWER(url), '?', 1)) WHERE regex=0" );
27
28 // Any URL that is now empty becomes /
29 return $this->do_query( $wpdb, "UPDATE `{$wpdb->prefix}redirection_items` SET match_url='/' WHERE match_url=''" );
30 }
31 }
32