Skip to content
Snippets Groups Projects
Commit 3e722b9a authored by ale's avatar ale
Browse files

Refactor fix-https command

Previously "https-siteurl", a somewhat opaque name.
parent ee0aa42f
No related branches found
No related tags found
No related merge requests found
...@@ -58,7 +58,7 @@ Known commands: ...@@ -58,7 +58,7 @@ Known commands:
-mail sends email to ai-changes@investici.org -mail sends email to ai-changes@investici.org
-json print JSON output -json print JSON output
https-siteurl BLOG fix-https BLOG
Adds https (instead of http) to siteurl and home options. Adds https (instead of http) to siteurl and home options.
fix-cdn BLOG fix-cdn BLOG
...@@ -386,39 +386,32 @@ function do_check_updates($args) { ...@@ -386,39 +386,32 @@ function do_check_updates($args) {
} }
// replaces http with https, and removes ending slash
function add_https_to_uri($uri){
$re = "#^http[s]?://([^.]+\.noblogs\.org)[/]?$#i";
$subst = "https://$1";
return preg_replace($re,$subst,$uri);
}
// adds https to siteurl and home options (and also flattrs custom image) // adds https to siteurl and home options (and also flattrs custom image)
function do_https_siteurl($args){ function do_fix_https($args){
$field_to_update = array('home', 'siteurl', 'flattrss_custom_image_url'); $fields_to_update = array('home', 'siteurl', 'flattrss_custom_image_url');
foreach ($args as $arg) { foreach ($args as $arg) {
$blog = noblogs_get_blog($arg); $blog = noblogs_get_blog($arg);
if (!$blog) { if (!$blog) {
echo "Blog {$arg} not found.\n"; echo "Blog {$arg} not found.\n";
continue; continue;
} }
switch_to_blog($blog->blog_id); switch_to_blog($blog->blog_id);
foreach ($field_to_update as $field){
$old = get_option($field);
if ( $old === false ){
continue;
}
$new = add_https_to_uri($old);
if ($old === $new){
continue;
}
update_option($field,$new);
}
echo "{$arg}\n"; foreach ($fields_to_update as $field) {
restore_current_blog(); $old_value = get_option($field);
if ($old_value === false) {
continue;
}
$new_value = str_replace("http://", "https://", $old_value);
if ($old_value === $new_value){
continue;
}
update_option($field, $new_value);
} }
echo "{$arg}\n";
restore_current_blog();
}
} }
// rewrites the correct settings for the CDN // rewrites the correct settings for the CDN
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment