Created
May 30, 2018 18:29
-
-
Save timbuckingham/4e7404b2037f6f3d09fb952c64b57505 to your computer and use it in GitHub Desktop.
BigTree 2.x to 4.0 Upgrade Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]--> | |
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]--> | |
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]--> | |
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]--> | |
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]--> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>BigTree 2 to 4 Converter</title> | |
<link rel="stylesheet" href="<?=WWW_ROOT?>admin/css/main.css" type="text/css" media="all" /> | |
<script type="text/javascript" src="<?=WWW_ROOT?>admin/js/lib.js"></script> | |
<script type="text/javascript" src="<?=WWW_ROOT?>admin/js/main.js"></script> | |
</head> | |
<body class="install"> | |
<div class="install_wrapper"> | |
<h1>BigTree 2 to 4 Converter</h1> | |
<form method="post" action="" class="module"> | |
<h2 class="getting_started"><span></span>It's Magic</h2> | |
<? | |
set_time_limit(0); | |
ini_set("memory_limit","512M"); | |
function squery($query,$con) { | |
global $sqlerrors; | |
$q = mysql_query($query,$con); | |
$e = mysql_error($con); | |
if ($e) { | |
$sqlerrors[] = array("query" => $query, "error" => $e); | |
} | |
return $q; | |
} | |
if ($_POST["path"]) { | |
$path = $_POST["path"]; | |
$dm = $_POST["data_merge"]; | |
include $path."templates/config.php"; | |
// Connect to the old database | |
$oc = mysql_connect($config["db"]["host"],$config["db"]["user"],$config["db"]["password"],true); | |
mysql_query("SET NAMES 'utf8'",$oc); | |
mysql_select_db($config["db"]["name"],$oc); | |
// Connect to the new database | |
$nc = mysql_connect($bigtree["config"]["db"]["host"],$bigtree["config"]["db"]["user"],$bigtree["config"]["db"]["password"],true); | |
mysql_query("SET NAMES 'utf8'",$nc); | |
mysql_select_db($bigtree["config"]["db"]["name"],$nc); | |
// Route making functions | |
function getUniqueRoute($title,$table) { | |
global $oc,$nc,$cms; | |
$route = $cms->urlify($title); | |
$oroute = $route; | |
$x = 2; | |
while (mysql_num_rows(squery("SELECT * FROM `$table` WHERE route = '$route'",$nc))) { | |
$route = $oroute."-$x"; | |
$x++; | |
} | |
return $route; | |
} | |
if (!$dm) { | |
// Wipe every table in the new database | |
squery("DELETE FROM bigtree_404s",$nc); | |
squery("DELETE FROM bigtree_audit_trail",$nc); | |
squery("DELETE FROM bigtree_callouts",$nc); | |
squery("DELETE FROM bigtree_feeds",$nc); | |
squery("DELETE FROM bigtree_field_types",$nc); | |
squery("DELETE FROM bigtree_locks",$nc); | |
squery("DELETE FROM bigtree_messages",$nc); | |
squery("DELETE FROM bigtree_module_actions",$nc); | |
squery("DELETE FROM bigtree_module_forms",$nc); | |
squery("DELETE FROM bigtree_module_groups",$nc); | |
squery("DELETE FROM bigtree_module_view_cache",$nc); | |
squery("DELETE FROM bigtree_module_views",$nc); | |
squery("DELETE FROM bigtree_modules",$nc); | |
squery("DELETE FROM bigtree_page_revisions",$nc); | |
squery("DELETE FROM bigtree_pages",$nc); | |
squery("DELETE FROM bigtree_pending_changes",$nc); | |
squery("DELETE FROM bigtree_resource_folders",$nc); | |
squery("DELETE FROM bigtree_resources",$nc); | |
squery("DELETE FROM bigtree_route_history",$nc); | |
squery("DELETE FROM bigtree_settings",$nc); | |
squery("DELETE FROM bigtree_tags",$nc); | |
squery("DELETE FROM bigtree_tags_rel",$nc); | |
squery("DELETE FROM bigtree_templates",$nc); | |
squery("DELETE FROM bigtree_users",$nc); | |
} | |
// Start tracking user permissions | |
$user_permissions = array(); | |
$page_permissions = array(); | |
// Start with Module Groups, then work our way in to preservef oreign key associations in BigTree 4. | |
$q = squery("SELECT * FROM bigtree_module_groups",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
$route = getUniqueRoute($f["name"],"bigtree_module_groups"); | |
squery("INSERT INTO bigtree_module_groups (`id`,`name`,`route`,`position`) VALUES ($id,$name,'$route',$position)",$nc); | |
} | |
// Modules | |
$q = squery("SELECT * FROM bigtree_modules",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
if (!$f["group"]) { | |
$group = "NULL"; | |
} | |
squery("INSERT INTO bigtree_modules (`id`,`group`,`name`,`route`,`class`,`position`) VALUES ($id,$group,$name,$route,$class,$position)",$nc); | |
} | |
// Module Actions | |
$q = squery("SELECT * FROM bigtree_module_actions",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
if ($f["route"] == "add" && $f["in_nav"]) { | |
$class = "add"; | |
} elseif ($f["in_nav"]) { | |
$class = "list"; | |
} | |
$form = "NULL"; | |
$view = "NULL"; | |
if ($f["auto"]) { | |
list($action,$action_id) = explode("#",$f["auto"]); | |
if ($action == "form") { | |
$form = $action_id; | |
} else { | |
$view = $action_id; | |
} | |
} | |
squery("INSERT INTO bigtree_module_actions (`id`,`module`,`name`,`route`,`in_nav`,`form`,`view`,`class`,`position`) VALUES ($id,$module,$name,$route,$in_nav,$form,$view,'$class',$position)",$nc); | |
} | |
// Module Forms | |
$q = squery("SELECT * FROM bigtree_module_forms",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
// Switch old field types to new ones and make the image/upload/photo galleries append their path. | |
$fields = unserialize($f["fields"]); | |
$fields_to_update = array(); | |
foreach ($fields as $key => &$field) { | |
// BigTree 2 exclusive | |
if ($field["type"] == "upload_thumb") { | |
$field["type"] = "upload"; | |
$field["image"] = "on"; | |
if ($field["thumbnail_width"]) { | |
$field["thumbs"] = array( | |
array("width" => $field["width"],"height" => $field["height"]), | |
array("prefix" => ltrim($field["thumbnail_suffix"],"_")."_","width" => $field["thumbnail_width"],"height" => $field["thumbnail_height"]) | |
); | |
} else { | |
$field["thumbs"] = array( | |
array("width" => $field["width"],"height" => $field["height"]) | |
); | |
} | |
$fields_to_update[$key] = "{staticroot}".$field["directory"]; | |
// BigTree 2 exclusive | |
} elseif ($field["type"] == "upload_crop") { | |
$field["type"] = "upload"; | |
$field["image"] = "on"; | |
if ($field["thumbnail_width"]) { | |
$thumbs = array("prefix" => ltrim($field["thumbnail_suffix"],"_")."_","width" => $field["thumbnail_width"],"height" => $field["thumbnail_height"]); | |
} else { | |
$thumbs = array(); | |
} | |
$field["crops"] = array( | |
array("width" => $field["width"],"height" => $field["height"],"thumbs" => $thumbs) | |
); | |
$fields_to_update[$key] = "{staticroot}".$field["directory"]; | |
// BigTree 2 exclusive | |
} elseif ($field["type"] == "state") { | |
$field["type"] = "list"; | |
$field["list_type"] = "state"; | |
// BigTree 2 exclusive | |
} elseif ($field["type"] == "country") { | |
$field["type"] = "list"; | |
$field["list_type"] = "country"; | |
} elseif ($field["type"] == "image") { | |
$field["type"] = "upload"; | |
$field["image"] = "on"; | |
$fields_to_update[$key] = "{staticroot}".$field["directory"]; | |
} elseif ($field["type"] == "upload") { | |
$fields_to_update[$key] = "{staticroot}".$field["directory"]; | |
} elseif ($field["type"] == "photo-gallery") { | |
$field = array( | |
"type" => "photo-gallery", | |
"min_width" => $field["width"], | |
"min_height" => $field["height"], | |
"title" => $field["title"], | |
"crops" => array(array("width" => $field["width"],"height" => $field["height"])), | |
"directory" => $field["directory"] | |
); | |
$fields_to_update[$key] = array("prefix" => "{staticroot}".$field["directory"]); | |
} elseif ($field["type"] == "simplehtml") { | |
$field["type"] = "html"; | |
$field["simple"] = "on"; | |
} elseif ($field["type"] == "poplist") { | |
$field["type"] = "list"; | |
$field["list_type"] = "db"; | |
$popsort = explode(" ",$field["pop-sort"]); | |
$field["pop-sort"] = "`".$popsort[0]."` ".strtoupper($popsort[1]); | |
} elseif ($field["type"] == "list") { | |
$field["list_type"] == "static"; | |
$good_list = array(); | |
foreach ($field["list"] as $k => $v) { | |
$good_list[] = array("value" => $k,"description" => $v); | |
} | |
$field["list"] = $good_list; | |
} elseif ($field["type"] == "many_to_many") { | |
$field["type"] = "many-to-many"; | |
// Create the connecting table. | |
squery("DROP TABLE IF EXISTS `".$field["mtm-connecting-table"]."`",$nc); | |
$show = mysql_fetch_assoc(squery("SHOW CREATE TABLE `".$field["mtm-connecting-table"]."`",$oc)); | |
squery($show["Create Table"],$nc); | |
$qq = squery("SELECT * FROM `".$field["mtm-connecting-table"]."`",$oc); | |
while ($ff = mysql_fetch_assoc($qq)) { | |
$keys = array(); | |
$vals = array(); | |
foreach ($ff as $key => $val) { | |
$keys[] = "`".$key."`"; | |
$vals[] = "'".mysql_real_escape_string($val)."'"; | |
} | |
squery("INSERT INTO `".$field["mtm-connecting-table"]."` (".implode(",",$keys).") VALUES (".implode(",",$vals).")",$nc); | |
} | |
} | |
} | |
$fields = mysql_real_escape_string(json_encode($fields)); | |
$positioning = mysql_real_escape_string(json_encode(unserialize($f["positioning"]))); | |
squery("INSERT INTO bigtree_module_forms (`id`,`title`,`table`,`fields`,`positioning`) VALUES ($id,$title,$table,'$fields','$positioning')",$nc); | |
// Loop through table to update file paths. | |
squery("DROP TABLE IF EXISTS `".$f["table"]."`",$nc); | |
$show = mysql_fetch_assoc(squery("SHOW CREATE TABLE `".$f["table"]."`",$oc)); | |
squery($show["Create Table"],$nc); | |
$qq = squery("SELECT * FROM `".$f["table"]."`",$oc); | |
while ($ff = mysql_fetch_assoc($qq)) { | |
$keys = array(); | |
$vals = array(); | |
foreach ($ff as $key => $val) { | |
$keys[] = "`".$key."`"; | |
$is_array = @unserialize($val); | |
if ($fields_to_update[$key]) { | |
if (is_array($fields_to_update[$key])) { | |
$val = unserialize($val); | |
if (is_array($val)) { | |
foreach ($val as &$piece) { | |
if ($piece["image"]) { | |
$piece["image"] = $fields_to_update[$key]["prefix"].$piece["image"]; | |
} | |
} | |
} | |
$vals[] = "'".mysql_real_escape_string(json_encode($val))."'"; | |
} else { | |
if ($val) { | |
$vals[] = "'".mysql_real_escape_string($fields_to_update[$key].$val)."'"; | |
} else { | |
$vals[] = "''"; | |
} | |
} | |
} elseif (is_array($is_array)) { | |
$vals[] = "'".mysql_real_escape_string(json_encode($is_array))."'"; | |
} else { | |
$vals[] = "'".mysql_real_escape_string($val)."'"; | |
} | |
} | |
squery("INSERT INTO `".$f["table"]."` (".implode(",",$keys).") VALUES (".implode(",",$vals).")",$nc); | |
} | |
} | |
// Module Views | |
$q = squery("SELECT * FROM bigtree_module_views",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
$options = unserialize($f["options"]); | |
$columns = unserialize($f["columns"]); | |
$fields = array(); | |
if (is_array($columns)) { | |
foreach ($columns as $k => $t) { | |
$fields[$k] = array("title" => $t); | |
} | |
} | |
$actions = unserialize($f["actions"]); | |
$clean_actions = array(); | |
if (is_array($actions)) { | |
foreach ($actions as $key => $val) { | |
$clean_actions[$val] = "on"; | |
} | |
} | |
$actions = mysql_real_escape_string(json_encode($clean_actions)); | |
// Draggable group doesn't exist anymore. | |
if ($type == "'draggable-group'") { | |
$type = "'grouped'"; | |
$options["draggable"] = "on"; | |
$options["ot_sort_field"] = $options["group_descriptor"]; | |
$options["ot_sort_direction"] = "ASC"; | |
$options["other_table"] = $options["group_table"]; | |
$options["title_field"] = $options["group_descriptor"]; | |
} | |
// Searchable type has different sorting now. | |
if ($type == "'searchable'" || $type == "'sortable'") { | |
$type = "'searchable'"; | |
if ($options["sort_column"]) { | |
if ($options["sort_direction"] == "SORT_DESC") { | |
$options["sort"] = "`".$options["sort_column"]."` DESC"; | |
} else { | |
$options["sort"] = "`".$options["sort_column"]."` ASC"; | |
} | |
} | |
unset($options["sort_column"]); | |
unset($options["sort_directions"]); | |
} | |
if ($type == "'images-group'") { | |
$type = "'images-grouped'"; | |
$options = array( | |
"draggable" => $options["image_grouped_draggable"], | |
"image" => $options["image_grouped_field"], | |
"group_field" => $options["image_group_field"], | |
"other_table" => $options["image_group_table"], | |
"title_field" => $options["image_group_descriptor"], | |
"sort" => "`id` DESC" | |
); | |
} | |
if ($type == "'images'") { | |
$options = array( | |
"image" => $options["image_list_field"], | |
"sort" => "`id` DESC" | |
); | |
} | |
$fields = mysql_real_escape_string(json_encode($fields)); | |
$options = mysql_real_escape_string(json_encode($options)); | |
squery("INSERT INTO bigtree_module_views (`id`,`title`,`description`,`type`,`table`,`fields`,`options`,`actions`,`suffix`) VALUES ($id,$title,$description,$type,$table,'$fields','$options','$actions',$suffix)",$nc); | |
} | |
// Callouts | |
$q = squery("SELECT * FROM bigtree_sidelets",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
$resources = unserialize($f["resources"]); | |
if (is_array($resources)) { | |
foreach ($resources as &$resource) { | |
$resource["title"] = $resource["name"]; | |
unset($resource["name"]); | |
// BigTree 2 exclusive | |
if ($resource["type"] == "upload_thumb") { | |
$resource["type"] = "upload"; | |
$resource["image"] = "on"; | |
if ($resource["thumbnail_width"]) { | |
$resource["thumbs"] = array( | |
array("width" => $resource["width"],"height" => $resource["height"]), | |
array("prefix" => ltrim($resource["thumbnail_suffix"],"_")."_","width" => $resource["thumbnail_width"],"height" => $resource["thumbnail_height"]) | |
); | |
} else { | |
$resource["thumbs"] = array( | |
array("width" => $resource["width"],"height" => $resource["height"]) | |
); | |
} | |
$resources_to_update[$key] = "{staticroot}files/pages/"; | |
// BigTree 2 exclusive | |
} elseif ($resource["type"] == "upload_crop") { | |
$resource["type"] = "upload"; | |
$resource["image"] = "on"; | |
if ($resource["thumbnail_width"]) { | |
$thumbs = array("prefix" => ltrim($resource["thumbnail_suffix"],"_")."_","width" => $resource["thumbnail_width"],"height" => $resource["thumbnail_height"]); | |
} else { | |
$thumbs = array(); | |
} | |
$resource["crops"] = array( | |
array("width" => $resource["width"],"height" => $resource["height"],"thumbs" => $thumbs) | |
); | |
$resources_to_update[$key] = "{staticroot}files/pages/"; | |
// BigTree 2 exclusive | |
} elseif ($resource["type"] == "state") { | |
$resource["type"] = "list"; | |
$resource["list_type"] = "state"; | |
// BigTree 2 exclusive | |
} elseif ($resource["type"] == "country") { | |
$resource["type"] = "list"; | |
$resource["list_type"] = "country"; | |
} elseif ($resource["type"] == "image") { | |
$resource["type"] = "upload"; | |
$resource["image"] = "on"; | |
$resources_to_update[$key] = "{staticroot}files/pages/"; | |
} elseif ($resource["type"] == "upload") { | |
$resources_to_update[$key] = "{staticroot}files/pages/"; | |
} elseif ($resource["type"] == "photo-gallery") { | |
$resource = array( | |
"id" => $resource["id"], | |
"type" => "photo-gallery", | |
"min_width" => $resource["width"], | |
"min_height" => $resource["height"], | |
"title" => $resource["title"], | |
"crops" => array(array("width" => $resource["width"],"height" => $resource["height"])) | |
); | |
$resources_to_update[$key] = array("prefix" => "{staticroot}files/pages/"); | |
} elseif ($resource["type"] == "simplehtml") { | |
$resource["type"] = "html"; | |
$resource["simple"] = "on"; | |
} elseif ($resource["type"] == "poplist") { | |
$resource["type"] = "list"; | |
$resource["list_type"] = "db"; | |
$popsort = explode(" ",$resource["pop-sort"]); | |
$resource["pop-sort"] = "`".$popsort[0]."` ".strtoupper($popsort[1]); | |
} elseif ($resource["type"] == "list") { | |
$resource["list_type"] == "static"; | |
$good_list = array(); | |
foreach ($resource["list"] as $k => $v) { | |
$good_list[] = array("value" => $k,"description" => $v); | |
} | |
$resource["list"] = $good_list; | |
} | |
} | |
} | |
unset($resource); | |
$resources = mysql_real_escape_string(json_encode($resources)); | |
squery("INSERT INTO bigtree_callouts (`id`,`name`,`description`,`resources`,`position`,`display_default`) VALUES ($id,$title,$description,'$resources',$position,'-')",$nc); | |
} | |
// Pages | |
function pageLoop($parent,$tree_permissions = array()) { | |
global $user_permissions,$oc,$nc; | |
$q = squery("SELECT * FROM bigtree_pages WHERE parent = '$parent'",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
$resources = unserialize($f["resources"]); | |
$publish_at = $f["publish_at"] ? "'".$f["publish_at"]."'" : "NULL"; | |
// We need to find out about this template and change its file paths in the resources. | |
$tdata = mysql_fetch_assoc(squery("SELECT * FROM bigtree_templates WHERE id = '".$f["template"]."'",$oc)); | |
if ($tdata) { | |
$tres = unserialize($tdata["resources"]); | |
if (is_array($tres)) { | |
foreach ($tres as $field) { | |
$key = $field["id"]; | |
if ($field["type"] == "upload" || $field["type"] == "image") { | |
if ($resources[$key]) { | |
$resources[$key] = "{staticroot}files/pages/".$resources[$key]; | |
} | |
} elseif ($field["type"] == "photo-gallery") { | |
$gallery = array(); | |
$array = is_array($resources[$key]) ? $resources[$key] : unserialize($resources[$key]); | |
if (is_array($array)) { | |
foreach ($array as $item) { | |
$gallery[] = array("image" => "{staticroot}files/pages/".$item["image"], "caption" => $item["caption"]); | |
} | |
} | |
$resources[$key] = json_encode($gallery); | |
} | |
// Test if the value was serialized | |
$test = @unserialize($resources[$key]); | |
if (is_array($test)) { | |
$resources[$key] = $test; | |
} | |
} | |
} | |
} | |
$resources = mysql_real_escape_string(json_encode($resources)); | |
$callouts = unserialize($f["sidebar"]); | |
if (is_array($callouts)) { | |
foreach ($callouts as &$callout) { | |
// We need to find out about this callout and change its file paths in the resources. | |
$tdata = mysql_fetch_assoc(squery("SELECT * FROM bigtree_callouts WHERE id = '".$callout["type"]."'",$nc)); | |
if ($tdata) { | |
$tres = json_decode($tdata["resources"],true); | |
if (is_array($tres)) { | |
foreach ($tres as $field) { | |
$key = $field["id"]; | |
if ($field["type"] == "upload" || $field["type"] == "image") { | |
if ($callout[$key]) { | |
$callout[$key] = "{staticroot}files/pages/".$callout[$key]; | |
} | |
} elseif ($field["type"] == "photo-gallery") { | |
$gallery = array(); | |
$array = unserialize($callout[$key]); | |
if (is_array($array)) { | |
foreach ($array as $item) { | |
$gallery[] = array("image" => "{staticroot}files/pages/".$item["image"], "caption" => $item["caption"]); | |
} | |
} | |
$callout[$key] = json_encode($gallery); | |
} | |
// Test if the value was serialized | |
$test = @unserialize($callout[$key]); | |
if (is_array($test)) { | |
$callout[$key] = $test; | |
} | |
} | |
} | |
} | |
} | |
} | |
unset($callout); | |
$callouts = mysql_real_escape_string(json_encode($callouts)); | |
squery("INSERT INTO bigtree_pages (`id`,`parent`,`in_nav`,`nav_title`,`route`,`title`,`meta_keywords`,`meta_description`,`template`,`external`,`new_window`,`resources`,`callouts`,`archived`,`position`,`created_at`,`updated_at`,`publish_at`) VALUES ($id,$parent,$in_nav,$nav_title,$route,$title,$meta_keywords,$meta_description,$template,$external,$new_window,'$resources','$callouts',$archived,$position,NOW(),NOW(),$publish_at)",$nc); | |
if ($f["id"] == "0") { | |
squery("UPDATE bigtree_pages SET id = '0', route = '', path = '' WHERE id = '".mysql_insert_id($nc)."'",$nc); | |
} | |
$permissions = unserialize($f["permissions"]); | |
foreach ($tree_permissions as $user => $perm) { | |
$user_permissions[$user]["page"][$f["id"]] = "n"; | |
} | |
if (is_array($permissions)) { | |
foreach ($permissions as $user => $p) { | |
// Permissions types are either "p" for a single page, in which case all of the subsequent pages should be a "n" unless somewhere along the line a "t" gets in. | |
// If a user gets a "t" then all of the subsequent pages should be "i" or nothing at all. There was no way to explicitly remove permissions for a page under a tree grant in BigTree 3. | |
$user_permissions[$user]["page"][$f["id"]] = $p["level"]; | |
if ($p["type"] == "p") { | |
$tree_permissions[$user] = true; | |
} elseif ($p["type"] == "t") { | |
unset($tree_permissions[$user]); | |
} | |
} | |
} | |
pageLoop($f["id"],$tree_permissions); | |
} | |
} | |
pageLoop(-1); | |
// Settings | |
$q = squery("SELECT * FROM bigtree_settings",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
$value = mysql_real_escape_string(json_encode($f["value"])); | |
if ($type == "'number'") { | |
$type = "'text'"; | |
} | |
if ($description != "''") { | |
$description = "'".mysql_real_escape_string("<p>".$f["description"]."</p>")."'"; | |
} | |
squery("INSERT INTO bigtree_settings (`id`,`value`,`type`,`name`,`description`) VALUES ($id,'$value',$type,$title,$description)",$nc); | |
} | |
// Templates | |
$q = squery("SELECT * FROM bigtree_templates",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
$resources = unserialize($f["resources"]); | |
foreach ($resources as &$resource) { | |
$resource["title"] = $resource["name"]; | |
unset($resource["name"]); | |
// BigTree 2 exclusive | |
if ($resource["type"] == "upload_thumb") { | |
$resource["type"] = "upload"; | |
$resource["image"] = "on"; | |
if ($resource["thumbnail_width"]) { | |
$resource["thumbs"] = array( | |
array("width" => $resource["width"],"height" => $resource["height"]), | |
array("prefix" => ltrim($resource["thumbnail_suffix"],"_")."_","width" => $resource["thumbnail_width"],"height" => $resource["thumbnail_height"]) | |
); | |
} else { | |
$resource["thumbs"] = array( | |
array("width" => $resource["width"],"height" => $resource["height"]) | |
); | |
} | |
$resources_to_update[$key] = "{staticroot}files/pages/"; | |
// BigTree 2 exclusive | |
} elseif ($resource["type"] == "upload_crop") { | |
$resource["type"] = "upload"; | |
$resource["image"] = "on"; | |
if ($resource["thumbnail_width"]) { | |
$thumbs = array("prefix" => ltrim($resource["thumbnail_suffix"],"_")."_","width" => $resource["thumbnail_width"],"height" => $resource["thumbnail_height"]); | |
} else { | |
$thumbs = array(); | |
} | |
$resource["crops"] = array( | |
array("width" => $resource["width"],"height" => $resource["height"],"thumbs" => $thumbs) | |
); | |
$resources_to_update[$key] = "{staticroot}files/pages/"; | |
// BigTree 2 exclusive | |
} elseif ($resource["type"] == "state") { | |
$resource["type"] = "list"; | |
$resource["list_type"] = "state"; | |
// BigTree 2 exclusive | |
} elseif ($resource["type"] == "country") { | |
$resource["type"] = "list"; | |
$resource["list_type"] = "country"; | |
} elseif ($resource["type"] == "image") { | |
$resource["type"] = "upload"; | |
$resource["image"] = "on"; | |
$resources_to_update[$key] = "{staticroot}files/pages/"; | |
} elseif ($resource["type"] == "upload") { | |
$resources_to_update[$key] = "{staticroot}files/pages/"; | |
} elseif ($resource["type"] == "photo-gallery") { | |
$resource = array( | |
"id" => $resource["id"], | |
"type" => "photo-gallery", | |
"min_width" => $resource["width"], | |
"min_height" => $resource["height"], | |
"title" => $resource["title"], | |
"crops" => array(array("width" => $resource["width"],"height" => $resource["height"])) | |
); | |
$resources_to_update[$key] = array("prefix" => "{staticroot}files/pages"); | |
} elseif ($resource["type"] == "simplehtml") { | |
$resource["type"] = "html"; | |
$resource["simple"] = "on"; | |
} elseif ($resource["type"] == "poplist") { | |
$resource["type"] = "list"; | |
$resource["list_type"] = "db"; | |
$popsort = explode(" ",$resource["pop-sort"]); | |
$resource["pop-sort"] = "`".$popsort[0]."` ".strtoupper($popsort[1]); | |
} elseif ($resource["type"] == "list") { | |
$resource["list_type"] == "static"; | |
$good_list = array(); | |
foreach ($resource["list"] as $k => $v) { | |
$good_list[] = array("value" => $k,"description" => $v); | |
} | |
$resource["list"] = $good_list; | |
} | |
} | |
unset($resource); | |
$resources = mysql_real_escape_string(json_encode($resources)); | |
// Figure out if it's routed | |
if (substr($f["id"],0,7) == "module-") { | |
$routed = "on"; | |
$id = "'".substr($f["id"],7)."'"; | |
mysql_query("UPDATE bigtree_pages SET template = $id WHERE template = '".$f["id"]."'"); | |
} else { | |
$routed = ""; | |
} | |
// Figure out what module it is. | |
$f = mysql_fetch_assoc(squery("SELECT * FROM bigtree_modules WHERE route = $module",$nc)); | |
if ($f) { | |
$module = "'".$f["id"]."'"; | |
} else { | |
$module = "'0'"; | |
} | |
if ($image == "'page_module.jpg'") { | |
$image = "'page-module.png'"; | |
} else { | |
$image = "'page-blank.png'"; | |
} | |
squery("INSERT INTO bigtree_templates (`id`,`name`,`description`,`routed`,`image`,`resources`,`callouts_enabled`,`module`,`position`) VALUES ($id,$name,$description,'$routed',$image,'$resources','on',$module,$position)",$nc); | |
} | |
// Users | |
$q = squery("SELECT * FROM bigtree_users",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
$module_permissions = unserialize($f["permissions"]); | |
$user_permissions[$f["id"]]["module"] = $module_permissions; | |
$permissions = "'".mysql_real_escape_string(json_encode($user_permissions[$f["id"]]))."'"; | |
$digest = isset($f["digest"]) ? "'".mysql_real_escape_string($f["digest"])."'" : "''"; | |
squery("INSERT INTO bigtree_users (`id`,`email`,`name`,`company`,`level`,`permissions`,`daily_digest`) VALUES ($id,$email,$name,$company,$level,$permissions,$digest)",$nc); | |
} | |
// Insert deathstar@fastspot.com user | |
squery("INSERT INTO bigtree_users (`email`,`name`,`company`,`level`,`password`) VALUES ('deathstar@fastspot.com','Developer','Fastspot','2','".'$P$BUjyVXaNe'.".P3ZxuS.0UmMXvjYF/QoO.')",$nc); | |
// Pending Changes | |
$q = squery("SELECT * FROM bigtree_pending_changes",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = "'".mysql_real_escape_string($val)."'"; | |
} | |
$comments = mysql_real_escape_string(json_encode(unserialize($f["comments"]))); | |
$changes = mysql_real_escape_string(json_encode(unserialize($f["changes"]))); | |
$mtm_changes = mysql_real_escape_string(json_encode(unserialize($f["mtm_changes"]))); | |
$tags_changes = mysql_real_escape_string(json_encode(unserialize($f["tags_changes"]))); | |
squery("INSERT INTO bigtree_pending_changes (`id`,`user`,`date`,`title`,`comments`,`table`,`changes`,`mtm_changes`,`tags_changes`,`item_id`,`type`,`module`,`pending_page_parent`) VALUES ($id,$user,$date,$title,'$comments',$table,'$changes','$mtm_changes','$tags_changes',$item_id,$type,$module,$pending_page_parent)",$nc); | |
} | |
// Fix Page "path"s | |
@$admin = new BigTreeAdmin; | |
$q = mysql_query("SELECT * FROM bigtree_pages",$nc); | |
while ($f = mysql_fetch_assoc($q)) { | |
$path = "'".mysql_real_escape_string($admin->getFullNavigationPath($f["id"]))."'"; | |
mysql_query("UPDATE bigtree_pages SET path = $path WHERE id = '".$f["id"]."'",$nc); | |
} | |
// Set Page 0 to be the _home template, even if it doesn't exist. | |
mysql_query("UPDATE bigtree_pages SET template = 'home', path = '', route = '' WHERE id = 0",$nc); | |
// Copy directories | |
function recursiveCopyDir($from,$to) { | |
$d = opendir($from); | |
while ($r = readdir($d)) { | |
if ($r != "." && $r != "..") { | |
if (is_dir($from.$r)) { | |
@mkdir($to.$r); | |
@chmod($to.$r,0777); | |
recursiveCopyDir($from.$r."/",$to.$r."/"); | |
} else { | |
@copy($from.$r,$to.$r); | |
@chmod($to.$r,0777); | |
} | |
} | |
} | |
} | |
if (isset($_POST["copy_files"]) && $_POST["copy_files"]) { | |
$path = $_POST["path"]; | |
recursiveCopyDir($path."templates/pages/",SERVER_ROOT."templates/basic/"); | |
recursiveCopyDir($path."templates/modules/",SERVER_ROOT."templates/routed/"); | |
recursiveCopyDir($path."templates/sidelets/",SERVER_ROOT."templates/callouts/"); | |
recursiveCopyDir($path."templates/ajax/",SERVER_ROOT."templates/ajax/"); | |
recursiveCopyDir($path."templates/layouts/",SERVER_ROOT."templates/layouts/"); | |
recursiveCopyDir($path."custom/",SERVER_ROOT."custom/"); | |
recursiveCopyDir($path."site/css/",SERVER_ROOT."site/css/"); | |
recursiveCopyDir($path."site/js/",SERVER_ROOT."site/js/"); | |
recursiveCopyDir($path."site/swf/",SERVER_ROOT."site/swf/"); | |
recursiveCopyDir($path."site/files/",SERVER_ROOT."site/files/"); | |
recursiveCopyDir($path."site/images/",SERVER_ROOT."site/images/"); | |
recursiveCopyDir($path."site/fonts/",SERVER_ROOT."site/fonts/"); | |
} | |
@unlink(SERVER_ROOT."cache/module-class-list.btc"); | |
@unlink(SERVER_ROOT."cache/form-field-types.btc"); | |
// Do stuff to Form builder if it exists. | |
$q = mysql_query("SELECT * FROM bigtree_templates WHERE id = 'module-formbuilder'",$oc); | |
if (mysql_num_rows($q)) { | |
// Create the new tables | |
mysql_query("DROP TABLE IF EXISTS `btx_form_builder_forms`",$nc); | |
mysql_query("CREATE TABLE `btx_form_builder_forms` (`id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `paid` char(2) COLLATE utf8_bin NOT NULL DEFAULT '', `base_price` float NOT NULL, `early_bird_base_price` float NOT NULL, `early_bird_date` datetime DEFAULT NULL, `total_collected` float NOT NULL, `entries` int(11) NOT NULL, `limit_entries` char(2) COLLATE utf8_bin NOT NULL DEFAULT '', `max_entries` int(11) NOT NULL, `last_entry` datetime DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;",$nc); | |
mysql_query("DROP TABLE IF EXISTS `btx_form_builder_fields`",$nc); | |
mysql_query("CREATE TABLE `btx_form_builder_fields` (`id` int(11) NOT NULL AUTO_INCREMENT, `form` int(11) NOT NULL, `column` int(11) NOT NULL, `alignment` char(5) COLLATE utf8_bin NOT NULL, `type` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '', `data` longtext COLLATE utf8_bin NOT NULL, `position` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `form` (`form`), KEY `column` (`column`), KEY `position` (`position`), CONSTRAINT `btx_form_builder_fields_ibfk_1` FOREIGN KEY (`form`) REFERENCES `btx_form_builder_forms` (`id`) ON DELETE CASCADE | |
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;",$nc); | |
mysql_query("DROP TABLE IF EXISTS `btx_form_builder_entries`",$nc); | |
mysql_query("CREATE TABLE `btx_form_builder_entries` (`id` int(11) NOT NULL AUTO_INCREMENT, `form` int(11) NOT NULL, `data` longtext COLLATE utf8_bin NOT NULL, `created_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`id`), KEY `form` (`form`), CONSTRAINT `btx_form_builder_entries_ibfk_1` FOREIGN KEY (`form`) REFERENCES `btx_form_builder_forms` (`id`) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;",$nc); | |
// Copy from the old forms table. | |
$q = mysql_query("SELECT * FROM plugin_formbuilder_forms",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = mysql_real_escape_string($val); | |
} | |
mysql_query("INSERT INTO btx_form_builder_forms (`id`,`title`,`entries`) VALUES ('$id','$title','$entries')",$nc); | |
} | |
// Copy from old fields table. | |
$q = mysql_query("SELECT * FROM plugin_formbuilder_form_fields",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = mysql_real_escape_string($val); | |
} | |
$data = mysql_real_escape_string(json_encode(unserialize($f["data"]))); | |
mysql_query("INSERT INTO btx_form_builder_fields (`id`,`form`,`column`,`type`,`data`,`position`) VALUES ('$id','$form','$column','$type','$data','$position')",$nc); | |
} | |
// Copy from old entries table. | |
$q = mysql_query("SELECT * FROM plugin_formbuilder_entries",$oc); | |
while ($f = mysql_fetch_assoc($q)) { | |
foreach ($f as $key => $val) { | |
$$key = mysql_real_escape_string($val); | |
} | |
$data = mysql_real_escape_string(json_encode(unserialize($f["data"]))); | |
mysql_query("INSERT INTO btx_form_builder_entries (`id`,`form`,`data`,`created_at`) VALUES ('$id','$form','$data','$created_at')",$nc); | |
} | |
// Rename the template and module names. | |
mysql_query("UPDATE bigtree_templates SET id = 'btx-form-builder' WHERE id = 'formbuilder'",$nc); | |
mysql_query("UPDATE bigtree_pages SET template = 'btx-form-builder' WHERE template = 'formbuilder'",$nc); | |
mysql_query("UPDATE bigtree_modules SET route = 'btx-form-builder', class = 'BTXFormBuilder' WHERE route = 'form-builder'",$nc); | |
mysql_query("DELETE FROM bigtree_modules WHERE route = 'form-builder-entries'",$nc); | |
// Figure out the current module and empty / repop it's actions and such. | |
$current = mysql_fetch_assoc(mysql_query("SELECT * FROM bigtree_modules WHERE route = 'btx-form-builder'",$nc)); | |
mysql_query("DELETE FROM bigtree_module_actions WHERE module = '".$current["id"]."'",$nc); | |
// Create the view | |
mysql_query("INSERT INTO `bigtree_module_views` (`title`, `description`, `type`, `table`, `fields`, `options`, `actions`, `suffix`, `preview_url`) VALUES (X'466F726D73', X'', X'73656172636861626C65', X'6274785F666F726D5F6275696C6465725F666F726D73', X'7B227469746C65223A7B227769647468223A22313933222C227469746C65223A225469746C65222C22706172736572223A22227D2C22656E7472696573223A7B227769647468223A22313933222C227469746C65223A22456E7472696573222C22706172736572223A22227D2C226C6173745F656E747279223A7B227769647468223A22313933222C227469746C65223A224C61737420456E747279222C22706172736572223A22696620282476616C756529207B202476616C7565203D2064617465285C2246206A204020673A69615C222C737472746F74696D65282476616C756529293B207D227D7D', X'7B22736F72745F636F6C756D6E223A227469746C65222C22736F72745F646972656374696F6E223A22415343222C227065725F70616765223A223135222C2266696C746572223A22227D', X'7B226578706F7274223A227B5C226E616D655C223A5C224578706F72745C222C5C22636C6173735C223A5C2269636F6E5F6578706F72745C222C5C22726F7574655C223A5C226578706F72745C222C5C2266756E6374696F6E5C223A5C225C227D222C22656E7472696573223A227B5C226E616D655C223A5C22456E74726965735C222C5C22636C6173735C223A5C2269636F6E5F766965775C222C5C22726F7574655C223A5C22656E74726965735C222C5C2266756E6374696F6E5C223A5C225C227D222C2265646974223A226F6E222C2264656C657465223A226F6E227D', X'', X'')",$nc); | |
$view_id = mysql_insert_id($nc); | |
// Add the actions. | |
mysql_query("INSERT INTO `bigtree_module_actions` (`module`, `name`, `route`, `in_nav`, `form`, `view`, `class`, `level`, `position`) VALUES (".$current["id"].", X'5669657720466F726D73', X'', X'6F6E', 0, $view_id, X'6C697374', 0, 3), (".$current["id"].", X'41646420466F726D', X'616464', X'6F6E', 0, 0, X'616464', 0, 2), (".$current["id"].", X'53657474696E6773', X'73657474696E6773', X'6F6E', 0, 0, X'736572766572', 0, 1); | |
",$nc); | |
// Now we fix the columns fields were in since we keep one column entry with alignment instead of two. | |
$q = mysql_query("SELECT * FROM btx_form_builder_forms",$nc); | |
while ($form = mysql_fetch_assoc($q)) { | |
// Go through each of form's fields | |
$last_was_column = false; | |
$qq = mysql_query("SELECT * FROM btx_form_builder_fields WHERE form = '".$form["id"]."' ORDER BY position DESC, id ASC",$nc); | |
while ($field = mysql_fetch_assoc($qq)) { | |
if ($field["type"] == "column") { | |
if ($last_was_column) { | |
mysql_query("UPDATE btx_form_builder_fields SET alignment = 'right', `column` = '$last_was_column' WHERE `column` = '".$field["id"]."'",$nc); | |
mysql_query("DELETE FROM btx_form_builder_fields WHERE id = '".$field["id"]."'",$nc); | |
$last_was_column = false; | |
} else { | |
$last_was_column = $field["id"]; | |
mysql_query("UPDATE btx_form_builder_fields SET alignment = 'left' WHERE `column` = '".$field["id"]."'",$nc); | |
} | |
} else { | |
$last_was_column = false; | |
} | |
} | |
} | |
} | |
?> | |
<fieldset class="clear"> | |
<p>Shazam. You're done, hopefully. Remember to update your templates to stop including paths for file uploads. You're going to need to reset all the passwords for your users.</p> | |
<br /><br /> | |
</fieldset> | |
<? | |
} else { | |
?> | |
<fieldset class="clear"> | |
<p>Welcome to the BigTree converter. This should be run in a clean BigTree 4 install.</p> | |
<br /> | |
</fieldset> | |
<hr /> | |
<fieldset class="left"> | |
<label>BigTree ~2.0 Directory <small>(full path to the root directory, not /core/, but above it)</small></label> | |
<input class="text" type="text" name="path" tabindex="1" /> | |
</fieldset> | |
<fieldset class="right"> | |
<label>Data Merge</label> | |
<input type="checkbox" name="data_merge" /> | |
</fieldset> | |
<fieldset class="right"> | |
<label>Copy Files</label> | |
<input type="checkbox" name="copy_files" /> | |
</fieldset> | |
<br class="clear" /> | |
<fieldset class="lower"> | |
<input type="submit" class="button blue" value="Convert Now" tabindex="15" /> | |
</fieldset> | |
<? | |
} | |
?> | |
</form> | |
<a href="http://www.bigtreecms.com" class="install_logo" target="_blank">BigTree</a> | |
<a href="http://www.fastspot.com" class="install_copyright" target="_blank">© <?php echo date("Y") ?> Fastspot</a> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment