├── .gitattributes ├── LICENSE.txt ├── README.md ├── .gitignore ├── php-mysql.php └── Drupal2Wordpress.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) [2015] [Robin Singh] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Drupal 7 to Wordpress 3.9 / 4.x 2 | 3 | ## Features 4 | 5 | This script supports the migration of the following items: 6 | * Content (Drupal nodes) - nodes of type "article" are migrated into Wordpress as 'post' content type, and any other Drupal node content type is migrated into Wordpress as 'page' content type. All nodes are imported with their original owner user id, timestamp, published or unpublished state. With regards to SEO, Drupal's leading 'content/' prefix for any page is removed. 7 | * Categories - Wordpress 3.9 requires that any blog post is associated with at least one category, and not just a tag, hence the script will create a default 'Blog' category and associate all of the content created into that category. 8 | * Taxonomies 9 | * Comments on Content (up to 11 levels of threaded comments) - only approved comments are imported due to the high level of spam which Drupal sites might endure (in Drupal this means all comments with status 1) 10 | * Users - Drupal's user id 0 (anonymous) and user id 1 (site admin) are ignored. User's basic information is migrated, such as username, e-mail and creation date. Users are migrated with no password, which means in Wordpress that they can't login and must reset their account details (this is due to security reasons). 11 | 12 | See also: http://fuzzythinking.davidmullens.com/content/moving-from-drupal-7-to-wordpress-3-3/ to get an insight of the underlying logic. 13 | 14 | 15 | ## Preparing the migration 16 | 17 | * The script assumes a fresh Wordpress 3.9 installation with just the administrative user account. 18 | * The script itself needs to be configured settings the proper values in the .php file. 19 | * Additionally, you need to perform a basic wp install (just copy the wp files, configure wp-config.php and point your browser to the root URL of your instance, complete the basic setup, and run your Drupal2WordPress script. 20 | 21 | 22 | ## Success Stories on the news 23 | * mjreed on migrating Drupal 7 to Wordpress 4: http://mjreed.com/how-to-migrate-from-drupal-7-to-wordpress-4/ 24 | * chris on migrating a Drupal 7 to Wordpress 4: http://chrisadas.com/2014/09/22/drupal2wordpress-script/ 25 | 26 | # Contributors 27 | 28 | * Liran Tal (http://www.enginx.com) 29 | * versvs (http://www.versvs.net) 30 | * Ali Sadattalab (http://twitter.com/xbox3000) 31 | 32 | 33 | 34 | # To Do 35 | 36 | * [LiranTal] Support importing the media resources that were uploaded to Drupal or referrenced to a Drupal install 37 | * [LiranTal] Code clean up with the comments 11 levels foreach() nesting (should possibly be replaced with a recursive function) 38 | 39 | # Changelog 40 | 41 | * [versvs] Script built upon the foundation of robinflyhigh's work. 42 | * [versvs] fixed some details regarding post type and post status after migration, and also improved it so it can migrate up to 11 levels of nested comments. 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | -------------------------------------------------------------------------------- /php-mysql.php: -------------------------------------------------------------------------------- 1 | host = $connection['host']; 29 | $this->user = $connection['username']; 30 | $this->pass = $connection['password']; 31 | $this->name = $connection['database']; 32 | $this->port = null; 33 | $this->socket = null; 34 | if (!empty($connection['port'])){ 35 | $this->port = $connection['port']; 36 | } 37 | if (!empty($connection['socket'])){ 38 | $this->socket = $connection['socket']; 39 | } 40 | } 41 | else if (!empty($connection) && is_array($connection)){ 42 | foreach ($connection as $c){ 43 | if (!empty($c['host']) && !empty($c['username']) && !empty($c['password']) && !empty($c['database']) && !empty($c['alias'])){ 44 | if (empty($c['port'])){ 45 | $c['port'] = null; 46 | } 47 | if (empty($c['socket'])){ 48 | $c['socket'] = null; 49 | } 50 | 51 | if (!empty($c['mode']) && ($c['mode'] == "r" || $c['mode'] == "w" || $c['mode'] == "rw")){ 52 | $mode = $c['mode']; 53 | unset($c['mode']); 54 | $this->connections[$mode][$c['alias']] = $c; 55 | } 56 | else{ 57 | unset($c['mode']); 58 | $this->connections['rw'][$c['alias']] = $c; 59 | } 60 | } 61 | } 62 | } 63 | } 64 | 65 | //Confirm the server is accessible 66 | public function check($connection=null){ 67 | $port = $socket = null; 68 | if (!empty($connection)){ 69 | if (!empty($this->connections['r'][$connection]['host']) && !empty($this->connections['r'][$connection]['username']) && !empty($this->connections['r'][$connection]['password']) && !empty($this->connections['r'][$connection]['database'])){ 70 | if (!empty($this->connections['r'][$connection]['port'])){ 71 | $port = $this->connections['r'][$connection]['port']; 72 | } 73 | if (!empty($this->connections['r'][$connection]['socket'])){ 74 | $socket = $this->connections['r'][$connection]['socket']; 75 | } 76 | 77 | $dbc = @mysqli_connect($this->connections['r'][$connection]['host'],$this->connections['r'][$connection]['username'],$this->connections['r'][$connection]['password'],$this->connections['r'][$connection]['database'],$port,$socket); 78 | if (mysqli_connect_errno()){ 79 | return false; 80 | } 81 | } 82 | else if (!empty($this->connections['w'][$connection]['host']) && !empty($this->connections['w'][$connection]['username']) && !empty($this->connections['w'][$connection]['password']) && !empty($this->connections['w'][$connection]['database'])){ 83 | if (!empty($this->connections['w'][$connection]['port'])){ 84 | $port = $this->connections['w'][$connection]['port']; 85 | } 86 | if (!empty($this->connections['w'][$connection]['socket'])){ 87 | $socket = $this->connections['w'][$connection]['socket']; 88 | } 89 | 90 | $dbc = @mysqli_connect($this->connections['w'][$connection]['host'],$this->connections['w'][$connection]['username'],$this->connections['w'][$connection]['password'],$this->connections['w'][$connection]['database'],$port,$socket); 91 | if (mysqli_connect_errno()){ 92 | return false; 93 | } 94 | } 95 | else if (!empty($this->connections['rw'][$connection]['host']) && !empty($this->connections['rw'][$connection]['username']) && !empty($this->connections['rw'][$connection]['password']) && !empty($this->connections['rw'][$connection]['database'])){ 96 | if (!empty($this->connections['rw'][$connection]['port'])){ 97 | $port = $this->connections['rw'][$connection]['port']; 98 | } 99 | if (!empty($this->connections['rw'][$connection]['socket'])){ 100 | $socket = $this->connections['rw'][$connection]['socket']; 101 | } 102 | 103 | $dbc = @mysqli_connect($this->connections['rw'][$connection]['host'],$this->connections['rw'][$connection]['username'],$this->connections['rw'][$connection]['password'],$this->connections['rw'][$connection]['database'],$port,$socket); 104 | if (mysqli_connect_errno()){ 105 | return false; 106 | } 107 | } 108 | } 109 | else{ 110 | if (!empty($this->host) && !empty($this->name) && !empty($this->user) && !empty($this->pass)){ 111 | $dbc = @mysqli_connect($this->host,$this->user,$this->pass,$this->name,$port,$socket); 112 | if (mysqli_connect_errno()){ 113 | return false; 114 | } 115 | } 116 | else if (!empty($this->connections)){ 117 | $output = array(); 118 | foreach ($this->connections as $conns){ 119 | foreach ($conns as $k=>$v){ 120 | if (!empty($v['host']) && !empty($v['username']) && !empty($v['password']) && !empty($v['database'])){ 121 | $port = $socket = null; 122 | if (!empty($v['port'])){ 123 | $port = $v['port']; 124 | } 125 | if (!empty($v['socket'])){ 126 | $socket = $v['socket']; 127 | } 128 | 129 | $dbc = @mysqli_connect($v['host'],$v['username'],$v['password'],$v['database'],$port,$socket); 130 | if (mysqli_connect_errno()){ 131 | $output[$k] = 0; 132 | } 133 | else{ 134 | $output[$k] = 1; 135 | } 136 | } 137 | else{ 138 | $output[$k] = 0; 139 | } 140 | } 141 | } 142 | 143 | return $output; 144 | } 145 | else{ 146 | return false; 147 | } 148 | } 149 | return true; 150 | } 151 | 152 | 153 | // Opens a connection to the database and sets up mysql_query object 154 | public function query($sql){ 155 | $mode = "r"; 156 | $args = func_get_args(); 157 | array_shift($args); 158 | 159 | if (isset($args[0]) and is_array($args[0])){ 160 | if (!empty($args[1]) && count($args)==2){ 161 | $mode = $args[1]; 162 | } 163 | $args = $args[0]; 164 | } 165 | 166 | $result = $this->run_query($sql,$args); 167 | 168 | return $result; 169 | } 170 | 171 | 172 | private function run_query($sql,$args=array(),$mode="r"){ 173 | if (!empty($sql) && !is_array($sql)){ 174 | $sql = array("query" => $sql); 175 | } 176 | 177 | if (is_string($args)){ 178 | $args = func_get_args(); 179 | array_shift($args); 180 | } 181 | 182 | if (!empty($sql['show_error'])){ 183 | $show_error = $sql['show_error']; 184 | } 185 | else{ 186 | $show_error = TRUE; 187 | } 188 | 189 | if (!empty($this->host) && !empty($this->name) && !empty($this->user) && !empty($this->pass)){ 190 | $connection = array( 191 | "host" => $this->host, 192 | "username" => $this->user, 193 | "password" => $this->pass, 194 | "database" => $this->name, 195 | "port" => $this->port, 196 | "socket" => $this->socket 197 | ); 198 | } 199 | else if (!empty($this->connections)){ 200 | $arr1 = $arr2 = array(); 201 | 202 | if ($mode == "r"){ 203 | if (!empty($this->connections['r'])){ 204 | $arr1 = $this->connections['r']; 205 | } 206 | if (!empty($this->connections['rw'])){ 207 | $arr2 = $this->connections['rw']; 208 | } 209 | $arr3 = array_merge($arr1,$arr2); 210 | } 211 | else if ($mode == "w"){ 212 | if (!empty($this->connections['w'])){ 213 | $arr1 = $this->connections['w']; 214 | } 215 | if (!empty($this->connections['rw'])){ 216 | $arr2 = $this->connections['rw']; 217 | } 218 | $arr3 = array_merge($arr1,$arr2); 219 | } 220 | 221 | if (!empty($arr3)){ 222 | if (count($arr3)==1){ 223 | $connection = $arr3[0]; 224 | } 225 | else{ 226 | $random = rand(0,count($arr3)-1); 227 | $connection = $arr[$random]; 228 | } 229 | } 230 | } 231 | 232 | 233 | if (empty($connection)){ 234 | printf("Invalid Database Connection"); 235 | exit; 236 | } 237 | 238 | if ($this->connPool[$connection['database']]) { 239 | $conn = $this->connPool[$connection['database']]; 240 | } 241 | else { 242 | $conn = @mysqli_connect($connection['host'],$connection['username'],$connection['password'],$connection['database'],$connection['port'],$connection['socket']); 243 | $this->connPool[$connection['database']] = $conn; 244 | } 245 | $this->conn = $conn; 246 | 247 | if (mysqli_connect_errno()){ 248 | printf("Connect failed: %s\n", mysqli_connect_error()); 249 | exit; 250 | } 251 | 252 | $this->string_sanitize($args, TRUE); 253 | $query = preg_replace_callback(DB_QUERY_REGEXP, array(&$this, 'string_sanitize'), $sql['query']); 254 | mysqli_query($conn,"SET NAMES 'utf8'"); 255 | $result = mysqli_query($conn, $query); 256 | 257 | if (!$result){ 258 | if ($show_error){ 259 | echo "Error querying database. : $query
"; 260 | } 261 | } 262 | else{ 263 | return $result; 264 | } 265 | } 266 | 267 | // Executes query and filters results into a single array or object 268 | public function row($sql){ 269 | if (!empty($sql['output'])){ 270 | if ($sql['output'] == "array" || $sql['output'] == "object"){ 271 | $type = $sql['output']; 272 | } 273 | else{ 274 | $type = "array"; 275 | } 276 | } 277 | else{ 278 | $type = "array"; 279 | } 280 | 281 | $args = func_get_args(); 282 | array_shift($args); 283 | 284 | if (isset($args[0]) and is_array($args[0])){ 285 | $args = $args[0]; 286 | } 287 | 288 | $result = $this->run_query($sql,$args); 289 | 290 | if ($result){ 291 | $row = mysqli_fetch_assoc($result); 292 | if ($type == "array"){ 293 | return $row; 294 | } 295 | if ($type == "object"){ 296 | return (object) $row; 297 | } 298 | } 299 | } 300 | 301 | // Executes query and filters results into an array or object 302 | public function results($sql){ 303 | if (!empty($sql['output'])){ 304 | if ($sql['output'] == "array" || $sql['output'] == "object"){ 305 | $type = $sql['output']; 306 | } 307 | else{ 308 | $type = "array"; 309 | } 310 | } 311 | else{ 312 | $type = "array"; 313 | } 314 | 315 | $args = func_get_args(); 316 | array_shift($args); 317 | 318 | if (isset($args[0]) and is_array($args[0])){ 319 | $args = $args[0]; 320 | } 321 | 322 | $result = $this->run_query($sql,$args); 323 | 324 | $return = array(); 325 | 326 | while ($row = mysqli_fetch_assoc($result)){ 327 | if ($type == "array"){ 328 | $return[] = $row; 329 | } 330 | if ($type == "object"){ 331 | $return[] = (object) $row; 332 | } 333 | } 334 | 335 | if ($result){ 336 | if ($type == "array"){ 337 | return $return; 338 | } 339 | if ($type == "object"){ 340 | return (object) $return; 341 | } 342 | } 343 | } 344 | 345 | // Executes query and returns row count for result set 346 | public function count($sql){ 347 | 348 | $args = func_get_args(); 349 | array_shift($args); 350 | 351 | if (isset($args[0]) and is_array($args[0])){ 352 | $args = $args[0]; 353 | } 354 | 355 | $result = $this->run_query($sql,$args); 356 | 357 | if ($result){ 358 | $row = mysqli_num_rows($result); 359 | return $row; 360 | } 361 | 362 | return 0; 363 | } 364 | 365 | // Executes query and returns affected row count for result set 366 | public function affected_rows($sql){ 367 | 368 | $args = func_get_args(); 369 | array_shift($args); 370 | 371 | if (isset($args[0]) and is_array($args[0])){ 372 | $args = $args[0]; 373 | } 374 | 375 | $result = $this->run_query($sql,$args); 376 | 377 | if ($result){ 378 | $row = mysqli_affected_rows(); 379 | return $row; 380 | } 381 | } 382 | 383 | private function string_sanitize($match,$init=FALSE){ 384 | static $args = NULL; 385 | if ($init){ 386 | $args = $match; 387 | return; 388 | } 389 | 390 | switch ($match[1]){ 391 | case '%d': 392 | return (int) array_shift($args); // We don't need db_escape_string as numbers are db-safe 393 | case '%s': 394 | return mysqli_real_escape_string($this->conn,array_shift($args)); 395 | case '%%': 396 | return '%'; 397 | case '%f': 398 | return (float) array_shift($args); 399 | case '%b': // binary data 400 | return mysqli_real_escape_string($this->conn,array_shift($args)); 401 | } 402 | } 403 | } 404 | ?> 405 | -------------------------------------------------------------------------------- /Drupal2Wordpress.php: -------------------------------------------------------------------------------- 1 | $DB_HOSTNAME,"username" => $DB_DP_USERNAME,"password" => $DB_DP_PASSWORD,"database" => $DB_DRUPAL); 24 | $wordpress_connection = array("host" => $DB_HOSTNAME,"username" => $DB_WP_USERNAME,"password" => $DB_WP_PASSWORD,"database" => $DB_WORDPRESS); 25 | 26 | //Create Connection for Drupal and Wordpress 27 | $dc = new DB($drupal_connection); 28 | $wc = new DB($wordpress_connection); 29 | 30 | //Check if database connection is fine 31 | $dcheck = $dc->check(); 32 | if (!$dcheck){ 33 | echo "This $DB_DRUPAL service is UNAVAILABLE"; die(); 34 | } 35 | 36 | $wcheck = $wc->check(); 37 | if (!$wcheck){ 38 | echo "This $DB_WORDPRESS service is UNAVAILABLE"; die(); 39 | } 40 | 41 | message('Database Connection successful'); 42 | 43 | //Empty the current worpdress Tables 44 | $wc->query("TRUNCATE TABLE ".$DB_WORDPRESS_PREFIX."comments"); 45 | $wc->query("TRUNCATE TABLE ".$DB_WORDPRESS_PREFIX."links"); 46 | $wc->query("TRUNCATE TABLE ".$DB_WORDPRESS_PREFIX."postmeta"); 47 | $wc->query("TRUNCATE TABLE ".$DB_WORDPRESS_PREFIX."posts"); 48 | $wc->query("TRUNCATE TABLE ".$DB_WORDPRESS_PREFIX."term_relationships"); 49 | $wc->query("TRUNCATE TABLE ".$DB_WORDPRESS_PREFIX."term_taxonomy"); 50 | $wc->query("TRUNCATE TABLE ".$DB_WORDPRESS_PREFIX."terms"); 51 | message('Wordpress Table Truncated'); 52 | 53 | //Get all drupal Tags and add it into worpdress terms table 54 | $drupal_tags = $dc->results("SELECT DISTINCT d.tid, d.name, REPLACE(LOWER(d.name), ' ', '_') AS slug FROM ".$DB_DRUPAL_PREFIX."taxonomy_term_data d INNER JOIN ".$DB_DRUPAL_PREFIX."taxonomy_term_hierarchy h ON (d.tid = h.tid) ORDER BY d.tid ASC"); 55 | foreach($drupal_tags as $dt) 56 | { 57 | $wc->query("REPLACE INTO ".$DB_WORDPRESS_PREFIX."terms (term_id, name, slug) VALUES ('%s','%s','%s')", $dt['tid'], $dt['name'], $dt['slug']); 58 | } 59 | 60 | //Update worpdress term_taxonomy table 61 | $drupal_taxonomy = $dc->results("SELECT DISTINCT d.tid AS term_id, 'post_tag' AS post_tag, d.description AS description, h.parent AS parent FROM ".$DB_DRUPAL_PREFIX."taxonomy_term_data d INNER JOIN ".$DB_DRUPAL_PREFIX."taxonomy_term_hierarchy h ON (d.tid = h.tid) ORDER BY 'term_id' ASC"); 62 | foreach($drupal_taxonomy as $dt) 63 | { 64 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."term_taxonomy (term_id, taxonomy, description, parent) VALUES ('%s','%s','%s','%s')", $dt['term_id'], $dt['post_tag'], $dt['description'], $dt['parent']); 65 | } 66 | 67 | message('Tags Updated'); 68 | 69 | // Update worpdress category for a new Blog entry (as catgegory) which 70 | // is a must for a post to be displayed well 71 | // Insert a fake new category named Blog 72 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."terms (name, slug) VALUES ('%s','%s')", 'Blog', 'blog'); 73 | 74 | // Then query to get this entry so we can attach it to content we create 75 | $blog_term_id = 0; 76 | $row = $wc->row("SELECT term_id FROM ".$DB_WORDPRESS_PREFIX."terms WHERE name = '%s' AND slug = '%s'", 'Blog', 'blog'); 77 | if (!empty($row['term_id'])) { 78 | $blog_term_id = $row['term_id']; 79 | 80 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."term_taxonomy (term_id, taxonomy) VALUES ('%d','%s')", $blog_term_id, 'category'); 81 | 82 | } 83 | 84 | message('Category Updated'); 85 | 86 | 87 | //Get all post from Drupal and add it into wordpress posts table 88 | $drupal_posts = $dc->results("SELECT DISTINCT n.nid AS id, n.uid AS post_author, FROM_UNIXTIME(n.created) AS post_date, r.body_value AS post_content, n.title AS post_title, r.body_summary AS post_excerpt, n.type AS post_type, IF(n.status = 1, 'publish', 'draft') AS post_status FROM ".$DB_DRUPAL_PREFIX."node n, ".$DB_DRUPAL_PREFIX."field_data_body r WHERE (n.nid = r.entity_id)"); 89 | $post_type = 'page'; 90 | foreach($drupal_posts as $dp) 91 | { 92 | 93 | // Wordpress basicially has 2 core post_type options, similar to Drupal - 94 | // either a blog-style content, where in Drupal is referred to as 'article' 95 | // and in Wordpress this is 'post', and the page-style content which is 96 | // referred to as 'page' content type in both platforms. 97 | 98 | // For the sake of supporting out of the box seamless migration we will 99 | // assume that any Drupal 'article' content type should be a Wordpress 100 | // 'post' type and anything else will be set to 'page' 101 | 102 | if ($dp['post_type'] === 'article') 103 | $post_type = 'post'; 104 | else 105 | $post_type = 'page'; 106 | 107 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."posts (id, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_type, post_status) VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')", $dp['id'], $dp['post_author'], $dp['post_date'], $dp['post_date'], $dp['post_content'], $dp['post_title'], $dp['post_excerpt'], $post_type, $dp['post_status']); 108 | 109 | // Attach all posts to the Blog category we created earlier 110 | if ($blog_term_id !== 0) { 111 | // Attach all posts the terms/tags 112 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."term_relationships (object_id, term_taxonomy_id) VALUES ('%s','%s')", $dp['id'], $blog_term_id); 113 | } 114 | 115 | } 116 | message('Posts Updated'); 117 | 118 | //Add relationship for post and tags 119 | $drupal_post_tags = $dc->results("SELECT DISTINCT node.nid, taxonomy_term_data.tid FROM (".$DB_DRUPAL_PREFIX."taxonomy_index taxonomy_index INNER JOIN ".$DB_DRUPAL_PREFIX."taxonomy_term_data taxonomy_term_data ON (taxonomy_index.tid = taxonomy_term_data.tid)) INNER JOIN ".$DB_DRUPAL_PREFIX."node node ON (node.nid = taxonomy_index.nid)"); 120 | foreach($drupal_post_tags as $dpt) 121 | { 122 | $wordpress_term_tax = $wc->row("SELECT DISTINCT term_taxonomy.term_taxonomy_id FROM ".$DB_WORDPRESS_PREFIX."term_taxonomy term_taxonomy WHERE (term_taxonomy.term_id = ".$dpt['tid'].")"); 123 | 124 | // Attach all posts the terms/tags 125 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."term_relationships (object_id, term_taxonomy_id) VALUES ('%s','%s')", $dpt['nid'], $wordpress_term_tax['term_taxonomy_id']); 126 | } 127 | 128 | message('Tags & Posts Relationships Updated'); 129 | 130 | //Update the post type for worpdress 131 | $wc->query("UPDATE ".$DB_WORDPRESS_PREFIX."posts SET post_type = 'post' WHERE post_type IN ('blog')"); 132 | message('Posted Type Updated'); 133 | 134 | //Count the total tags 135 | $wc->query("UPDATE ".$DB_WORDPRESS_PREFIX."term_taxonomy tt SET count = ( SELECT COUNT(tr.object_id) FROM ".$DB_WORDPRESS_PREFIX."term_relationships tr WHERE tr.term_taxonomy_id = tt.term_taxonomy_id )"); 136 | message('Tags Count Updated'); 137 | 138 | //Get the url alias from drupal and use it for the Post Slug 139 | $drupal_url = $dc->results("SELECT url_alias.source, url_alias.alias FROM ".$DB_DRUPAL_PREFIX."url_alias url_alias WHERE (url_alias.source LIKE 'node%')"); 140 | foreach($drupal_url as $du) 141 | { 142 | $update = $wc->query("UPDATE ".$DB_WORDPRESS_PREFIX."posts SET post_name = '%s' WHERE ID = '%s'", 143 | // Make sure we import without Drupal's leading 'content/' in the URL 144 | str_replace('content/', '', $du['alias']), 145 | str_replace('node/','',$du['source']) 146 | ); 147 | } 148 | message('URL Alias to Slug Updated'); 149 | 150 | // Move the comments and their replies - 11 Levels 151 | // Ensure we import only approved comments (c.status = 1) as otherwise we might be importing a ton of spam from a Drupal site 152 | $drupal_comments = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = 0) AND c.status = 1"); 153 | foreach($drupal_comments as $duc) 154 | { 155 | $insert = $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$duc['comment_ID'],$duc['comment_post_ID'],$duc['comment_author'],$duc['comment_author_email'],$duc['comment_author_url'],$duc['comment_author_IP'],$duc['comment_date'],$duc['comment_date'],$duc['comment_content'],'1','0'); 156 | 157 | $drupal_comments_level1 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$duc['comment_ID'].") AND c.status = 1"); 158 | 159 | foreach($drupal_comments_level1 as $dcl1) 160 | { 161 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl1['comment_ID'],$dcl1['comment_post_ID'],$dcl1['comment_author'],$dcl1['comment_author_email'],$dcl1['comment_author_url'],$dcl1['comment_author_IP'],$dcl1['comment_date'],$dcl1['comment_date'],$dcl1['comment_content'],'1',$duc['comment_ID']); 162 | 163 | $drupal_comments_level2 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl1['comment_ID'].") AND c.status = 1"); 164 | 165 | foreach ($drupal_comments_level2 as $dcl2) 166 | { 167 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl2['comment_ID'],$dcl2['comment_post_ID'],$dcl2['comment_author'],$dcl2['comment_author_email'],$dcl2['comment_author_url'],$dcl2['comment_author_IP'],$dcl2['comment_date'],$dcl2['comment_date'],$dcl2['comment_content'],'1',$dcl1['comment_ID']); 168 | 169 | 170 | $drupal_comments_level3 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl2['comment_ID'].") AND c.status = 1"); 171 | 172 | foreach ($drupal_comments_level3 as $dcl3) 173 | { 174 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl3['comment_ID'],$dcl3['comment_post_ID'],$dcl3['comment_author'],$dcl3['comment_author_email'],$dcl3['comment_author_url'],$dcl3['comment_author_IP'],$dcl3['comment_date'],$dcl3['comment_date'],$dcl3['comment_content'],'1',$dcl2['comment_ID']); 175 | 176 | 177 | $drupal_comments_level4 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl3['comment_ID'].") AND c.status = 1"); 178 | 179 | 180 | foreach ($drupal_comments_level4 as $dcl4) 181 | { 182 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl4['comment_ID'],$dcl4['comment_post_ID'],$dcl4['comment_author'],$dcl4['comment_author_email'],$dcl4['comment_author_url'],$dcl4['comment_author_IP'],$dcl4['comment_date'],$dcl4['comment_date'],$dcl4['comment_content'],'1',$dcl3['comment_ID']); 183 | 184 | 185 | $drupal_comments_level5 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl4['comment_ID'].") AND c.status = 1"); 186 | 187 | 188 | foreach ($drupal_comments_level5 as $dcl5) 189 | { 190 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl5['comment_ID'],$dcl5['comment_post_ID'],$dcl5['comment_author'],$dcl5['comment_author_email'],$dcl5['comment_author_url'],$dcl5['comment_author_IP'],$dcl5['comment_date'],$dcl5['comment_date'],$dcl5['comment_content'],'1',$dcl4['comment_ID']); 191 | 192 | 193 | $drupal_comments_level6 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl5['comment_ID'].") AND c.status = 1"); 194 | 195 | 196 | foreach ($drupal_comments_level6 as $dcl6) 197 | { 198 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl6['comment_ID'],$dcl6['comment_post_ID'],$dcl6['comment_author'],$dcl6['comment_author_email'],$dcl6['comment_author_url'],$dcl6['comment_author_IP'],$dcl6['comment_date'],$dcl6['comment_date'],$dcl6['comment_content'],'1',$dcl5['comment_ID']); 199 | 200 | 201 | $drupal_comments_level7 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl6['comment_ID'].") AND c.status = 1"); 202 | 203 | 204 | foreach ($drupal_comments_level7 as $dcl7) 205 | { 206 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl7['comment_ID'],$dcl7['comment_post_ID'],$dcl7['comment_author'],$dcl7['comment_author_email'],$dcl7['comment_author_url'],$dcl7['comment_author_IP'],$dcl7['comment_date'],$dcl7['comment_date'],$dcl7['comment_content'],'1',$dcl6['comment_ID']); 207 | 208 | 209 | $drupal_comments_level8 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl7['comment_ID'].") AND c.status = 1"); 210 | 211 | foreach ($drupal_comments_level8 as $dcl8) 212 | { 213 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl8['comment_ID'],$dcl8['comment_post_ID'],$dcl8['comment_author'],$dcl8['comment_author_email'],$dcl8['comment_author_url'],$dcl8['comment_author_IP'],$dcl8['comment_date'],$dcl8['comment_date'],$dcl8['comment_content'],'1',$dcl7['comment_ID']); 214 | 215 | 216 | $drupal_comments_level9 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl8['comment_ID'].") AND c.status = 1"); 217 | 218 | foreach ($drupal_comments_level9 as $dcl9) 219 | { 220 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl9['comment_ID'],$dcl9['comment_post_ID'],$dcl9['comment_author'],$dcl9['comment_author_email'],$dcl9['comment_author_url'],$dcl9['comment_author_IP'],$dcl9['comment_date'],$dcl9['comment_date'],$dcl9['comment_content'],'1',$dcl8['comment_ID']); 221 | 222 | 223 | 224 | $drupal_comments_level10 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl9['comment_ID'].") AND c.status = 1"); 225 | 226 | 227 | foreach ($drupal_comments_level10 as $dcl10) 228 | { 229 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl10['comment_ID'],$dcl10['comment_post_ID'],$dcl10['comment_author'],$dcl10['comment_author_email'],$dcl10['comment_author_url'],$dcl10['comment_author_IP'],$dcl10['comment_date'],$dcl10['comment_date'],$dcl10['comment_content'],'1',$dcl9['comment_ID']); 230 | 231 | echo $dcl10['comment_ID'] . '
'; 232 | 233 | 234 | $drupal_comments_level11 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl10['comment_ID'].") AND c.status = 1"); 235 | 236 | 237 | 238 | foreach ($drupal_comments_level11 as $dcl11) 239 | { 240 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl11['comment_ID'],$dcl11['comment_post_ID'],$dcl11['comment_author'],$dcl11['comment_author_email'],$dcl11['comment_author_url'],$dcl11['comment_author_IP'],$dcl11['comment_date'],$dcl11['comment_date'],$dcl11['comment_content'],'1',$dcl10['comment_ID']); 241 | 242 | 243 | 244 | 245 | $drupal_comments_level12 = $dc->results("SELECT DISTINCT c.cid AS comment_ID, c.nid AS comment_post_ID, c.name AS comment_author, c.mail AS comment_author_email, c.homepage AS comment_author_url, c.hostname AS comment_author_IP, FROM_UNIXTIME(c.created) AS comment_date, field_data_comment_body.comment_body_value AS comment_content FROM ".$DB_DRUPAL_PREFIX."comment c INNER JOIN ".$DB_DRUPAL_PREFIX."field_data_comment_body field_data_comment_body ON (c.cid = field_data_comment_body.entity_id) WHERE (c.pid = ".$dcl11['comment_ID'].") AND c.status = 1"); 246 | 247 | 248 | foreach ($drupal_comments_level12 as $dcl12) 249 | { 250 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."comments (comment_ID,comment_post_ID ,comment_author ,comment_author_email ,comment_author_url ,comment_author_IP ,comment_date ,comment_date_gmt, comment_content ,comment_approved,comment_parent)VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$dcl12['comment_ID'],$dcl12['comment_post_ID'],$dcl12['comment_author'],$dcl12['comment_author_email'],$dcl12['comment_author_url'],$dcl12['comment_author_IP'],$dcl12['comment_date'],$dcl12['comment_date'],$dcl12['comment_content'],'1',$dcl11['comment_ID']); 251 | 252 | 253 | echo '
' . $dcl12['comment_ID'] . '
'; 254 | 255 | 256 | 257 | } 258 | 259 | } 260 | 261 | 262 | 263 | } 264 | } 265 | } 266 | } 267 | } 268 | } 269 | } 270 | } 271 | } 272 | } 273 | } 274 | message('Comments Updated - 11 Level'); 275 | 276 | //Update Comment Counts in Wordpress 277 | $wc->query("UPDATE ".$DB_WORDPRESS_PREFIX."posts SET comment_count = ( SELECT COUNT(comment_post_id) FROM ".$DB_WORDPRESS_PREFIX."comments WHERE ".$DB_WORDPRESS_PREFIX."posts.id = ".$DB_WORDPRESS_PREFIX."comments.comment_post_id )"); 278 | 279 | 280 | // Update wordpress users 281 | // From Drupal we're getting the essential user details, including their 282 | // user id so we can maintain the same posts ownership when we migrate 283 | // content over to Wordpress. 284 | // 285 | // * Special edge-case: we're skipping the administrative user migration 286 | // * Special edge-case: passwords are intentionally left blank as this 287 | // forces user expiration in Wordpress 288 | $drupal_users = $dc->results("SELECT u.uid, u.name, u.mail, FROM_UNIXTIME(u.created) AS created, u.access FROM ".$DB_DRUPAL_PREFIX."users u WHERE u.uid != 1 AND u.uid != 0"); 289 | foreach($drupal_users as $du) 290 | { 291 | $wc->query("INSERT INTO ".$DB_WORDPRESS_PREFIX."users 292 | (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_registered`, `display_name`) 293 | VALUES 294 | ('%s','%s','%s','%s','%s','%s','%s')", $du['uid'], $du['name'], '', $du['name'], $du['mail'], $du['created'], $du['name']); 295 | } 296 | 297 | message('Users Updated'); 298 | 299 | message('Cheers !!'); 300 | 301 | /* 302 | TO DO - Skipped coz didnt have much comment and Users, if you need then share you database and shall work upon and fix it for you. 303 | 304 | 1.) Update Users/Authors 305 | */ 306 | 307 | //Preformat the Object for Debuggin Purpose 308 | function po($obj){ 309 | echo "
";
310 | 		print_r($obj);
311 | 		echo "
"; 312 | } 313 | 314 | function message($msg){ 315 | echo "
$msg"; 316 | func_flush(); 317 | } 318 | 319 | function func_flush($s = NULL) 320 | { 321 | if (!is_null($s)) 322 | echo $s; 323 | 324 | if (preg_match("/Apache(.*)Win/S", getenv('SERVER_SOFTWARE'))) 325 | echo str_repeat(" ", 2500); 326 | elseif (preg_match("/(.*)MSIE(.*)\)$/S", getenv('HTTP_USER_AGENT'))) 327 | echo str_repeat(" ", 256); 328 | 329 | if (function_exists('ob_flush')) 330 | { 331 | // for PHP >= 4.2.0 332 | @ob_flush(); 333 | } 334 | else 335 | { 336 | // for PHP < 4.2.0 337 | if (ob_get_length() !== FALSE) 338 | ob_end_flush(); 339 | } 340 | flush(); 341 | } 342 | --------------------------------------------------------------------------------