1
kroewing
In search of the 2.2.x -> 2.0.x downgrade script
  • 2008/3/24 23:31

  • kroewing

  • Friend of XOOPS

  • Posts: 7

  • Since: 2008/3/24


Hi,

under download i found the XOOPS 2.2.3 to 2.0.x downgrade script but the link is broken.

https://xoops.org/modules/core/singlefile.php?cid=&lid=124

Please, can anyone share this skript.

Thanks
Heinz

2
jsaund22
Re: In search of the 2.2.x -> 2.0.x downgrade script
  • 2008/4/3 19:15

  • jsaund22

  • Just popping in

  • Posts: 4

  • Since: 2004/11/13


I am searching for this script as well, considering that the download on the XOOPS site itself does not work.

If anyone has this script, could you please point me to a valid download location?

Thanks.

3
Trier
Re: In search of the 2.2.x -> 2.0.x downgrade script
  • 2008/4/3 20:13

  • Trier

  • Friend of XOOPS

  • Posts: 12

  • Since: 2007/3/18


downgrade.php

Quote:
include "mainfile.php";
$xoopsConfig['theme_set'] = "default";
include "header.php";
//only leave relevant queries
$xoopsLogger->queries = array();
//enable PHP debug
error_reporting(E_ALL);

$log = array();
$op = isset($_REQUEST['op']) ? $_REQUEST['op'] : "start";
switch ($op) {
case "start":
showForm();
break;

case "config_go":
//Set core configuration back to zero for system module
$xoopsDB->query("UPDATE ".$xoopsDB->prefix('config')." SET conf_modid=0 WHERE conf_modid=1");
//Change debug modes so there can only be one active at any one time
$criteria = new Criteria('conf_name', 'debug_mode');
$config_handler =& xoops_gethandler('config');
$config =& $config_handler->getConfigs($criteria);
$value = 1;
$config[0]->setVar('conf_formtype', 'select');
$config[0]->setVar('conf_valuetype', 'int');
$config[0]->setConfValueForInput($value);
if (!$config_handler->insertConfig($config[0])) {
$log[] = "Could not update debug settings, check MySQL log for details";
}
else {
$log[] = "Debug settings updated";
}
unset($config);

//Drop non-System config categories
$criteria = new Criteria('confcat_modid', 1, ">");
$configcat_handler = xoops_gethandler('configcategory');
$configcats = $configcat_handler->getObjects($criteria);
if (count($configcats) > 0) {
$sql = "DELETE FROM ".$xoopsDB->prefix('configcategory')." WHERE confcat_modid > 1";
if (!$xoopsDB->query($sql)) {
$log[] = "Could not delete module configuration categories, check MySQL log for details";
}
else {
$log[] = "Module configuration categories removed";
}
}

//Drop category information fields added in 2.2
$sql = "ALTER TABLE ".$GLOBALS['xoopsDB']->prefix("configcategory")." DROP `confcat_nameid`";
if (!$GLOBALS['xoopsDB']->query($sql)) {
$log[] = 'Could not remove nameid field from configcategory table, check MySQL log for details';
}
else {
$log[] = "Nameid field removed from configcategory table";
}
$sql = "ALTER TABLE ".$GLOBALS['xoopsDB']->prefix("configcategory")." DROP `confcat_description`";
if (!$GLOBALS['xoopsDB']->query($sql)) {
$log[] = 'Could not remove description field from configcategory table, check MySQL log for details';
}
else {
$log[] = "Description field removed from configcategory";
}
$sql = "ALTER TABLE ".$GLOBALS['xoopsDB']->prefix("configcategory")." DROP `confcat_modid`";
if (!$GLOBALS['xoopsDB']->query($sql)) {
$log[] = 'Could not remove module id field from configcategory table, check MySQL log for details';
}
else {
$log[] = "Module id field removed from configcategory table";
}

// Re-add user configuration category
$sql = "INSERT INTO ".$xoopsDB->prefix("configcategory")." (confcat_id, confcat_name, confcat_order) VALUES (2, '_MD_AM_USERSETTINGS', 2)";
if (!$xoopsDB->query($sql)) {
$log[] = "Could not add user configuration category, check MySQL log for details";
}
else {
$log[] = "User configuration category added";
}

//Rebuild user configuration items
//Get values from Profile module
$module_handler = xoops_gethandler('module');
$profile_module = $module_handler->getByDirname('profile');
if (is_object($profile_module)) {
$profile_config = $config_handler->getConfigs(new Criteria('conf_modid', $profile_module->getVar('mid')));
foreach (array_keys($profile_config) as $i) {
$profile_config_arr[$profile_config[$i]->getVar('conf_name')] = $profile_config[$i]->getVar('conf_value', 'n');
}
}
else {
$myts = MyTextSanitizer::getInstance();
$profile_config_arr['minpass'] = 5;
$profile_config_arr['minuname'] = 3;
$profile_config_arr['new_user_notify'] = 1;
$profile_config_arr['new_user_notify_group'] = XOOPS_GROUP_ADMIN;
$profile_config_arr['activation_type'] = 0;
$profile_config_arr['activation_group'] = XOOPS_GROUP_ADMIN;
$profile_config_arr['uname_test_level'] = 0;
$profile_config_arr['avatar_allow_upload'] = 0;
$profile_config_arr['avatar_width'] = 80;
$profile_config_arr['avatar_height'] = 80;
$profile_config_arr['avatar_maxsize'] = 35000;
$profile_config_arr['self_delete'] = 0;
$profile_config_arr['bad_unames'] = serialize(array('webmaster', '^xoops', '^admin'));
$profile_config_arr['bad_emails'] = serialize(array('xoops.org$'));
$profile_config_arr['maxuname'] = 10;
$profile_config_arr['avatar_minposts'] = 0;
$profile_config_arr['allow_chgmail'] = 0;
$profile_config_arr['reg_dispdsclmr'] = 0;
$profile_config_arr['reg_disclaimer'] = "";
$profile_config_arr['allow_register'] = 1;
}

$config_error = 0;
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (17, 0, 2, 'minpass', '_MD_AM_MINPASS', '".$profile_config_arr['minpass']."', '_MD_AM_MINPASSDSC', 'textbox', 'int', 1)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (18, 0, 2, 'minuname', '_MD_AM_MINUNAME', '".$profile_config_arr['minuname']."', '_MD_AM_MINUNAMEDSC', 'textbox', 'int', 2)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (19, 0, 2, 'new_user_notify', '_MD_AM_NEWUNOTIFY', '".$profile_config_arr['new_user_notify']."', '_MD_AM_NEWUNOTIFYDSC', 'yesno', 'int', 4)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (20, 0, 2, 'new_user_notify_group', '_MD_AM_NOTIFYTO', '".$profile_config_arr['new_user_notify_group']."', '_MD_AM_NOTIFYTODSC', 'group', 'int', 6)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (21, 0, 2, 'activation_type', '_MD_AM_ACTVTYPE', '".$profile_config_arr['activation_type']."', '_MD_AM_ACTVTYPEDSC', 'select', 'int', 8)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (22, 0, 2, 'activation_group', '_MD_AM_ACTVGROUP', '".$profile_config_arr['activation_group']."', '_MD_AM_ACTVGROUPDSC', 'group', 'int', 10)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (23, 0, 2, 'uname_test_level', '_MD_AM_UNAMELVL', '".$profile_config_arr['uname_test_level']."', '_MD_AM_UNAMELVLDSC', 'select', 'int', 12)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (24, 0, 2, 'avatar_allow_upload', '_MD_AM_AVATARALLOW', '".$profile_config_arr['avatar_allow_upload']."', '_MD_AM_AVATARALWDSC', 'yesno', 'int', 14)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (27, 0, 2, 'avatar_width', '_MD_AM_AVATARW', '".$profile_config_arr['avatar_width']."', '_MD_AM_AVATARWDSC', 'textbox', 'int', 16)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (28, 0, 2, 'avatar_height', '_MD_AM_AVATARH', '".$profile_config_arr['avatar_height']."', '_MD_AM_AVATARHDSC', 'textbox', 'int', 18)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (29, 0, 2, 'avatar_maxsize', '_MD_AM_AVATARMAX', '".$profile_config_arr['avatar_maxsize']."', '_MD_AM_AVATARMAXDSC', 'textbox', 'int', 20)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (31, 0, 2, 'self_delete', '_MD_AM_SELFDELETE', '".$profile_config_arr['self_delete']."', '_MD_AM_SELFDELETEDSC', 'yesno', 'int', 22)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (34, 0, 2, 'bad_unames', '_MD_AM_BADUNAMES', '".$profile_config_arr['bad_unames']."', '_MD_AM_BADUNAMESDSC', 'textarea', 'array', 24)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (35, 0, 2, 'bad_emails', '_MD_AM_BADEMAILS', '".$profile_config_arr['bad_emails']."', '_MD_AM_BADEMAILSDSC', 'textarea', 'array', 26)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (36, 0, 2, 'maxuname', '_MD_AM_MAXUNAME', '".$profile_config_arr['maxuname']."', '_MD_AM_MAXUNAMEDSC', 'textbox', 'int', 3)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (46, 0, 2, 'avatar_minposts', '_MD_AM_AVATARMP', '".$profile_config_arr['avatar_minposts']."', '_MD_AM_AVATARMPDSC', 'textbox', 'int', 15)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (52, 0, 2, 'allow_chgmail', '_MD_AM_ALLWCHGMAIL', '".$profile_config_arr['allow_chgmail']."', '_MD_AM_ALLWCHGMAILDSC', 'yesno', 'int', 3)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (54, 0, 2, 'reg_dispdsclmr', '_MD_AM_DSPDSCLMR', '".$profile_config_arr['reg_dispdsclmr']."', '_MD_AM_DSPDSCLMRDSC', 'yesno', 'int', 30)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (55, 0, 2, 'reg_disclaimer', '_MD_AM_REGDSCLMR', '".$profile_config_arr['reg_disclaimer']."', '_MD_AM_REGDSCLMRDSC', 'textarea', 'text', 32)")) {
$config_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("config")." VALUES (56, 0, 2, 'allow_register', '_MD_AM_ALLOWREG', '".$profile_config_arr['allow_register']."', '_MD_AM_ALLOWREGDSC', 'yesno', 'int', 0)")) {
$config_error++;
}
if ($config_error > 0) {
$log[] = $config_error." configuration items could not be inserted, check MySQL log for details";
}

//Rebuild user configuration options
$option_error = 0;
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("configoption")." VALUES (8, '_MD_AM_USERACTV', '0', 21)")) {
$option_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("configoption")." VALUES (9, '_MD_AM_AUTOACTV', '1', 21)")) {
$option_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("configoption")." VALUES (10, '_MD_AM_ADMINACTV', '2', 21)")) {
$option_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("configoption")." VALUES (11, '_MD_AM_STRICT', '0', 23)")) {
$option_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("configoption")." VALUES (12, '_MD_AM_MEDIUM', '1', 23)")) {
$option_error++;
}
if (!$GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix("configoption")." VALUES (13, '_MD_AM_LIGHT', '2', 23)")) {
$option_error++;
}
if ($option_error > 0) {
$log[] = $option_error." configuration options could not be inserted, check MySQL log for details";
}

// remove admin theme configuration item
$criteria = new Criteria('conf_name', 'theme_set_admin');
$config =& $config_handler->getConfigs($criteria);
if (!$config_handler->deleteConfig($config[0])) {
$log[] = "Could not delete theme_set_admin configuration item, check MySQL log for details";
}
else {
$log[] = "theme_set_admin removed";
}

// remove authentication category
$sql = "DELETE FROM ".$xoopsDB->prefix('configcategory')." WHERE confcat_id=7";
if (!$xoopsDB->query($sql)) {
$log[] = "Could not delete authentication configuration category";
}
else {
$log[] = "Authentication configuration category removed";
}

showForm();
break;

case "users":

case "users_go":
//Re-add user fields
if (!alterTable("users", "user_icq", "varchar(32) NOT NULL default ''")) {
$log[] = "Could not add user_icq field to user table";
}
else {
$log[] = "user_icq field added to user table";
}
if (!alterTable("users", "user_from", "varchar(255) NOT NULL default ''")) {
$log[] = "Could not add user_from field to user table";
}
else {
$log[] = "user_from field added to user table";
}
if (!alterTable("users", "user_sig", "text NOT NULL")) {
$log[] = "Could not add user_sig field to user table";
}
else {
$log[] = "user_sig field added to user table";
}
if (!alterTable("users", "user_viewemail", "tinyint(2) NOT NULL default 0")) {
$log[] = "Could not add user_viewemail field to user table";
}
else {
$log[] = "user_viewemail field added to user table";
}
if (!alterTable("users", "user_aim", "varchar(128) NOT NULL default ''")) {
$log[] = "Could not add user_aim field to user table";
}
else {
$log[] = "user_aim field added to user table";
}
if (!alterTable("users", "user_yim", "varchar(128) NOT NULL default ''")) {
$log[] = "Could not add user_yim field to user table";
}
else {
$log[] = "user_yim field added to user table";
}
if (!alterTable("users", "user_msnm", "varchar(128) NOT NULL default ''")) {
$log[] = "Could not add user_msnm field to user table";
}
else {
$log[] = "user_msnm field added to user table";
}
if (!alterTable("users", "user_occ", "varchar(128) NOT NULL default ''")) {
$log[] = "Could not add user_occ field to user table";
}
else {
$log[] = "user_occ field added to user table";
}
if (!alterTable("users", "url", "varchar(255) NOT NULL default ''")) {
$log[] = "Could not add url field to user table";
}
else {
$log[] = "url field added to user table";
}
if (!alterTable("users", "bio", "text")) {
$log[] = "Could not add bio field to user table";
}
else {
$log[] = "bio field added to user table";
}
if (!alterTable("users", "user_intrest", "varchar(255) NOT NULL default ''")) {
$log[] = "Could not add user_intrest field to user table";
}
else {
$log[] = "user_intrest field added to user table";
}
if (!alterTable("users", "umode", "varchar(12) NOT NULL default ''")) {
$log[] = "Could not add umode field to user table";
}
else {
$log[] = "umode field added to user table";
}
if (!alterTable("users", "uorder", "tinyint(2) NOT NULL default 0")) {
$log[] = "Could not add uorder field to user table";
}
else {
$log[] = "uorder field added to user table";
}
if (!alterTable("users", "notify_method", "tinyint(2) NOT NULL default 0")) {
$log[] = "Could not add notify_method field to user table";
}
else {
$log[] = "notify_method field added to user table";
}
if (!alterTable("users", "notify_mode", "tinyint(2) NOT NULL default 0")) {
$log[] = "Could not add notify_mode field to user table";
}
else {
$log[] = "notify_mode field added to user table";
}
if (!alterTable("users", "user_regdate", "int NOT NULL default 0")) {
$log[] = "Could not add user_regdate field to user table";
}
else {
$log[] = "user_regdate field added to user table";
}
if (!alterTable("users", "posts", "int NOT NULL default 0")) {
$log[] = "Could not add posts field to user table";
}
else {
$log[] = "posts field added to user table";
}
if (!alterTable("users", "attachsig", "tinyint(2) NOT NULL default 0")) {
$log[] = "Could not add attachsig field to user table";
}
else {
$log[] = "attachsig field added to user table";
}
if (!alterTable("users", "timezone_offset", "varchar(10) NOT NULL default ''")) {
$log[] = "Could not add timezone_offset field to user table";
}
else {
$log[] = "timezone_offset field added to user table";
}
if (!alterTable("users", "user_mailok", "tinyint(2) NOT NULL default 0")) {
$log[] = "Could not add user_mailok field to user table";
}
else {
$log[] = "user_mailok field added to user table";
}
if (!alterTable("users", "theme", "varchar(128) NOT NULL default ''")) {
$log[] = "Could not add theme field to user table";
}
else {
$log[] = "theme field added to user table";
}
if (!alterTable("users", "actkey", "varchar(128) NOT NULL default ''")) {
$log[] = "Could not add actkey field to user table";
}
else {
$log[] = "actkey field added to user table";
}
if (!alterTable("users", "last_login", "int NOT NULL default 0")) {
$log[] = "Could not add last_login field to user table";
}
else {
$log[] = "last_login field added to user table";
}

//Try one query
$sql = "UPDATE ".$xoopsDB->prefix("users")." u, ".$xoopsDB->prefix("user_profile")." p SET u.user_icq = p.user_icq, u.user_from=p.user_from, u.user_sig=p.user_sig, u.user_viewemail=p.user_viewemail, u.user_aim=p.user_aim, u.user_yim=p.user_yim, u.user_msnm=p.user_msnm, u.user_occ=p.user_occ, u.url=p.url, u.bio=p.bio, u.user_intrest=p.user_intrest, u.umode=p.umode, u.uorder=p.uorder, u.notify_method=p.notify_method, u.notify_mode=p.notify_mode, u.user_regdate=p.user_regdate, u.posts=p.posts, u.attachsig=p.attachsig, u.timezone_offset=p.timezone_offset, u.user_mailok=p.user_mailok, u.theme=p.theme, u.actkey=p.actkey, u.last_login=p.last_login WHERE u.uid=p.profileid";
if (!$xoopsDB->query($sql)) {
//Move fields individually

//Get dynamic fields
$sql = "SELECT field_name, field_title FROM ".$xoopsDB->prefix("user_profile_field");
$result = $xoopsDB->query($sql);
while (list($name, $title) = $xoopsDB->fetchRow($result)) {
$fields[$name] = $title." (".$name.")";
}

include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
$form = new XoopsThemeForm("Map Fields", "form", "downgrade.php");

$form->addElement(new XoopsFormLabel('', "User fields could not be automatically migrated, please manually map each 2.0.x field to its 2.2.x counterpart"));

$userfields = array("user_icq", "user_from", "user_sig", "user_viewemail", "user_aim", "user_yim", "user_msnm", "user_occ", "url", "bio", "user_intrest", "umode", "uorder", "notify_method", "notify_mode", "user_regdate", "posts", "attachsig", "timezone_offset", "user_mailok", "theme", "actkey", "last_login");

foreach ($userfields as $field) {
$field_select = new XoopsFormSelect($field, $field, $field);
$field_select->addOption(-1, "Don't migrate this field");
$field_select->addOptionArray($fields);
$form->addElement($field_select);
unset($field_select);
}

$form->addElement(new XoopsFormHidden('op', 'users_finish'));
$form->addElement(new XoopsFormButton('', 'user_downgrade', "Migrate User Fields", "Submit"));

$form->display();
break;
}
else {
$log[] = "Profile data migrated to users table";
}

case "users_finish":
//When we get here, everything should be successful - it is intentional that there is not a break before this case as it should continue automatically, if fields are migrated perfectly automatically

$userfields = array("user_icq", "user_from", "user_sig", "user_viewemail", "user_aim", "user_yim", "user_msnm", "user_occ", "url", "bio", "user_intrest", "umode", "uorder", "notify_method", "notify_mode", "user_regdate", "posts", "attachsig", "timezone_offset", "user_mailok", "theme", "actkey", "last_login");

