Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
## script migration flutter a Magic fields
## version: 0.1.1
## author: Edgar G (hunk)
## this script is for migrate of flutter 1.1 to Magic Fields 1.2
global $wpdb;
// first change all references of the write panel (flutter) for reference of the write panel (magic fields)
$one = $wpdb->query("UPDATE $wpdb->postmeta SET meta_key = '_mf_write_panel_id' WHERE meta_key = '_rc_cwp_write_panel_id' ");
echo "changes reference of the write panels in postmeta <br />";
echo "number of changes: ".$one."<br />";
// array with names of tables flutter and Magic Fields
$tables = array();
$tables[$wpdb->prefix."rc_cwp_custom_field_options"] = $wpdb->prefix."mf_custom_field_options";
$tables[$wpdb->prefix."rc_cwp_custom_field_properties"] = $wpdb->prefix."mf_custom_field_properties";
$tables[$wpdb->prefix."rc_cwp_custom_field_types"] = $wpdb->prefix."mf_custom_field_types";
$tables[$wpdb->prefix."rc_cwp_module_groups"] = $wpdb->prefix."mf_module_groups";
$tables[$wpdb->prefix."rc_cwp_panel_category"] = $wpdb->prefix."mf_panel_category";
$tables[$wpdb->prefix."rc_cwp_panel_custom_field"] = $wpdb->prefix."mf_panel_custom_field";
$tables[$wpdb->prefix."rc_cwp_panel_standard_field"] = $wpdb->prefix."mf_panel_standard_field";
$tables[$wpdb->prefix."rc_cwp_post_meta"] = $wpdb->prefix."mf_post_meta";
$tables[$wpdb->prefix."rc_cwp_write_panels"] = $wpdb->prefix."mf_write_panels";
// changes names of table
foreach($tables as $k => $v){
$sql = "RENAME TABLE $k TO $v";
$table = $wpdb->query($sql);
if($table == 0){
echo "table migrate: ".$k." to ".$v." .............<b>correct</b><br />";
echo "table migrate: ".$k." to ".$v." .............error<br />";
//for version 1.2
$wpdb->query('ALTER TABLE '.$wpdb->prefix.'mf_panel_custom_field MODIFY display_order INTEGER');
$wpdb->query('ALTER TABLE '.$wpdb->prefix.'mf_panel_custom_field ADD COLUMN help_text text after duplicate');
$wpdb->query('ALTER TABLE '.$wpdb->prefix.'mf_write_panels MODIFY display_order INTEGER');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment