Import drupal database table data to wordpress database - wordpress

i have my current working site on wordpress. i want to import data from database which had in another server working on drupal. How can i import all the data from table in drupal site to my current working website database in wordpress. Please help me with this

First Option : Steps and applicable queries to migrate your Drupal database to WordPress:
1. Make a backup of both your Drupal and WordPress databases.
2. Before converting Drupal to WordPress, make sure that in your original Drupal install the taxonomies are correctly labeled. Step 11 will further discuss fixing taxonomy.
3. Create a new WordPress installation in a different database
from your Drupal installation. Name the different databases
‘drupal’ and ‘wordpress’.
4. Clear out previous content from the WordPress database by
running this command in your database’s SQL queries tab in
phpmyadmin.
TRUNCATE TABLE wordpress.wp_comments;
TRUNCATE TABLE wordpress.wp_links;
TRUNCATE TABLE wordpress.wp_postmeta;
TRUNCATE TABLE wordpress.wp_posts;
TRUNCATE TABLE wordpress.wp_term_relationships;
TRUNCATE TABLE wordpress.wp_term_taxonomy;
TRUNCATE TABLE wordpress.wp_terms;
5. Apply this code to convert over multiple users.
DELETE FROM wordpress.wp_users WHERE ID > 1;
DELETE FROM wordpress.wp_usermeta WHERE user_id > 1;
6. To migrate over tags, use the following code...
(To ensure duplicate names don’t get lost, make sure that the
Drupal term_data table has been cleaned of all duplicate names.)
REPLACE INTO wordpress.wp_terms
(term_id, `name`, slug, term_group)
SELECT DISTINCT
d.tid,
d.name,
REPLACE(LOWER(d.name), ' ', '_'), 0
FROM drupal.term_data d
INNER JOIN drupal.term_hierarchy h
USING(tid)
WHERE (1
)
;
INSERT INTO wordpress.wp_term_taxonomy
(term_id, taxonomy, description, parent)
SELECT DISTINCT
d.tid `term_id`,
'post_tag' `taxonomy`,
d.description `description`,
h.parent `parent`
FROM drupal.term_data d
INNER JOIN drupal.term_hierarchy h
USING(tid)
INNER JOIN drupal.term_node n
USING(tid)
WHERE (1
)
;
7. To convert over posts, apply the following query:
INSERT INTO wordpress.wp_posts
(id, post_author, post_date, post_content, post_title,
post_excerpt, post_name, post_modified, post_type,
`post_status`)
SELECT DISTINCT
n.nid `id`,
n.uid `post_author`,
FROM_UNIXTIME(n.created) `post_date`,
r.body `post_content`,
n.title `post_title`,
r.teaser `post_excerpt`,
IF(SUBSTR(a.dst, 11, 1) = '/', SUBSTR(a.dst, 12),
a.dst) `post_name`,
FROM_UNIXTIME(n.changed) `post_modified`,
n.type `post_type`,
IF(n.status = 1, 'publish', 'private') `post_status` FROM
drupal.node n
INNER JOIN drupal.node_revisions r
USING(vid)
LEFT OUTER JOIN drupal.url_alias a
ON a.src = CONCAT('node/', n.nid)
# If applicable, add more Drupal content types below.
WHERE n.type IN ('post', 'page', 'blog')
;
*If your Drupal installation has multiple post types, be sure to
add the name of the post type into this line: WHERE n.type IN
(‘post’, ‘page’, ‘blog’). Failure to do so will result in not all posts
types being converted over.
8. To combine post types in WordPress, run this script:
UPDATE wordpress.wp_posts
SET post_type = 'post' WHERE
post_type IN ('blog') ;
9. To define the post/tag relationship, apply the following:
INSERT INTO wordpress.wp_term_relationships (object_
id, term_taxonomy_id)
SELECT DISTINCT nid, tid FROM drupal.term_node
;
# Update tag counts.
UPDATE wp_term_taxonomy tt
SET `count` = (
SELECT COUNT(tr.object_id)
FROM wp_term_relationships tr
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id
)
;
10.Apply this query to migrate comments:
INSERT INTO wordpress.wp_comments
(comment_post_ID, comment_date, comment_content,
comment_parent, comment_author,
comment_author_email, comment_author_url, comment_
approved)
SELECT DISTINCT
nid, FROM_UNIXTIME(timestamp), comment, thread, name,
mail, homepage, ((status + 1) % 2)
FROM drupal.comments
;
# Update comments count on wp_posts table.
UPDATE wordpress.wp_posts
SET `comment_count` = (
SELECT COUNT(`comment_post_id`)
FROM wordpress.wp_comments
WHERE wordpress.wp_posts.`id` = wordpress.wp_
comments.`comment_post_id`
)
;
11.You do not have to do anything if you want to keep your
Drupal images and files in the same location, but if you are
FTP-ing your files to the uploads folder in your WordPress
wp-content folder, use the following code to fix the image
URLs.
UPDATE wordpress.wp_posts SET post_content =
REPLACE(post_content, ‚“/files/‘, ‚“/wp-content/
uploads/‘);
12.To fix taxonomy (assuming you’ve set it up correctly in your
original Drupal site), use the following code:
UPDATE IGNORE wordpress.wp_term_relationships,
wordpress.wp_term_taxonomy
SET wordpress.wp_term_relationships.term_taxonomy_id =
wordpress.wp_term_taxonomy.term_taxonomy_id
WHERE wordpress.wp_term_relationships.term_taxonomy_id
= wordpress.wp_term_taxonomy.term_id
;
13.To assign author roles for your users, here’s the code:
INSERT IGNORE INTO wordpress.wp_users
(ID, user_login, user_pass, user_nickname, user_email,
user_registered, user_activation_key, user_status,
display_name)
SELECT DISTINCT
u.uid, u.mail, NULL, u.name, u.mail,
FROM_UNIXTIME(created), ‚' ', 0, u.name
FROM drupal.users u
INNER JOIN drupal.users_roles r
USING (uid)
WHERE (1
# Uncomment and enter any email addresses you want to
exclude below.
# AND u.mail NOT IN (‚test#example.com‘)
)
;
14.Here’s the code you can use to set the author role’s permissions:
INSERT IGNORE INTO wordpress.wp_usermeta (user_id,
meta_key, meta_value)
SELECT DISTINCT
u.uid, 'wp_capabilities',
'a:1:{s:6:“author“;s:1:“1“;}'
FROM drupal.users u
INNER JOIN drupal.users_roles r
USING (uid)
WHERE (1
# Uncomment and enter any email addresses you want to
exclude below.
# AND u.mail NOT IN ('test#example.com')
)
;
INSERT IGNORE INTO wordpress.wp_usermeta (user_id,
meta_key, meta_value)
SELECT DISTINCT
u.uid, 'wp_user_level', '2'
FROM drupal.users u
INNER JOIN drupal.users_roles r
USING (uid)
WHERE (1
# Remove and enter any email addresses you want to
exclude below.
# AND u.mail NOT IN ('test#example.com')
)
;
You can remove the number sign before the line that has
the email address and put your own in so that your remain
the administrator.
15.Use this code to assign and give administrator status:
UPDATE wordpress.wp_usermeta
SET meta_value = 'a:1:{s:13:“administrator“;s:1:“1“;}‘
WHERE user_id IN (1) AND meta_key = 'wp_capabilities' ;
UPDATE wordpress.wp_usermeta
SET meta_value = '10'
WHERE user_id IN (1) AND meta_key = 'wp_user_level'
;
16.This code will help assign authors to the posts they wrote:
UPDATE wordpress.wp_posts
SET post_author = NULL
WHERE post_author NOT IN (SELECT DISTINCT ID FROM
wordpress.wp_users)
;
17. You can then feed the following code for the editor to help
clean it up so that your posts don’t look bizarre after the
conversion.
UPDATE wordpress.wp_posts
SET post_name =
REVERSE(SUBSTRING(REVERSE(post_
name),1,LOCATE('/',REVERSE(post_name))-1)) ;
That’s the basics of migrating your Drupal site to WordPress.
Second Option : Using with Plugin To Migrate you Drupal Database to Wordpress
In this section, we’ll be using the FG Drupal to WordPress plugin to carry out our migration. This tool is remarkably simple to use, and we’ll cover how to use it in this piece. However, if you do happen to run into any errors, the plugin’s documentation should see you through.
It’s worth noting this plugin also comes in a premium version, but the free option is more than enough to carry out a regular migration. However, if you’re looking to move multiple authors, your comments, users, and even custom post types, the premium version might be worth considering.
Step #1: Install and activate the FG Drupal to WordPress plugin
Step #2: Find out your Drupal database parameters
Step #3: Import your Drupal content into WordPress
Get more details, you can follow the link - How to migrate Drupal to WordPress (in 3 steps)

Related

DELETE from same table used in the WHERE

I have the following query that is supposed to delete from a table with a circular FK requirement;
DELETE FROM question
WHERE defaultGotoQuestionId IN (
SELECT id from question WHERE facilityId IN (
SELECT id FROM facility WHERE customerId NOT IN (1,76)
)
);
But I get the following error;
Table is specified twice, both as a target for 'DELETE' and as a separate source for data
I understand the error message - that I can't DELETE from a TABLE that I am specifying in the WHERE - I just can't seem to work out how to solve it, for myself.
I saw a few examples of using a join - but perhaps I am having an off day - because I have been iterating through copy/paste examples - but still can't manage it.
It works as a SELECT : In that the result gives me the records I want to delete;
SELECT id FROM question
WHERE defaultGotoQuestionId IN (
SELECT id from question WHERE facilityId IN (
SELECT id FROM facility WHERE customerId NOT IN (1,76)
)
);
Thanks for any help!
What version of MariaDB are you using?
DELETE :: Same Source and Target Table
Until MariaDB 10.3.1, deleting from a table with the same source and target was not possible. From MariaDB 10.3.1, this is now possible.
See dbfiddle.
In older versions of MariaDB (or in MySQL, for example), one option you can use is:
DELETE
`question`
FROM
`question`
INNER JOIN (
SELECT
`id`
FROM
`question`
WHERE
`defaultGotoQuestionId` IN (
SELECT
`id`
FROM
`question`
WHERE
`facilityId` IN (
SELECT
`id`
FROM
`facility`
WHERE
`customerId` NOT IN (1, 5)
)
)
) `der` ON
`question`.`id` = `der`.`id`;
See dbfiddle.

Retrieve Record Based on a Value Existing in Record's Association Table

I have two tables. posts is the record I want, whilst post_tags allows a one-to-many relationship between them. NB. I have this working, however, they do not feel efficient to me and I could do with some SQLite gurus to help me out.
posts
id
post_tags
post_id
tag
Exact Match
I want to be able to retrieve posts that match a specific tag that I pass in.
Here is my current query.
SELECT * FROM posts WHERE "desiredTag" IN (SELECT tag FROM post_tags WHERE post_id = posts.id AND tag = "desiredTag");
One Of
My next requirement is an adaptation of the first. Instead of just matching one tag, I want to be able to pass in an array of tags and posts to be returned when they match at least one of the passed in tags. Again, I have this working but inefficiently.
SELECT * FROM posts WHERE ("tagOne" IN (SELECT tag FROM post_tags WHERE post_id = posts.id AND tag = "tagOne") OR "tagTwo" IN (SELECT tag FROM post_tags WHERE post_id = posts.id AND tag = "tagTwo"));
Usually EXISTS performs better:
SELECT p.*
FROM posts p
WHERE EXISTS (SELECT 1 FROM tag t WHERE t.post_id = p.id AND t.tag IN ('tag1', 'tag2'))
Or you could do it with an INNER JOIN:
SELECT DISTINCT p.*
FROM posts p INNER JOIN tag t
ON t.post_id = p.id
WHERE t.tag IN ('tag1', 'tag2')

SORT CRITERIA not working properly

Running drupal 7.22, I need to add an option to sort to a view - Content type Lecture which is associated with Curses.
In the Curse page I need to display the Lecture in a certain order.
The Lecture are dispayed in the following way
print views_embed_view('lecture_list_of_online_courses','block', $node->nid);
I tried the following simple solution -
added field 'my_wight' to the lecture content type
added values from 1 to 10 according to the necessary order.
add SORT CRITERIA to the lecture_list_of_online_courses view
result: the view displayed in a sort that seems to have nothing to do with the values I added to 'my_wight'
I've been working with drupal many times before, and did this sort of things more than once.
I can get whats wrong with this.
here is the resulting SQL query from the View -
SELECT node_field_data_field_oc_forum_reference.nid AS node_field_data_field_oc_forum_reference_nid, node_field_data_field_oc_forum_reference.title AS node_field_data_field_oc_forum_reference_title, node_field_data_field_oc_forum_reference.language AS node_field_data_field_oc_forum_reference_language, node_field_data_field_oc_forum_reference.type AS node_field_data_field_oc_forum_reference_type, node_field_data_field_oc_forum_reference.comment AS node_field_data_field_oc_forum_reference_comment, field_data_field_lecture_weight.field_lecture_weight_value AS field_data_field_lecture_weight_field_lecture_weight_value, 'node' AS field_data_body_node_entity_type
FROM
{node} node
LEFT JOIN {field_data_field_oc_forum_reference} field_data_field_oc_forum_reference ON node.nid = field_data_field_oc_forum_reference.entity_id AND (field_data_field_oc_forum_reference.entity_type = 'node' AND field_data_field_oc_forum_reference.deleted = '0')
INNER JOIN {node} node_field_data_field_oc_forum_reference ON field_data_field_oc_forum_reference.field_oc_forum_reference_nid = node_field_data_field_oc_forum_reference.nid
LEFT JOIN {field_data_field_lecture_weight} field_data_field_lecture_weight ON node.nid = field_data_field_lecture_weight.entity_id AND (field_data_field_lecture_weight.entity_type = 'node' AND field_data_field_lecture_weight.deleted = '0')
WHERE (( (node.nid = '175' ) )AND(( (node.status = '1') AND (node.type IN ('online_courses')) )))
ORDER BY field_data_field_lecture_weight_field_lecture_weight_value DESC
I cannot run this query - any idea why?
First - for the SQL to work you must remove '{' and '}' from the query
Second - When creating the SORT CRITERIA, u need to chose 'Relationship' in the settings of the SORT CRITERIA

Previous/next navigation that uses ordering/sorting different than node id (n.nid)

I am trying to create "previous/next node" navigation on my nodes in order to show 2 previous and 2 following nodes in the term currently being viewed. Here is the code that displays 2 prev and 2 next nodes, but it is not taxonomy aware, i. e. it sorts nodes according to their IDs:
Prev/Next node navigation with a thumbnail in a full node
If I add a node in the term after some time, it will display this node as the last one, not as a "neighbour" of a node uploaded e.g. 3 months ago.
I have tried with "n.title", but it doesn't change anything. Ideally, it should order them either by titles or url aliases.
Thank you in advance!
it's not querying the taxonomy tables in the database query. You probably want to add a variable to the function as such dad_prev_next($current_node = NULL, $op = 'p', $tid) to pass it the term ID and then add that to your query through an inner join
SELECT n.nid, n.title
FROM {node} n
INNER JOIN {taxonomy_index} t
ON n.nid = t.nid
WHERE n.nid $sql_op :nid
AND t.tid = :tid
AND type IN ('photos')
AND status = 1
ORDER BY n.nid $order
LIMIT 1
I think that should be pretty close, then just pass that at the end of db_query db_query($sql, array(':nid' => $current_node -> nid, ':tid' => $tid));
Newer version of Previous/Next module has multiple options for sorting prev/next nodes. You can use the workaround to get thumbnails too:
http://drupal.org/project/prev_next
http://drupal.org/node/1790290

sql server: select either conditions using an OR clause?

I have a Products tablet; in that there are a couple of fields like subcatid and designerid, which are coming from a Subcategories and Designers tables respectively. The website (ASP.NET C#) admin can insert some kind of Coupon Codes in a CouponCodes table by selecting either a designerid or a subcatid or both. This means that a particular product can be sold cheaper if either designerid or the subcatid fields or both for that product is found inside the CouponCodes table. Note, a Product does not necessarily have a designerid or a subcatid: An Admin can enter 'N/A' for either as Product is entered; the N/A has designerid of 27 and a subcatid of 9 in their respective tables. Probably not the best database design.
Anyway, here is my code in SSMS; when I try execute it I get an error of syntax. How to implement the sql? Thanks!
select * from couponcodes
where ( couponcodes.subcatid in
(select subcatid from Products where Products.prodid = 1012)
AND (couponcodes.couponcode = '5braceLets'))
OR
Where ( couponcodes.designerid in
(select designerid from Products where Products.prodid = 1012)
AND (couponcodes.couponcode = '5dora'))
You have where twice which is causing the syntax error. What you want to do is
select * from couponcodes
where ( couponcodes.subcatid in
(select subcatid from Products where Products.prodid = 1012)
AND (couponcodes.couponcode = '5braceLets'))
OR
( couponcodes.designerid in
(select designerid from Products where Products.prodid = 1012)
AND (couponcodes.couponcode = '5dora'))

Resources