$error = false;
$myts = MyTextSanitizer::getInstance();
foreach ($userfields as $field) {
if (isset($_REQUEST[$field]) && $_REQUEST[$field] != -1) {
$sql = "UPDATE ".$xoopsDB->prefix("users")." u, ".$xoopsDB->prefix("user_profile")." p
SET u.".$field." = p.".$myts->addSlashes($_REQUEST[$field]);
if (!$xoopsDB->query($sql)) {
$log[] = "Could not set ".$field." field in users table to the value of ".$_REQUEST[$field]." field in profile table";
$error = true;
}
}
}

if ($error != true) {
//drop user_profile table
$sql = "DROP TABLE ".$xoopsDB->prefix("user_profile");
if (!$xoopsDB->query($sql)) {
$log[] = "Could not drop table ".$xoopsDB->prefix("user_profile");
}
else {
$log[] = $xoopsDB->prefix("user_profile")." table dropped";

//drop user_profile_field table
$sql = "DROP TABLE ".$xoopsDB->prefix("user_profile_field");
if (!$xoopsDB->query($sql)) {
$log[] = "Could not drop table ".$xoopsDB->prefix("user_profile_field");
}
else {
$log[] = $xoopsDB->prefix("user_profile_field")." table dropped";
}
//Set loginname as uname
$sql = "UPDATE ".$xoopsDB->prefix("users")." SET uname=loginname";
if (!$xoopsDB->query($sql)) {
$log[] = "Could not set uname to loginname value, check MySQL log for details";
}
else {
$log[] = "uname field set to loginname value";
//Drop loginname
$sql = "ALTER TABLE ".$xoopsDB->prefix("users")." DROP loginname";
if (!$xoopsDB->query($sql)) {
$log[] = "Could not drop loginname field from users table";
}
else {
$log[] = "loginname field dropped";
}
}
}
}

showForm();
break;

case "blocks":
//Change block module link to remove pages
$sql = "DELETE FROM ".$xoopsDB->prefix("block_module_link")." WHERE pageid > 0";//Remove page links for module subpages
if (!$xoopsDB->query($sql)) {
$log[] = "Could not drop pageid field from block_module_link table, check MySQL log for details";
}
else {
$log[] = "pageid field dropped from block_module_link table";

$sql = "ALTER TABLE ".$xoopsDB->prefix("block_module_link")." DROP PRIMARY KEY "; //Drop primary key since it includes pageid
if (!$xoopsDB->query($sql)) {
$log[] = "Could not drop block_module_link primary key";
}
else {
$log[] = "Primary key dropped from block_module_link table";
$sql = "ALTER TABLE ".$xoopsDB->prefix("block_module_link")." DROP pageid"; //Drop pageid field
if (!$xoopsDB->query($sql)) {
$log[] = "Could not drop pageid field from block_module_link table, check MySQL log for details";
}
else {
$log[] = "pageid field dropped from block_module_link table";

$sql = "ALTER TABLE ".$xoopsDB->prefix("block_module_link")." ADD PRIMARY KEY ( `block_id` , `module_id`)"; //Make new primary key
if (!$xoopsDB->query($sql)) {
$log[] = "Could not add primary key to block_module_link table, check MySQL log for details";
}
else {
$log[] = "Primary key added to block_module_link table";
}
}
}
}

// Get id of custom block type
$sql = "SELECT bid FROM ".$xoopsDB->prefix('newblocks')." WHERE show_func='b_system_custom_show'";
$result = $xoopsDB->query($sql);
list($custom_blockid) = $xoopsDB->fetchRow($result);

// Check whether duplicates of one block exists - except custom blocks
$sql = "SELECT bid, count(*) FROM ".$xoopsDB->prefix("block_instance")." WHERE bid !=".$custom_blockid." GROUP BY bid HAVING count(*) > 1";
$result = $xoopsDB->query($sql);
$bids = array();
while (list($bid, $count) = $xoopsDB->fetchRow($result)) {
$bids[] = $bid;
}
if (count($bids) > 0) {
//There are duplicate instances, ask the user to pick the right ones.
//Get instances
$sql = "SELECT * FROM ".$xoopsDB->prefix("block_instance")." WHERE bid IN (".implode(',', $bids).")";
$result = $xoopsDB->query($sql);
while ($row = $xoopsDB->fetchArray($result)) {
$instances[$row['bid']][] = $row;
}
//Get blocks
$sql = "SELECT * FROM ".$xoopsDB->prefix("newblocks")." WHERE bid IN (".implode(',', $bids).")";
$result = $xoopsDB->query($sql);
while ($row = $xoopsDB->fetchArray($result)) {
$blocks[$row['bid']] = $row;
}

//Join them together in a select, mapping each block to one instance
include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
$form = new XoopsThemeForm("Downgrade Blocks", "form", "downgrade.php");
$form->addElement(new XoopsFormLabel('', 'One or more blocks have several instances. Please select the instance that you would want to keep, the rest will be lost'));
foreach (array_keys($blocks) as $i) {
$select = new XoopsFormSelect($blocks[$i]['name'], 'blocks['.$i.']');
foreach ($instances[$i] as $instance) {
$select->addOption($instance['instanceid'], $instance['title']."(".$instance['instanceid'].")");
}
$form->addElement($select);
unset($select);
}
$form->addElement(new XoopsFormHidden('op', 'blocks_go'));
$form->addElement(new XoopsFormButton('', 'submit', 'Downgrade Blocks', 'submit'));
$form->display();
break;
}


