Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-10 06:55:10

passionado
Member
From: Cologne
Registered: 2006-04-09
Posts: 11

Downgrading from Txp 4.5 to 4.41

Hello guys,

I was just wondering: How do I downgrade Txp from 4.5 to 4.41? My site was already done, but due to glz_custom_fields which doesn’t work with Txp 4.5 yet I’d like to publish my site with 4.41 and upgrade to Txp 4.5 later when the plugin works again. Suggestions on how to do this are greatly appreciated ;)

Offline

#2 2012-09-10 14:14:35

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Downgrading from Txp 4.5 to 4.41

Restore your site from a backup you made before updating. At minimum you will at least have to restore txp_prefs and txp_section tables to bring back removed rows and revert altered structure. After you have restored the database, you can overwrite the source files with ones from 4.4.1.

Offline

#3 2012-09-10 15:04:58

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: Downgrading from Txp 4.5 to 4.41

Gocom wrote:

Restore your site from a backup you made before updating.

LOL

Offline

#4 2012-09-10 15:29:16

Algaris
Member
From: England
Registered: 2006-01-27
Posts: 535

Re: Downgrading from Txp 4.5 to 4.41

Hey, everyone does that before upgrading, right?

Offline

#5 2012-09-10 15:57:49

passionado
Member
From: Cologne
Registered: 2006-04-09
Posts: 11

Re: Downgrading from Txp 4.5 to 4.41

let’s pretend I’m part of those minorities who didn’t: Are there any other solutions than grabbing a backup? ;)

Last edited by passionado (2012-09-10 15:58:01)

Offline

#6 2012-09-10 16:05:43

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Downgrading from Txp 4.5 to 4.41

I think it’s possible if you revert one of the database changes:
Edit the txp_section table (phpMyAdmin) and add a column called is_default with default value 0, type INT(2) (integer) and set it to 1 for the section that you previously had as the default section.

Then just install TXP 4.4.1 again, similar to how you did the upgrade to 4.5.1.
The only thing you’ve lost now is raw ?php support, but that was already deprecated a long time ago.

Just don’t forget to remove that is_default column again when you upgrade to a higher version or (and this is probably the preferred way to do this, because it will remove is_default on upgrade automatically) edit the txp_prefs table and in the row where name is version, set the value to 4.4.1 and remove the row where name is default_section.

PS. Do make a backup before attempting this :)

Or be very very brave, put this in a file called downgrade.php and place that file in your /textpattern directory and then visit it in your browser (not tested). Remove downgrade.php afterwards.

<?php
include './config.php';
include_once './lib/constants.php';
include './lib/txplib_misc.php';
include './lib/txplib_db.php';
$dbversion = safe_field('val','txp_prefs',"name='version'");
if ($dbversion !== '4.5.0')
{
  echo "DB version not 4.5.0... aborting downgrade";
}
else
{
  safe_alter('txp_section', "ADD `is_default` INT(2) DEFAULT '0' AFTER `css`");
  $default_section = safe_field('val','txp_prefs',"name='default_section'");
  safe_update('txp_section', 'is_default=1', "name='$default_section'");
  safe_delete('txp_prefs', "name = 'default_section'");
  safe_delete('txp_prefs', "name = 'version'");
  safe_insert('txp_prefs', "prefs_id=1, name='version',val='4.4.1', type='2'");
  echo "DB downgraded from 4.5.0 to 4.4.1... well at least to the point that a downgrade works.";
}
?>

Corrected code.

Last edited by ruud (2012-09-15 12:47:49)

Offline

#7 2012-09-12 20:39:13

passionado
Member
From: Cologne
Registered: 2006-04-09
Posts: 11

Re: Downgrading from Txp 4.5 to 4.41

ruud, thank you so much! Since I am (or would like to think of myself as) brave, I’ll definitely go for your php version ;). Will let you know how it worked out!

Offline

#8 2012-09-12 21:29:31

passionado
Member
From: Cologne
Registered: 2006-04-09
Posts: 11

Re: Downgrading from Txp 4.5 to 4.41

done, it worked! I had to edit your php since I got error messages that the includes couldn’t be found. I simply kicked “txpath.” and added the “.” before each “/” and voila ;)

Again, thanks for your support!

Offline

#9 2012-09-12 22:37:13

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,304

Re: Downgrading from Txp 4.5 to 4.41

Glad you answered yourself, Fabricio, I wanted to ask already whether Ruud’s code was helpful, cause it could become a lifesaver for more people until the necessary plugins are all updated.

Could you please post your final code so it’s not so error prone to edit and use?
Thanks!


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#10 2012-09-13 08:00:19

passionado
Member
From: Cologne
Registered: 2006-04-09
Posts: 11

Re: Downgrading from Txp 4.5 to 4.41

So here’s the code for the final php that worked for me: As already stated by ruud, simply create downgrade.php in your textpattern/ directory with the following code:

<?php
include './config.php';
include_once './lib/constants.php';
include './lib/txplib_misc.php';
include './lib/txplib_db.php';
$dbversion = safe_field('val','txp_prefs',"name='version'");
if ($dbversion !== '4.5.0')
{
  echo "DB version not 4.5.0... aborting downgrade";
}
else
{
  safe_alter('txp_section', "ADD `is_default` INT(2) DEFAULT '0' AFTER `css`");
  $default_section = safe_field('val','txp_prefs',"name='default_section'");
  safe_update('txp_section', 'is_default=1', "name='$default_section'");
  safe_delete('txp_prefs', "name = 'default_section'");
  safe_delete('txp_prefs', "name = 'version'");
  safe_insert('txp_prefs', "prefs_id=1, name='version',val='4.4.1', type='2'");
  echo "DB downgraded from 4.5.0 to 4.4.1... well at least to the point that a downgrade works.";
}
?>

Call downgrade.php in your browser to revert the textpattern database. Afterwards, install txp 4.4.1 like you would upgrade.

Ruud: and then remove downgrade.php!

Last edited by ruud (2012-09-15 12:36:21)

Offline

Board footer

Powered by FluxBB