Coverting masspirates.org to https

From Mass Pirate Wiki
Revision as of 20:00, 1 May 2014 by Srevilak (talk | contribs) (initial revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Converting masspirates.org to https.

piratenkleider repair

Our wordpress theme stores a collection of attributes in the wp_options table. Here's a sample.

 localhost:masspirates_wp> select * from wp_options where option_id = 300067\G
 *************************** 1. row ***************************
    option_id: 300067
  option_name: theme_mods_piratenkleider
 option_value: a:4:{i:0;b:0;s:18:"nav_menu_locations";a:3:{s:7:"primary";i:0;s:3:"top";i:33;s:3:"sub";i:0;}s:12:"header_image";s:81:"http://masspiratesweb.mayfirst.org/blog/wp-content/uploads/2013/03/TabLogoF-1.png";s:17:"header_image_data";O:8:"stdClass":5:{s:13:"attachment_id";i:1301;s:3:"url";s:81:"http://masspiratesweb.mayfirst.org/blog/wp-content/uploads/2013/03/TabLogoF-1.png";s:13:"thumbnail_url";s:81:"http://masspiratesweb.mayfirst.org/blog/wp-content/uploads/2013/03/TabLogoF-1.png";s:6:"height";i:0;s:5:"width";i:0;}}
     autoload: yes
 1 row in set (0.00 sec)

These are serialized php objects, where strings are all length-prefixed. For example, s:6:"height"; means "string of six characters, which are 'height'". In this case, you can't simply edit the values -- you have to get the lengths right.

Do do this, you'll need to deserialize the php objects, dump them out, change the values, and then re-serialize. I did this with a semi-manual process, because we only had three options to change.

 <?php
 $text = 'a:4:{i:0;b:0;s:18:"nav_menu_locations";a:3:{s:7:"primary";i:0;s:3:"top";i:33;s:3:"sub";i:0;}s:12:"header_image";s:81:"http://masspiratesweb.mayfirst.org/blog/wp-content/uploads/2013/03/TabLogoF-1.png";s:17:"header_image_data";O:8:"stdClass":5:{s:13:"attachment_id";i:1301;s:3:"url";s:81:"http://masspiratesweb.mayfirst.org/blog/wp-content/uploads/2013/03/TabLogoF-1.png";s:13:"thumbnail_url";s:81:"http://masspiratesweb.mayfirst.org/blog/wp-content/uploads/2013/03/TabLogoF-1.png";s:6:"height";i:0;s:5:"width";i:0;}}';
 $obj = unserialize($text);
 var_export($obj);

This pretty prints the deserialized object. Given the pretty-printed copy, we can edit the values, and re-serialize.

 <?php
 $x = array (
   0 => false,
   'nav_menu_locations' => 
   array (
     'primary' => 0,
     'top' => 33,
     'sub' => 0,
   ),
   'header_image' => '/blog/wp-content/uploads/2013/03/TabLogoF-1.png',
   'header_image_data' => (object)
   array(
      'attachment_id' => 1301,
      'url' => '/blog/wp-content/uploads/2013/03/TabLogoF-1.png',
      'thumbnail_url' => '/blog/wp-content/uploads/2013/03/TabLogoF-1.png',
      'height' => 0,
      'width' => 0,
         ),
             );
 print serialize($x) . "\n";

Once we have the new serialized value, we update the wp_options table

 update wp_options
 set option_value = 'a:4:{i:0;b:0;s:18:"nav_menu_locations";a:3:{s:7:"primary";i:0;s:3:"top";i:33;s:3:"sub";i:0;}s:12:"header_image";s:47:"/blog/wp-content/uploads/2013/03/TabLogoF-1.png";s:17:"header_image_data";O:8:"stdClass":5:{s:13:"attachment_id";i:1301;s:3:"url";s:47:"/blog/wp-content/uploads/2013/03/TabLogoF-1.png";s:13:"thumbnail_url";s:47:"/blog/wp-content/uploads/2013/03/TabLogoF-1.png";s:6:"height";i:0;s:5:"width";i:0;}}'
 where option_id = 300067;

Then, repeat for the other values. These are the options that required changes

 +-----------+------------------------------------+
 | option_id | option_name                        |
 +-----------+------------------------------------+
 |    300067 | theme_mods_piratenkleider          |
 |    300082 | piratenkleider_theme_options       |
 |    300101 | piratenkleider_theme_defaultbilder |
 +-----------+------------------------------------+

I wasn't able to get the unserialize-modify-serialize trick to work with widget_text, so I think we'll have to modify that through the UI.

http://masspirates.org also appears in widget_text. I wasn't able to get that to deserialize, so we may have to fix it via the UI.

Updating the rest of the database

I decided not to do this.

I applied the changes to wordpress's wp_options table, and changed

  • Settings > General > Wordpress Address
  • Settings > General > Site URL

to https://masspirates.org/. Doing this much, wordpress seems to change http://masspirates.org links to https://masspirates.org. As long as wordpress does this, I'm not inclined to go through and rewrite the database.

When deploying the change, I noticed some bad interactions with Firefox and WP Super Cache (which I didn't notice on my development copy). Disabling WP Super Cache seemed to fix this.

TODO

Go through wordpress widgets, and change http: URLs to HTTPs