case "blocks_go":

// Deal with custom blocks
// Get custom blocks
$sql = "SELECT * FROM ".$xoopsDB->prefix("newblocks")." b, ".$xoopsDB->prefix("block_instance")." i WHERE b.bid=i.bid AND b.show_func='b_system_custom_show'";
$result = $xoopsDB->query($sql);
while ($row = $xoopsDB->fetchArray($result)) {
$custom_blocks[] = $row;
$custom_blockids[] = $row['instanceid'];
}

// Move information from instances table
if (isset($_REQUEST['blocks'])) {
//Remove blocks that are discarded
$sql = "SELECT instanceid FROM ".$xoopsDB->prefix("block_instance")." WHERE bid IN (".implode(',', array_keys($_REQUEST['blocks'])).") AND instanceid NOT IN (".implode(',', $_REQUEST['blocks']).") AND instanceid NOT IN (".implode(',', $custom_blockids).")";
if (!($result = $xoopsDB->query($sql))) {
$log[] = "Non-selected block instances could not be removed, check MySQL log for details";
}
else {
while (list($instanceid) = $xoopsDB->fetchRow($result)) {
$instanceids[] = $instanceid;
}
$sql = "DELETE FROM ".$xoopsDB->prefix("block_instance")." WHERE instanceid IN (".implode(',', $instanceids).")";
if ($xoopsDB->query($sql)) {
$log[] = "Non-selected block instances removed";
//Remove permissions
$sql = "DELETE FROM ".$xoopsDB->prefix("group_permission")." WHERE gperm_name='block_read' AND gperm_itemid IN (".implode(',', $instanceids).")";
$xoopsDB->query($sql);
}
else {
$log[] = "Non-selected block instances could not be removed, check MySQL log for details";
}
}
}

$block_error_count = $block_success_count = 0;
// Change block table
if (!alterTable("newblocks", "func_num", "tinyint(3) unsigned NOT NULL default '0'")) {
$block_error_count++;
}
else {
$block_success_count++;
}
if (!alterTable("newblocks", "title", "varchar(255) NOT NULL default ''")) {
$block_error_count++;
}
else {
$block_success_count++;
}
if (!alterTable("newblocks", "content", "text NOT NULL")) {
$block_error_count++;
}
else {
$block_success_count++;
}
if (!alterTable("newblocks", "side", "tinyint(1) unsigned NOT NULL default '0'")) {
$block_error_count++;
}
else {
$block_success_count++;
}
if (!alterTable("newblocks", "weight", "smallint(5) unsigned NOT NULL default '0'")) {
$block_error_count++;
}
else {
$block_success_count++;
}
if (!alterTable("newblocks", "visible", "tinyint(1) unsigned NOT NULL default '0'")) {
$block_error_count++;
}
else {
$block_success_count++;
}
if (!alterTable("newblocks", "block_type", "char(1) NOT NULL default ''")) {
$block_error_count++;
}
else {
$block_success_count++;
}
if (!alterTable("newblocks", "c_type", "char(1) NOT NULL default ''")) {
$block_error_count++;
}
else {
$block_success_count++;
}
if (!alterTable("newblocks", "bcachetime", "int(10) unsigned NOT NULL default '0'")) {
$block_error_count++;
}
else {
$block_success_count++;
}

// Log progress
if ($block_error_count > 0) {
$log[] = "Could not add ".$block_error_count." instance fields to blocks table";
}
if ($block_success_count > 0) {
$log[] = $block_success_count." instance fields added to blocks table";
}

$groupperm_handler = xoops_gethandler('groupperm');

// Get id of custom block type
$sql = "SELECT bid FROM ".$xoopsDB->prefix('newblocks')." WHERE show_func='b_system_custom_show'";
$result = $xoopsDB->query($sql);
list($custom_blockid) = $xoopsDB->fetchRow($result);

// Remove custom block instances from instance table
$sql = "DELETE FROM ".$xoopsDB->prefix("block_instance")." WHERE bid=".$custom_blockid;
if (!$xoopsDB->query($sql)) {
$log[] = "Could not delete custom block instances, check MySQL log for details";
}
else {
$log[] = "Custom block instance(s) removed";
}

// Remove custom block item in the newblocks table
$sql = "DELETE FROM ".$xoopsDB->prefix("newblocks")." WHERE show_func='b_system_custom_show'";
if (!$xoopsDB->query($sql)) {
$log[] = "Could not delete custom block definition from blocks table, check MySQL log for details";
}
else {
$log[] = "Custom block definition removed from blocks table";
}

