Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-06-23 11:54:22

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 638
Website

Move content from one field to another using MySQL?

Hey!
I need to move content from one field (Body) to a custom-field for a specific section.
(I was gonna do this manual but there are like 500+/- articles I need this change for)
Yes of course I will make a backup first ;)
But is it possible please?
and do I just going to mysql of my txp database and run a query in the SQL tab?

Offline

#2 2010-06-23 12:17:40

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

Re: Move content from one field to another using MySQL?

Gil, I only swapped Body and Excerpt, but the following should work with cf’s too:

UPDATE textpattern SET custom_n = Body  WHERE Section = 'your-section';
UPDATE textpattern SET Body = ''  WHERE Section = 'your-section', SET Body_html = ''  WHERE Section = 'your-section';

Yes, backup, fine! ;)

Edit: Forgot to restrict to a section

Last edited by uli (2010-06-23 12:24:58)


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

Offline

#3 2010-06-23 12:40:00

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

Re: Move content from one field to another using MySQL?

Hm, does the first two operations when applied solo, but goes on strike for Body_html, even if surrounded by awry ` apostrophes. So probably useless.


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

Offline

#4 2010-06-23 13:13:57

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 638
Website

Re: Move content from one field to another using MySQL?

Thanks the first query works good as copying from one field to another in a specific section.
(really simple! :)

The second query (that removes the content from the source field) return an error,
so I removed the , SET Body_html = '' WHERE Section = 'your-section' part from it, and it does works.

Do I need the code with the part of Body_html? what does it’s doing?
(I’m doing tests on a local txp test installation, so I don’t afraid playing with it)

Offline

#5 2010-06-23 13:31:51

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

Re: Move content from one field to another using MySQL?

THE BLUE DRAGON wrote:

Do I need the code with the part of Body_html? what does it’s doing?

It empties Body_html. The Body_html column contains all the Textiled content. TXP generates the HTML from textile when the article is saved and cache the markup in Body_html field.

Thanks the first query works good as copying from one field to another in a specific section.

Remember that the varchar(255) field can only store max. of 255 characters. If your body contains more, you need to change the fieldtype from varchar or increase the maximum lenght.

uli wrote:

UPDATE textpattern SET Body = '' WHERE Section = 'your-section', SET Body_html = '' WHERE Section = 'your-section';

Close, but instead of replicating set, you can set multiple fields once. In MySQL you can use comma seperated list of fields.

UPDATE textpattern SET custom_n = Body, Body = '', Body_html = ''  WHERE Section='your-section'

Offline

#6 2010-06-23 13:35:18

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

Re: Move content from one field to another using MySQL?

THE BLUE DRAGON wrote:

Do I need the code with the part of Body_html? what does it’s doing?

TXP stores articles in both Textile and HTML-tagged formats, and uses the tagged version – as far as I remember – to quickly compose the page when called. Try to call an article that’s only left as HTML_body anymore and see if it’s still available for display. If so you’re stuck.


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

Offline

#7 2010-06-23 13:38:24

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

Re: Move content from one field to another using MySQL?

Gocom wrote:

UPDATE textpattern SET custom_n = Body, Body = '', Body_html = ''  WHERE Section='your-section'

Thanks, pasted over into the tools sheet :)


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

Offline

#8 2010-06-23 13:54:47

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 638
Website

Re: Move content from one field to another using MySQL?

So if I don’t use Textile at all (using only ‘convert linebreaks’)
so I don’t need to empty the Body_html?
or TXP always also stores body&excerpt fields in Textile if I want it or not, and I need to empty them too?
if so for excerpt will it be Excerpt_html?

Offline

#9 2010-06-23 14:36:54

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

Re: Move content from one field to another using MySQL?

THE BLUE DRAGON wrote:

So if I don’t use Textile at all (using only ‘convert linebreaks’)

The pre-formated body/excerpt is always saved to (and returned from) the Body_html. Note that also converting linebreaks requires formating and parsing the body.

or TXP always also stores body&excerpt fields in Textile if I want it or not, and I need to empty them too?

Parsing Textile requires time. Thus, the body and excerpt fiels are pre-parsed when you save the article. Content is always fetched from Body_html and Excerpt_html.

if so for excerpt will it be Excerpt_html?

Yes.

Offline

#10 2010-06-23 15:35:05

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 638
Website

Re: Move content from one field to another using MySQL?

Cool! works great. thank you Jukka & Uli =)

Offline

Board footer

Powered by FluxBB