Auch hier: Projekt Strandfigur

I’m using Drupal from several sites as a CMS/CMF, e.g. Buildd.Net and SysAdmin-Jobs.de. Drupal upgrades its database with a dedicated script, which usually works well. But I experienced some problems with taxonomy terms and nodes after upgrade finished. For example all forum articles are “lost”. They are still there but have lost information to which taxonomy term they belong. And because Drupal uses taxonomy terms for its forum tree, no forum article is displayed any longer.
Same problem is with Blog articles that are tagged with taxonomy terms: the node is still there, but the taxonomy information is lost.

Looking at the databases table term_node for Drupal5 and Drupal6 makes the difference visible:

[code]
CREATE TABLE term_node
(
nid int_unsigned NOT NULL DEFAULT ‘0’::int_unsigned,
tid int_unsigned NOT NULL DEFAULT ‘0’::int_unsigned,
CONSTRAINT term_node_pkey PRIMARY KEY (tid, nid)
)
WITHOUT OIDS;
ALTER TABLE term_node OWNER TO drupal5;
[/code]

[code]
CREATE TABLE term_node
(
nid int_unsigned NOT NULL DEFAULT (‘0’::int_unsigned)::int_unsigned,
tid int_unsigned NOT NULL DEFAULT (‘0’::int_unsigned)::int_unsigned,
vid int_unsigned NOT NULL DEFAULT 0
)
WITHOUT OIDS;
ALTER TABLE term_node OWNER TO drupal6;
[/code]

So, obviously the update script of Drupal misses to store the additional table row vid somehow. At least all the difference in the table schema causes the loss of taxonomy terms of those nodes.

So, I wrote a little script called bin/drupal6_fix_taxonomy.sh to fix that problem for my PostgreSQL databases:

[code]
#!/bin/bash
# name: bin/drupal6_fix_taxonomy.sh
# usage: bin/drupal6_fix_taxonomy.sh DBUSER drupal5-db drupal6-db

USER=$1
DB1=$2
DB2=$3

ERG=`psql -t -U $USER ${DB1} -c “select nid, tid from term_node” | sed -e ‘s/|/:/g’ | tr -d ” “`

for line in `echo $ERG`; do
nid=`echo $line | cut -f1 -d”:”`
tid=`echo $line | cut -f2 -d”:”`
vid=`psql -t -U $USER ${DB2} -c “select vid from node where nid=${nid}” | tr -d ” “`
vid2=`psql -t -U $USER ${DB2} -c “select vid from term_node where nid=${nid} and tid=${tid}”`
if [ -z $vid2 ]; then
psql -U $USER ${DB2} -c “insert into term_node (nid, tid, vid) values (‘${nid}’, ‘${tid}’, ‘${vid}’)”
echo “inserted: ${nid}, ${tid}, ${vid}”
else
echo “OK: ${nid}, ${tid}, ${vid}”
fi
done
[/code]

It works for me![TM]
Use it at your own risk!

Uncategorized

2 thoughts on “Auch hier: Projekt Strandfigur

  1. Danke! Ich hoffe, dass dieses Jahr die Kniee mitmachen. Letztes Jahr hatte ich es zwar schonmal versucht, aber Beschwerden im rechten Knie gehabt. Orthopaede und MRT konnten aber nichts finden… mal schauen, wie das nun wird…

Comments are closed.