// Update remaining blocks information
$sql = "UPDATE ".$xoopsDB->prefix("newblocks")." b, ".$xoopsDB->prefix("block_instance")." i SET b.title=i.title, b.side=i.side, b.weight=i.weight, b.visible=i.visible, b.block_type='M', b.c_type='', b.bcachetime=i.bcachetime WHERE b.bid=i.bid";
if (!$xoopsDB->query($sql)) {
$log[] = "Could not update block information with data from instance table, check MySQL log for details";
}
else {
$log[] = "Block information updated with data from instance table";

//Update permissions to go with block id rather than instanceid
$sql = "UPDATE ".$xoopsDB->prefix("group_permission").", ".$xoopsDB->prefix("block_instance")." SET gperm_itemid=bid WHERE gperm_name='block_read' AND gperm_itemid=instanceid";
$xoopsDB->query($sql);

// Drop block_instance table
$sql = "DROP TABLE ".$xoopsDB->prefix("block_instance");
if (!$xoopsDB->query($sql)) {
$log[] = "Could not drop instance table, check MySQL log for details";
}
else {
$log[] = "Instance table dropped";


// Update block options from array to |-separated strings
$active_blocks = XoopsBlock::getAllBlocks();
$inactive_blocks = XoopsBlock::getAllBlocks('object', null, null, "side,weight,bid", 0);
$blocks = array_merge($active_blocks, $inactive_blocks);

/*
// Get blocks with group permissions - admin
$groupperm_handler = xoops_gethandler('groupperm');
$admin_blocks = $groupperm_handler->getItemIds("block_read", XOOPS_GROUP_ADMIN);
// Get blocks with group permissions - users
$user_blocks = $groupperm_handler->getItemIds("block_read", XOOPS_GROUP_USERS);

*/
foreach ($blocks as $block) {
// Update blocks_module_link table to hold records for all blocks
$sql = "INSERT INTO ".$xoopsDB->prefix("block_module_link")." VALUES (".$block->getVar('bid').", 0)";

$options = $block->getVar('options', 'n') != "" ? unserialize($block->getVar('options', 'n')) : array();

$options_count = count($options);
if ($options_count > 0) {
//Convert array values to comma-separated
for ( $i = 0; $i < $options_count; $i++ ) {
if (is_array($options[$i])) {
$options[$i] = implode(',', $options[$i]);
}
}
$options = is_array($options) ? implode('|', $options) : "";
$block->setVar('options', $options);
}
else {
$block->setVar('options', "");
}
if (!$block->store()) {
$errors = $block->getErrors();
$log = array_merge($log, $errors);
}
else {
$log[] = $block->getVar('name')." Updated";
}
/*
//If admins don't have permissions for this block
if (!in_array($block->getVar('bid'), $admin_blocks)) {
//add permissions
if (!$groupperm_handler->addRight("block_read", $block->getVar('bid'), XOOPS_GROUP_ADMIN)) {
$log[] = "Could not add read permissions for admin users to ".$block->getVar('name');
}
else {
$log[] = "Read permissions for admin users to ".$block->getVar('name')." added";
}
}
//If registered users don't have permissions for this block
if (!in_array($block->getVar('bid'), $user_blocks)) {
//add permissions
if (!$groupperm_handler->addRight("block_read", $block->getVar('bid'), XOOPS_GROUP_USERS)) {
$log[] = "Could not add read permissions for registered users to ".$block->getVar('name');
}
else {
$log[] = "Read permissions for registered users to ".$block->getVar('name')." added";
}
}
*/
}
}
}

// Reinsert rows for each custom block
foreach ($custom_blocks as $block) {
$options = unserialize($block['options']);
$newblock = new XoopsBlock();
$newblock->setVar('mid', 0);
$newblock->setVar('func_num', 0);
$newblock->setVar('options', '');
//Change to set name depending on block content type
$newblock->setVar('name', $block['name']);
$newblock->setVar('title', $block['title']);
$newblock->setVar('content', $options[0]);
$newblock->setVar('side', $block['side']);
$newblock->setVar('weight', $block['weight']);
$newblock->setVar('visible', $block['visible']);
$newblock->setVar('block_type', "C");
//Change to set c_type depending on instance options
$newblock->setVar('c_type', $options[1]);
$newblock->setVar('isactive', 1);

$newblock->setVar('dirname', "system");
$newblock->setVar('func_file', "");
$newblock->setVar('show_func', "");
$newblock->setVar('edit_func', "");

$newblock->setVar('template', "");
$newblock->setVar('bcachetime', $block['bcachetime']);
$newblock->setVar('last_modified', $block['last_modified']);
if (!$newbid = $newblock->store()) {
$errors = $newblock->getErrors();
$log = array_merge($log, $errors);
}
else {
$log[] = $block['title']." Updated";
}
//Convert block permissions
$sql = "UPDATE ".$xoopsDB->prefix("group_permission")." SET gperm_itemid=".$newbid." WHERE gperm_itemid=".$block['instanceid']." AND gperm_name='block_read'";
$xoopsDB->query($sql);

unset($newblock);
}

