| 1 |
<?php |
| 2 |
|
| 3 |
class Red_Database_410 extends Red_Database_Upgrader { |
| 4 |
/** |
| 5 |
* @return array<string, string> |
| 6 |
*/ |
| 7 |
public function get_stages() { |
| 8 |
return [ |
| 9 |
'handle_double_slash' => 'Support double-slash URLs', |
| 10 |
]; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* @param \wpdb $wpdb |
| 15 |
* @return bool |
| 16 |
*/ |
| 17 |
protected function handle_double_slash( $wpdb ) { |
| 18 |
// Update any URL with a double slash at the end |
| 19 |
$this->do_query( $wpdb, "UPDATE `{$wpdb->prefix}redirection_items` SET match_url=LOWER(LEFT(SUBSTRING_INDEX(url, '?', 1),LENGTH(SUBSTRING_INDEX(url, '?', 1)) - 1)) WHERE RIGHT(SUBSTRING_INDEX(url, '?', 1), 2) = '//' AND regex=0" ); |
| 20 |
|
| 21 |
// Any URL that is now empty becomes / |
| 22 |
return $this->do_query( $wpdb, "UPDATE `{$wpdb->prefix}redirection_items` SET match_url='/' WHERE match_url=''" ); |
| 23 |
} |
| 24 |
} |
| 25 |
|