Move ezp database content to drupal database

Last modified: April 4, 2006 - 00:11

[note from editor ax: you have to escape the special characters < (&lt;), > (&gt;), and & (&amp;)]

mysql -ppassword drupal < migrate.sql

The following is the content of migrate.sql:

select @uid := if(max(uid),max(uid),0) from users;
select @tid := if(max(tid),max(tid),0) from term_data;
select @nid := if(max(nid),max(nid),0) from node;
select @role_authenticated_user := rid from role where name = 'authenticated user';
select @ezp_url := "http://myezpsite.com";

#
# Insert all ezpublish articles as drupal "story" nodes
#


INSERT INTO node
(nid, type,title,uid,status,comment, promote, users, attributes, revisions, created,teaser,body)
select
id+@nid, # nid
'story', # type
name, # title
1, # uid
1, # status
2, # comment
0, # promote
'',
'',
'',
created,
contents,
contents
from ezp.eZArticle_Article
where IsPublished;



#
# Insert all ezpublish weblinks as nodes
#


select @weblink_nid:= max(nid)+1 from node;


INSERT INTO node
(nid, type, title, uid, status, comment, promote, users, attributes, revisions, created, teaser, body)
select
id+@weblink_nid,
'weblink',
name,
1,
1,
2,
0,
'',
'',
'',
created,
description,
description
from ezp.eZLink_Link;


INSERT INTO weblink
(
nid,
weblink,
click,
monitor,
#size,
change_stamp,
checked,
#feed,
refresh,
threshold,
spider_site
#spider_url
)
select
id+@weblink_nid,
if (url regexp '://', url, concat('http://', url)),
0,
0,
0,
0,
21600,
40,
0
from ezp.eZLink_Link;



#
# Discover vocabularies for ezarticle and one for ezlink
# (These established manually by drupal configure/taxonomy UI)
#

select @topic := vid from vocabulary where name = 'Topic';
select @link := vid from vocabulary where name = 'Link';



#
# Insert ezarticle_category names as terms under topics vocabulary
#

INSERT INTO term_data
(
tid,
vid,
name,
description,
weight
)
select
id+@tid,
@topic,
name,
description,
0
from ezp.eZArticle_Category;


#
# The article categories (terms) are non-hierarchical
#

insert into term_hierarchy
select id+@tid,0 from ezp.eZArticle_Category;




#
# Insert categories assigned to ezarticles
#

INSERT INTO term_node
(
nid,
tid
)
select
articleid+@nid,
categoryid+@tid
from ezp.eZArticle_ArticleCategoryLink
;


#
# Insert eZLink_Category names as terms under vocabulary links
#

select @weblink_tid := max(tid)+1 from term_data;

INSERT INTO term_data
(
tid,
vid,
name,
description,
weight
)
select
id+@weblink_tid,
@link,
name,
description,
0
from ezp.eZLink_Category;


#
# The link categories (terms) are non-hierarchical
#

insert into term_hierarchy
select id+@weblink_tid,0 from ezp.eZLink_Category;


#
# Insert categories assigned to ezlinks
#

INSERT INTO term_node
(
nid,
tid
)
select
linkid+@weblink_nid,
categoryid+@weblink_tid
from ezp.eZLink_LinkCategoryLink
;


#
# Insert users
#


INSERT INTO users
(
  uid ,
  name ,
  pass ,
  mail ,
#  mode ,
#  sort ,
# threshold ,
#  theme ,
  signature ,
  timestamp ,
  status ,
  timezone ,
#  language ,
  init ,
#  data ,
  rid
)
select
id+@uid,
login,
password, # encryption differs, so users will have to reset their passwords
email,
signature,
1074479825,
1,  # active status
0,  # timezone
email,  # init
@role_authenticated_user
from ezp.eZUser_User;




#
# drupal declares these table primary keys as auto_increment, but
# in fact actually assigns them explicitly. Update drupal's idea
# of what id to assign next for each table.
#


delete from sequences where name='users_uid';
insert into sequences (name, id)
select 'users_uid', max(uid) from users;


delete from sequences where name='term_data_tid';
insert into sequences (name, id)
select 'term_data_tid', max(tid) from term_data;


delete from sequences where name='node_nid';
insert into sequences (name, id)
select 'node_nid', max(nid) from node;


#
# Identify articles with internallinks (to be edited manually in drupal)
#

select nid from node where body regexp @ezp_url;

 
 

Drupal is a registered trademark of Dries Buytaert.