showForm();
break;

case "pm":
$sql = "CREATE TABLE `".$xoopsDB->prefix("priv_msgs")."` (
msg_id mediumint(8) unsigned NOT NULL auto_increment,
msg_image varchar(100) default NULL,
subject varchar(255) NOT NULL default '',
from_userid mediumint(8) unsigned NOT NULL default '0',
to_userid mediumint(8) unsigned NOT NULL default '0',
msg_time int(10) unsigned NOT NULL default '0',
msg_text text NOT NULL,
read_msg tinyint(1) unsigned NOT NULL default '0',
PRIMARY KEY (msg_id),
KEY to_userid (to_userid),
KEY touseridreadmsg (to_userid,read_msg),
KEY msgidfromuserid (msg_id,from_userid)
) TYPE=MyISAM;";
if ($xoopsDB->query($sql)) {
$log[] = "Private Messaging table re-created";
}
else {
$log[] = "Error while creating Private Messaging table, check MySQL Log for details";
}

showForm();
break;
}
showLog($log);
include "footer.php";

/**
* Shows a form for choosing which downgrade routine to perform
*
* @return void
*/
function showForm() {
global $xoopsDB, $xoopsUser;
include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
$form = new XoopsThemeForm("Downgrade from XOOPS 2.2.x to 2.0.x", "form", "downgrade.php");

$elements = false;

//$config_handler = xoops_gethandler('configcategory');
//$criteria = new Criteria("confcat_modid", 1);
//if (count($config_handler->getObjects($criteria)) > 0) {
$sql = "SHOW COLUMNS FROM ".$xoopsDB->prefix('configcategory')." LIKE 'confcat_modid'";
$result = $xoopsDB->queryF($sql);
if ($result) {
if ($xoopsDB->getRowsNum($result) > 0) {
$config_button = new XoopsFormButton('', 'config_downgrade', "Downgrade Configuration", "Submit");
$config_button->setExtra("onclick='document.forms.form.op.value=\"config_go\"'");
$form->addElement($config_button);

$elements = true;
}
}
//unset($criteria);

$sql = "SHOW TABLES LIKE '".$xoopsDB->prefix("user_profile")."'";
$result = $xoopsDB->queryF($sql);
if ($result) {
if ($xoopsDB->getRowsNum($result) > 0) {
$users_button = new XoopsFormButton('', 'user_downgrade', "Downgrade User Tables", "Submit");
$users_button->setExtra("onclick='document.forms.form.op.value=\"users\"'");
$form->addElement($users_button);
$elements = true;
}
}

$sql = "SHOW TABLES LIKE '".$xoopsDB->prefix("block_instance")."'";
$result = $xoopsDB->queryF($sql);
if ($result) {
if ($xoopsDB->getRowsNum($result) > 0) {
$blocks_button = new XoopsFormButton('', 'block_downgrade', "Downgrade Blocks", "Submit");
$blocks_button->setExtra("onclick='document.forms.form.op.value=\"blocks\"'");
$form->addElement($blocks_button);
$elements = true;
}
}

$sql = "SHOW TABLES LIKE '".$xoopsDB->prefix("priv_msgs")."'";
$result = $xoopsDB->queryF($sql);
if ($result) {
if ($xoopsDB->getRowsNum($result) == 0) {
$privmsg_button = new XoopsFormButton('', 'pm_downgrade', "Reinsert Private Message table", "Submit");
$privmsg_button->setExtra("onclick='document.forms.form.op.value=\"pm\"'");
$form->addElement($privmsg_button);
$elements = true;
}
}

if ($elements) {
$form->addElement(new XoopsFormHidden('op', 'start'));
$form->display();
}
else {
if (!$xoopsUser) {
echo "
Downgrade completed, please log in and go to the administration, checking that things are correct
";
}
else {
echo "";
}
}
}

function showLog($log) {
global $xoopsLogger;
if (count($log)>0) {
$msgs = implode('
', $log);
echo "

Message Log

".$msgs."

";
}
echo "

MySQL Log

".$xoopsLogger->dumpQueries()."
";
}

function alterTable($table, $field, $definition) {
global $xoopsDB;
$sql = "SHOW COLUMNS FROM ".$xoopsDB->prefix($table)." LIKE '".$field."'";
$result = $xoopsDB->queryF($sql);
if ($result) {
if ($xoopsDB->getRowsNum($result) == 0) {
$sql = "ALTER TABLE ".$xoopsDB->prefix($table)." ADD `".$field."` ".$definition;
return $xoopsDB->query($sql);
}
}
return true;
}
?>

4
jsaund22
Re: In search of the 2.2.x -> 2.0.x downgrade script
  • 2008/4/4 13:48

  • jsaund22

  • Just popping in

  • Posts: 4

  • Since: 2004/11/13


Thank you!!!

Login

Who's Online

304 user(s) are online (207 user(s) are browsing Support Forums)


Members: 0


Guests: 304


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits