/*
 * Correct path of images
*/
UPDATE node_revisions NR
INNER JOIN node N ON N.nid = NR.nid
SET NR.body = REPLACE(REPLACE(NR.body, 'http://www.behrmanhouse.com/emailimgs/', '/sites/default/files/emailimgs/'), '../../emailimgs/', '/sites/default/files/emailimgs/'),
  NR.teaser = REPLACE(REPLACE(NR.teaser, 'http://www.behrmanhouse.com/emailimgs/', '/sites/default/files/emailimgs/'), '../../emailimgs/', '/sites/default/files/emailimgs/')
WHERE N.type = 'blog'
  AND NR.body like '%emailimgs/%'
  
/* Update password */
UPDATE users U
INNER JOIN wp_users WU ON U.name = WU.user_nicename
SET U.pass = 'phpass'
WHERE name <> 'admin'
  AND WU.user_pass LIKE '%$%'

/* Assign role blogger rid = 3 */
INSERT INTO users_roles (uid, rid)
SELECT DISTINCT U.uid, 3
FROM users U
INNER JOIN wp_users WU ON U.name = WU.user_login
LEFT JOIN users_roles UR ON UR.uid = U.uid
WHERE IFNULL(UR.rid, -1) <> 3
  AND U.uid NOT IN (SELECT uid FROM users_roles WHERE rid <> 3)
  AND U.name <> 'admin'

  
/* Move passwords from wordpress to Drupal */
INSERT INTO user_phpass (uid, hash)
SELECT DISTINCT U.uid, WU.user_pass
FROM users U
INNER JOIN wp_users WU ON U.name = WU.user_login
INNER JOIN users_roles UR ON UR.uid = U.uid
WHERE U.pass = 'phpass'
  AND UR.rid = 3
  AND U.name <> 'admin'
  AND U.uid NOT IN (SELECT uid FROM user_phpass)
  AND WU.user_pass LIKE '%$%'
  
/*  Move "simple" md5() passwords to Drupal */  
UPDATE users U
INNER JOIN wp_users WU ON U.name = WU.user_login
INNER JOIN users_roles UR ON UR.uid = U.uid
SET U.pass = WU.user_pass
WHERE UR.rid = 3
  AND U.name <> 'admin'
  AND NOT WU.user_pass LIKE '%$%'