/[drupal]/contributions/modules/drigg/drigg_pligg_import/drigg_pligg_import.module
ViewVC logotype

Diff of /contributions/modules/drigg/drigg_pligg_import/drigg_pligg_import.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.2.2.2, Fri Nov 7 03:32:56 2008 UTC revision 1.1.2.2.2.3, Mon Jun 22 18:35:13 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  // $Id: drigg_pligg_import.module,v 1.1.2.2.2.1 2008/11/07 01:00:11 mercmobily Exp $  // $Id: drigg_pligg_import.module,v 1.1.2.2.2.2 2008/11/07 03:32:56 mercmobily Exp $
4    
5  /**  /**
6  * @file  * @file
7  */  */
8    
9    function drigg_log_msg($msg) {
10    
11      // Change this to TRUE to get logging happening
12      $logging_is_enabled = false;
13    
14      // Where things will get logged
15      $log_file           = '/tmp/drigg_pligg_import.log';
16    
17      if( !$logging_is_enabled ){
18        return;
19      }
20    
21      $formatted_msg = $msg . "\n";
22    
23      try {
24        $file = @fopen($log_file, 'a');
25        if( $file == false ) {
26          throw new Exception("ERROR: Failed to open log file [" . $log_file . "]");
27        }
28    
29        if( fwrite($file, $formatted_msg) == false ) {
30          throw new Exception("ERROR: Failed to write to log file [" . $log_file . "]");
31        }
32    
33        if( fclose($file) == false ){
34          throw new Exception("ERROR: Failed to close log file [" . $log_file . "]");
35        }
36      }
37      catch( Exception $exception ){
38        /* Nothing's done about this. */
39      }
40    }
41    
42  /**  /**
43   * Implementation of hook_help().   * Implementation of hook_help().
44   */   */
# Line 20  function drigg_pligg_import_help($path, Line 53  function drigg_pligg_import_help($path,
53  /**  /**
54   * Implementation of hook_menu().   * Implementation of hook_menu().
55   *   *
  * This is again "the usual story". However, note that this "menu" is  
  * quite tricky, because it needs to pass the right arguments to  
  * drigg_pligg_import_node_list(). The function is commented throughout  
56   */   */
57  function drigg_pligg_import_menu() {  function drigg_pligg_import_menu() {
58    $items = array();    $items = array();
59    
60    // THe importer  
61      // The importer
62    $items['admin/settings/drigg/pligg_importer'] = array(    $items['admin/settings/drigg/pligg_importer'] = array(
63      'title' => 'Pligg importer',      'title' => 'Pligg importer',
64      'description' => 'Pligg importer for drigg',      'description' => 'Pligg importer for drigg. Change $logging_is_enabled to TRUE to enable logging into /tmp/drigg_pligg_import.log',
65      'page callback' => 'drigg_pligg_import_pligg_importer',      'page callback' => 'drigg_pligg_import_pligg_importer',
66      'access callback' => 'user_access',      'access callback' => 'user_access',
67      'access arguments' => array('administer site configuration'),      'access arguments' => array('administer site configuration'),
# Line 267  function drigg_pligg_import_pligg_import Line 298  function drigg_pligg_import_pligg_import
298    
299    if (module_exists('profile')) {    if (module_exists('profile')) {
300      db_query('DELETE FROM {profile_fields}');      db_query('DELETE FROM {profile_fields}');
301        drigg_log_msg('Emptied the Drigg profile_fields table');
302      db_query('DELETE FROM {profile_values}');      db_query('DELETE FROM {profile_values}');
303        drigg_log_msg('Emptied the Drigg profile_values table');
304    
305      db_query("INSERT INTO {profile_fields} VALUES (1,'Occupation','profile_occupation','Your occupation','User information','','textfield',0,0,1,3,0,'')");      db_query("INSERT INTO {profile_fields} VALUES (1,'Occupation','profile_occupation','Your occupation','User information','','textfield',0,0,1,3,0,'')");
306      db_query("INSERT INTO {profile_fields} VALUES (2,'Home page','profile_home_page','Your home page','User information','','textfield',0,0,1,3,0,'') ");      db_query("INSERT INTO {profile_fields} VALUES (2,'Home page','profile_home_page','Your home page','User information','','textfield',0,0,1,3,0,'') ");
# Line 280  function drigg_pligg_import_pligg_import Line 313  function drigg_pligg_import_pligg_import
313      db_query("INSERT INTO {profile_fields} VALUES (9,'Skype user name','profile_skype_user_name','Your Skype user name','Contact information','','textfield',0,0,1,3,0,'') ");      db_query("INSERT INTO {profile_fields} VALUES (9,'Skype user name','profile_skype_user_name','Your Skype user name','Contact information','','textfield',0,0,1,3,0,'') ");
314    }    }
315    
316      drigg_log_msg("Importing Pligg users...");
317    $query = sprintf("SELECT *,UNIX_TIMESTAMP(user_lastlogin) as user_lastlogin_t , UNIX_TIMESTAMP(user_date) as user_date_t FROM pligg_users where user_id != 1");    $query = sprintf("SELECT *,UNIX_TIMESTAMP(user_lastlogin) as user_lastlogin_t , UNIX_TIMESTAMP(user_date) as user_date_t FROM pligg_users where user_id != 1");
318    $result = mysql_query($query, $drigg_pligg_import_link);    $result = mysql_query($query, $drigg_pligg_import_link);
319    while ($r = mysql_fetch_assoc($result)) {    while ($r = mysql_fetch_assoc($result)) {
320    
321      $drupal_pic_path = '';      $drupal_pic_path = '';
322      if ($r['user_avatar_source'] == 'useruploaded' && $copy_pictures) {      if ($r['user_avatar_source'] == 'useruploaded' && $copy_pictures) {
323          drigg_log_msg("\tCopying avatar for Pligg user_id [" . $r['user_id'] . "]");
324        $from = $form_state['values']['avatar_path'] .'/'. $r['user_login'] .'_'. $form_state['values']['avatar_res'] .'.jpg';        $from = $form_state['values']['avatar_path'] .'/'. $r['user_login'] .'_'. $form_state['values']['avatar_res'] .'.jpg';
325        $to = "$drupal_img_path/picture-". $r['user_id'] .'.jpg';        $to = "$drupal_img_path/picture-". $r['user_id'] .'.jpg';
326        #drupal_set_message($from);        #drupal_set_message($from);
# Line 294  function drigg_pligg_import_pligg_import Line 329  function drigg_pligg_import_pligg_import
329        $drupal_pic_path = $to;        $drupal_pic_path = $to;
330      }      }
331      db_query("INSERT INTO {users} VALUES (%d, '%s', '%s', '%s', 0, 0, 0, '', '', %d, %d, %d, 1, NULL, '', '%s', '%s', NULL ) ", $r['user_id'], $r['user_login'], $r['user_pass'], $r['user_email'], $r['user_date_t'], $r['user_lastlogin_t'], $r['user_date_t'], $drupal_pic_path, $r['user_email']);      db_query("INSERT INTO {users} VALUES (%d, '%s', '%s', '%s', 0, 0, 0, '', '', %d, %d, %d, 1, NULL, '', '%s', '%s', NULL ) ", $r['user_id'], $r['user_login'], $r['user_pass'], $r['user_email'], $r['user_date_t'], $r['user_lastlogin_t'], $r['user_date_t'], $drupal_pic_path, $r['user_email']);
332        drigg_log_msg("\tCreated Pligg user_id [" . $r['user_id'] . "] in Drigg");
333    
334    
335      #drupal_set_message("Here: ". $r['user_date_t']);      #drupal_set_message("Here: ". $r['user_date_t']);
# Line 307  function drigg_pligg_import_pligg_import Line 343  function drigg_pligg_import_pligg_import
343        db_query("INSERT INTO {profile_values} VALUES (%d,%d,'%s') ", 7, $r['user_id'], $r['user_yahoo']);        db_query("INSERT INTO {profile_values} VALUES (%d,%d,'%s') ", 7, $r['user_id'], $r['user_yahoo']);
344        db_query("INSERT INTO {profile_values} VALUES (%d,%d,'%s') ", 8, $r['user_id'], $r['user_gtalk']);        db_query("INSERT INTO {profile_values} VALUES (%d,%d,'%s') ", 8, $r['user_id'], $r['user_gtalk']);
345        db_query("INSERT INTO {profile_values} VALUES (%d,%d,'%s') ", 9, $r['user_id'], $r['user_skype']);        db_query("INSERT INTO {profile_values} VALUES (%d,%d,'%s') ", 9, $r['user_id'], $r['user_skype']);
346          drigg_log_msg("\tAdded Pligg profile details to Drigg for user_id [" . $r['user_id'] . "]");
347      }      }
348    }    }
349      drigg_log_msg("\tFinished importing Pligg users");
350    
351    $max_uid = db_result(db_query("SELECT max(uid) FROM {users}"));    $max_uid = db_result(db_query("SELECT max(uid) FROM {users}"));
352    $max_uid ++;    $max_uid ++;
353    db_query("ALTER TABLE {users} AUTO_INCREMENT = %d", $max_uid);    db_query("ALTER TABLE {users} AUTO_INCREMENT = %d", $max_uid);
354      drigg_log_msg("Corrected the AUTO_INCREMENT setting for the Drigg users table");
355    
356    
357    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
358    //          *** IMPORT THE TERMS ***    //          *** IMPORT THE TERMS ***
359    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
360    
   
361    $vid = variable_get('drigg_section_vid', '');    $vid = variable_get('drigg_section_vid', '');
362    db_query('DELETE FROM {term_data}');    db_query('DELETE FROM {term_data}');
363      drigg_log_msg("Emptied the Drigg term_data table");
364    db_query('DELETE FROM {term_hierarchy}');    db_query('DELETE FROM {term_hierarchy}');
365      drigg_log_msg("Emptied the Drigg term_hierarchy table");
366    
367      drigg_log_msg('Importing Pligg categories...');
368    $query = sprintf("SELECT * FROM pligg_categories where category_name <> 'All'");    $query = sprintf("SELECT * FROM pligg_categories where category_name <> 'All'");
369    $result = mysql_query($query, $drigg_pligg_import_link);    $result = mysql_query($query, $drigg_pligg_import_link);
370    while ($r = mysql_fetch_assoc($result)) {    while ($r = mysql_fetch_assoc($result)) {
371      db_query("INSERT INTO {term_data} VALUES (%d, %d, '%s', '%s', %d) ", $r['category__auto_id'], $vid, $r['category_name'], $r['category_name'], $r['category_order']);      db_query("INSERT INTO {term_data} VALUES (%d, %d, '%s', '%s', %d) ", $r['category__auto_id'], $vid, $r['category_name'], '', $r['category_order']);
372      db_query("INSERT INTO {term_hierarchy} VALUES (%d, 0)", $r['category__auto_id']);      db_query("INSERT INTO {term_hierarchy} VALUES (%d, 0)", $r['category__auto_id']);
373        drigg_log_msg("\tAdded category [" . $r['category_name'] . "] to Drigg");
374    }    }
375    
376    // Reset the auto_increment so that it doesn't go bananas    // Reset the auto_increment so that it doesn't go bananas
377    $max = db_result(db_query("SELECT max(tid) FROM {term_data}"));    $max = db_result(db_query("SELECT max(tid) FROM {term_data}")) + 1;
   $max ++;  
378    db_query("ALTER TABLE {term_data} AUTO_INCREMENT = %d", $max);    db_query("ALTER TABLE {term_data} AUTO_INCREMENT = %d", $max);
379      drigg_log_msg("Corrected the AUTO_INCREMENT setting for the Drigg term_data table");
380    
381    // This is important: the sections have changed!    // This is important: the sections have changed!
382    variable_set("drigg_list", drigg_section_list());    variable_set("drigg_list", drigg_section_list());
383    
384    
385    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
386    //          *** IMPORT THE NODES ***    //          *** IMPORT THE NODES ***
387    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
388    
   
389    db_query("DELETE FROM {node}");    db_query("DELETE FROM {node}");
390      drigg_log_msg("Emptied the Drigg node table");
391    db_query("DELETE FROM {term_node}");    db_query("DELETE FROM {term_node}");
392      drigg_log_msg("Emptied the Drigg term_node table");
393    db_query("DELETE FROM {node_revisions}");    db_query("DELETE FROM {node_revisions}");
394      drigg_log_msg("Emptied the Drigg node_revisions table");
395    db_query("DELETE FROM {drigg_node}");    db_query("DELETE FROM {drigg_node}");
396      drigg_log_msg("Emptied the Drigg drigg_node table");
397    
398      drigg_log_msg('Importing queued and published Pligg scoops...');
399    $tl = drigg_section_list();    $tl = drigg_section_list();
400    $query = sprintf("SELECT *,UNIX_TIMESTAMP(link_published_date) as link_published_date_t, UNIX_TIMESTAMP(link_date) as link_date_t, UNIX_TIMESTAMP(link_modified) as link_modified_t FROM pligg_links where (link_status = 'queued' OR link_status = 'published' )");    $query = sprintf("SELECT *,UNIX_TIMESTAMP(link_published_date) as link_published_date_t, UNIX_TIMESTAMP(link_date) as link_date_t, UNIX_TIMESTAMP(link_modified) as link_modified_t FROM pligg_links where (link_status = 'queued' OR link_status = 'published' )");
401    $result = mysql_query($query, $drigg_pligg_import_link);    $result = mysql_query($query, $drigg_pligg_import_link);
# Line 381  function drigg_pligg_import_pligg_import Line 429  function drigg_pligg_import_pligg_import
429    
430      $d_teaser = node_teaser($d_body);      $d_teaser = node_teaser($d_body);
431    
432      db_query("INSERT INTO {node_revisions}(nid, uid, title, body, teaser, log, timestamp, format) VALUES (%d, %d, '%s', '%s', '%s', '', 0, 1) ", $d_nid, $d_uid, $d_title, $d_body, $d_teaser);      db_query("INSERT INTO {node_revisions}
433          (nid,   uid,    title,    body,     teaser,     log,  timestamp,  format) VALUES
434          (%d,    %d,     '%s',     '%s',     '%s',       '',   0,          1) ",
435          $d_nid, $d_uid, $d_title, $d_body,  $d_teaser);
436    
437      $d_vid = db_last_insert_id('node_revisions', 'vid');      $d_vid = db_last_insert_id('node_revisions', 'vid');
438    
439      db_query("INSERT INTO {node} VALUES (%d, %d, '%s', '%s', %d, %d, %d, %d, %d, %d, %d, %d) ", $d_nid, $d_vid, 'drigg', $d_title, $d_uid, 1, $d_created, $d_changed, $d_comment, $d_promote, 0, 0);      db_query("INSERT INTO {node} VALUES (
440          %d,       %d,       '%s',     '%s',       '%s',       %d,       %d,       %d,           %d,           %d,           %d,           %d,         %d,       %d,     %d)",
441          $d_nid,   $d_vid,   'drigg',  '',         $d_title,   $d_uid,   1,        $d_created,   $d_changed,   $d_comment,   $d_promote,   0,          0,        0,      0);
442    #     nid,      vid,      type,     language,   title,      uid,      status,   created,      changed,      comment,      promote,      moderate,   sticky,   tnid,   translate
443    
444        drigg_log_msg("\tCreated Pligg scoop: [nid = $d_nid] $d_title");
445    
446      $safe_section = $tl['lookup'][$c_category]['safe_name']; // IMPORTANT!      $safe_section = $tl['lookup'][$c_category]['safe_name']; // IMPORTANT!
447    
448      // This is because Pligg has a "1" in the URL for "Editorial" pieces.      # Pligg sets the URL to "1" if the scoop is an editorial, and to "http://" if URLs aren't required.
449      // THis means that broken links will be created!      # If either of these occurs, the Drigg node's URL needs to be corrected.
450      if ($d_url === '1') {      if (($d_url == '1') or ($d_url == 'http://'))
451        $d_url = rand(0, 2000);        {$d_url = "node/$d_nid";}
452      }  
453      db_query("INSERT INTO {drigg_node} VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', '%s', %d) ", $d_nid, $d_promoted_on, $d_killed, $d_url, $d_title_url, $safe_section, '', '', 0);      db_query("INSERT INTO {drigg_node} VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', '%s', %d) ", $d_nid, $d_promoted_on, $d_killed, $d_url, $d_title_url, $safe_section, '', '', 0);
454      db_query("INSERT INTO {term_node} VALUES (%d, %d, %d) ", $d_nid, $d_vid, $c_category);      db_query("INSERT INTO {term_node} VALUES (%d, %d, %d) ", $d_nid, $d_vid, $c_category);
455    }    }
456      drigg_log_msg("\tFinished importing Pligg scoops");
457    
458    // Clean up the nodes that went wrong    // Clean up the nodes that went wrong
459    db_query("DELETE FROM {node} WHERE nid NOT IN (SELECT dnid FROM {drigg_node} WHERE dnid = nid)");    db_query("DELETE FROM {node} WHERE nid NOT IN (SELECT dnid FROM {drigg_node} WHERE dnid = nid)");
460      drigg_log_msg('Cleaned up the "nodes that went wrong"');
461    
462    // Reset the auto_increment for node so that it doesn't go bananas    // Reset the auto_increment for node so that it doesn't go bananas
463    $max = db_result(db_query("SELECT max(nid) FROM {node}"));    $max = db_result(db_query("SELECT max(nid) FROM {node}")) + 1;
   $max ++;  
464    db_query("ALTER TABLE {node} AUTO_INCREMENT = %d", $max);    db_query("ALTER TABLE {node} AUTO_INCREMENT = %d", $max);
465      drigg_log_msg("Corrected the AUTO_INCREMENT setting for the Drigg node table");
466    
467    // Reset the auto_increment for node_revision so that it doesn't go bananas    // Reset the auto_increment for node_revision so that it doesn't go bananas
468    $max = db_result(db_query("SELECT max(nid) FROM {node_revisions}"));    $max = db_result(db_query("SELECT max(vid) FROM {node_revisions}")) + 1;
   $max ++;  
469    db_query("ALTER TABLE {node_revisions} AUTO_INCREMENT = %d", $max);    db_query("ALTER TABLE {node_revisions} AUTO_INCREMENT = %d", $max);
470      drigg_log_msg("Corrected the AUTO_INCREMENT setting for the Drigg node_revisions table");
471    
472    
473    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
474    //          *** IMPORT THE TAGS ***    //          *** IMPORT THE TAGS ***
475    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
476    
477      drigg_log_msg('Importing Pligg tags...');
478    
479    $query = sprintf("SELECT * FROM pligg_links where (link_status = 'queued' OR link_status = 'published' )");    $query = sprintf("SELECT * FROM pligg_links where (link_status = 'queued' OR link_status = 'published' )");
480    $result = mysql_query($query, $drigg_pligg_import_link);    $result = mysql_query($query, $drigg_pligg_import_link);
481    while ($r = mysql_fetch_assoc($result)) {    while ($r = mysql_fetch_assoc($result)) {
482        $all_tags = explode(',', $r['link_tags']);
483    
484      $tags_here = explode(',', $r['link_tags']);      foreach ($all_tags as $tag) {
   
   
     foreach ($tags_here as $tag) {  
485        $tag = trim($tag);        $tag = trim($tag);
486    
487        if ($tag <> '') {        if ($tag != '') {
488          $new_tid = db_result(db_query("SELECT * from {term_data} where name = '%s' and vid = %d", $tag,  variable_get('drigg_tag_vid', '')));          $tag_id = db_result(db_query("SELECT tid from {term_data} where name = '%s' and vid = %d", $tag,  variable_get('drigg_tag_vid', '')));
489          if (!$new_tid) {  
490            if (!$tag_id) {
491            db_query("INSERT INTO {term_data} VALUES (%d, '%s', '', 0) ", variable_get('drigg_tag_vid', ''), $tag);            db_query("INSERT INTO {term_data} VALUES (%d, %d, '%s', '', 0) ", $tag_id, variable_get('drigg_tag_vid', ''), $tag);
492                    $new_tid = db_last_insert_id('term_data', 'tid');                    $tag_id = db_last_insert_id('term_data', 'tid');
493            db_query("INSERT INTO {term_hierarchy} VALUES (%d, 0)", $new_tid);  
494              drigg_log_msg("\tAdding tag [$tag] with id [$tag_id] to Drigg");
495              db_query("INSERT INTO {term_hierarchy} VALUES (%d, 0)", $tag_id);
496          }          }
497    
498            $link_vid = db_result(db_query('SELECT vid FROM node WHERE nid = %d', $r['link_id']));
499    
500          db_query("INSERT INTO {term_node} VALUES (%d, %d, %d) ", $r['link_id'], $r['link_id'], $new_tid);          drigg_log_msg("\tAssociating Pligg link ID [" . $r['link_id'] . "] with tag ID [$tag_id]...");
501            db_query("INSERT INTO {term_node} VALUES (%d, %d, %d) ", $r['link_id'], $link_vid, $tag_id);
502        }        }
503      }      }
504      }
505      drigg_log_msg("\tFinished importing Pligg tags");
506    
507      // Reset the auto_increment for term_node so that it doesn't go bananas
508      $max = db_result(db_query("SELECT max(tid) FROM {term_data}")) + 1;
509      db_query("ALTER TABLE {term_data} AUTO_INCREMENT = %d", $max);
510      drigg_log_msg("Corrected the AUTO_INCREMENT setting for the Drigg term_data table");
511    
  }  
512    
513    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
514    //          *** IMPORT THE COMMENTS ***    //          *** IMPORT THE COMMENTS ***
515    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
516    
517    db_query("DELETE FROM {comments}");    db_query("DELETE FROM {comments}");
518      drigg_log_msg('Emptied the Drigg comments table');
519    
520      drigg_log_msg("Importing Pligg scoop comments...");
521    $query = sprintf("SELECT *,UNIX_TIMESTAMP(comment_date) as comment_date_t FROM pligg_comments");    $query = sprintf("SELECT *,UNIX_TIMESTAMP(comment_date) as comment_date_t FROM pligg_comments");
522    $result = mysql_query($query, $drigg_pligg_import_link);    $result = mysql_query($query, $drigg_pligg_import_link);
523    while ($r = mysql_fetch_assoc($result)) {    while ($r = mysql_fetch_assoc($result)) {
524    
525      # Pligg doesn't have "subjects" or "summaries" for scoops, but Drigg does. Thus, we need to use the beginning of a scoop's content as its subject.
526      # If the comment is too long to be used as a comment's subject, truncate the subject, and append "..." to imply that there's more content.
527      $subject = $r['comment_content'];
528      if (strlen($subject) > 35)
529        {$subject = substr($subject, 0, 32) . '...';}
530    
     // Trim the body. This could be done A MILLION times more elegantly,  
     // but I just can't be asked. This whole import will be obsolete very  
     // very soon anyway...  
     $b = $r['comment_content'];  
     #drupal_set_message("A: $b");  
     if ((strlen($b) > 35) && (strlen($b) > 1)) {  
       #drupal_set_message("MEH");  
       $w = strpos($b, " ", 30);  
       #drupal_set_message("W is $w");  
       if ($w < 45) {  
         $b = substr($b, 0, $w);  
       }  
       else {  
         $b = substr($b, 0, 35) .' [...]';  
       }  
     }  
   
     #drupal_set_message("B: $b");  
     #if ($ccc++ == 20) {  
     #  return;  
     #}  
   
   
531      db_query("INSERT INTO {comments} VALUES (      db_query("INSERT INTO {comments} VALUES (
532        %d, %d, %d, %d,        %d, %d, %d, %d,
533        '%s', '%s', '%s',        '%s', '%s', '%s',
# Line 481  function drigg_pligg_import_pligg_import Line 536  function drigg_pligg_import_pligg_import
536        '%s', '%s', '%s', '%s') ",        '%s', '%s', '%s', '%s') ",
537    
538        $r['comment_id'], $r['comment_parent'], $r['comment_link_id'], $r['comment_user_id'],        $r['comment_id'], $r['comment_parent'], $r['comment_link_id'], $r['comment_user_id'],
539        $b, $r['comment_content'], '',        $subject, $r['comment_content'], '',
540        $r['comment_date_t'],        $r['comment_date_t'],
541        0, 1,        0, 1,
542        '', NULL, NULL, NULL);        '', NULL, NULL, NULL);
543    }      drigg_log_msg("\tCreated Pligg comment in Drigg: [comment_id = " . $r['comment_id'] . "] " . $subject);
544      }
545      drigg_log_msg("\tFinished importing Pligg comments");
546    
547    // Clean up after pligg    // Clean up after pligg
548    db_query("DELETE FROM {comments} WHERE {comments}.nid NOT in (SELECT nid FROM {node} n WHERE n.nid = {comments}.nid)");    db_query("DELETE FROM {comments} WHERE {comments}.nid NOT in (SELECT nid FROM {node} n WHERE n.nid = {comments}.nid)");
549      drigg_log_msg('Cleaned up the "comments that went wrong"');
550    
551    // Reset the auto_increment for node_revision so that it doesn't go bananas    // Reset the auto_increment for node_revision so that it doesn't go bananas
552    $max = db_result(db_query("SELECT max(cid) FROM {comments}"));    $max = db_result(db_query("SELECT max(cid) FROM {comments}")) + 1;
   $max ++;  
553    db_query("ALTER TABLE {comments} AUTO_INCREMENT = %d", $max);    db_query("ALTER TABLE {comments} AUTO_INCREMENT = %d", $max);
554      drigg_log_msg("Corrected the AUTO_INCREMENT setting for the Drigg comments table");
555    
556    db_query("DELETE FROM {node_comment_statistics}");    db_query("DELETE FROM {node_comment_statistics}");
557      drigg_log_msg('Emptied the Drigg comment_statistics table');
558    
559      drigg_log_msg("Importing Pligg comment statistics...");
560    $query = sprintf("SELECT *,UNIX_TIMESTAMP(link_published_date) as link_published_date_t, UNIX_TIMESTAMP(link_date) as link_date_t, UNIX_TIMESTAMP(link_modified) as link_modified_t FROM pligg_links where (link_status = 'queued' OR link_status = 'published' )");    $query = sprintf("SELECT *,UNIX_TIMESTAMP(link_published_date) as link_published_date_t, UNIX_TIMESTAMP(link_date) as link_date_t, UNIX_TIMESTAMP(link_modified) as link_modified_t FROM pligg_links where (link_status = 'queued' OR link_status = 'published' )");
561    $result = mysql_query($query, $drigg_pligg_import_link);    $result = mysql_query($query, $drigg_pligg_import_link);
562    while ($r = mysql_fetch_assoc($result)) {    while ($r = mysql_fetch_assoc($result)) {
# Line 503  function drigg_pligg_import_pligg_import Line 565  function drigg_pligg_import_pligg_import
565    
566      _comment_update_node_statistics($r['link_id']);      _comment_update_node_statistics($r['link_id']);
567    }    }
568      drigg_log_msg("\tFinished importing Pligg comment statistics");
569    
570    
571    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
572    //          *** IMPORT THE VOTES ***    //          *** IMPORT THE VOTES ***
573    /////////////////////////////////////////////////////////    /////////////////////////////////////////////////////////
574    
575      drigg_log_msg("Importing Pligg votes...");
   
576    $query = sprintf("SELECT *,UNIX_TIMESTAMP(vote_date) as vote_date_t FROM pligg_votes where vote_user_id <> 0");    $query = sprintf("SELECT *,UNIX_TIMESTAMP(vote_date) as vote_date_t FROM pligg_votes where vote_user_id <> 0");
   #$query = sprintf("SELECT *,UNIX_TIMESTAMP(vote_date) as vote_date_t FROM pligg_votes where vote_user_id <> 0 ORDER BY vote_id DESC LIMIT 1000"); # FOR TESTING  
577    $result = mysql_query($query, $drigg_pligg_import_link);    $result = mysql_query($query, $drigg_pligg_import_link);
578    
579    while ($r = mysql_fetch_assoc($result)) {    while ($r = mysql_fetch_assoc($result)) {
   
580      if ($r['vote_type'] == 'links') {      if ($r['vote_type'] == 'links') {
581        $r_uid = db_result(db_query("SELECT uid FROM {node} where nid = %d", $r['vote_link_id']));        $r_uid = db_result(db_query("SELECT uid FROM {node} where nid = %d", $r['vote_link_id']));
582        $otype = 'n';        $otype = 'n';
# Line 541  function drigg_pligg_import_pligg_import Line 603  function drigg_pligg_import_pligg_import
603      $new_vote['content_id'] = $r['vote_link_id'];      $new_vote['content_id'] = $r['vote_link_id'];
604    
605      votingapi_set_votes($new_vote);      votingapi_set_votes($new_vote);
606        drigg_log_msg("\tuser_id [" . var_export($new_vote['uid'], true) . '] voted for content_id [' . var_export($new_vote['content_id'], true) . ']');
607    
608      // A bit of a hack to change the timestamp of the cast vote      // A bit of a hack to change the timestamp of the cast vote
609      db_query("UPDATE {votingapi_vote} SET timestamp = %d WHERE content_type = '%s' AND content_id = %d AND value_type = '%s' AND tag='%s' AND uid=%d",  $r['vote_date_t'], $content_type, $r['vote_link_id'], $value_type , $tag , $r['vote_user_id'] );      db_query("UPDATE {votingapi_vote} SET timestamp = %d WHERE content_type = '%s' AND content_id = %d AND value_type = '%s' AND tag='%s' AND uid=%d",  $r['vote_date_t'], $content_type, $r['vote_link_id'], $value_type , $tag , $r['vote_user_id'] );
   
610      #db_query("INSERT INTO {simple_karma} VALUES (%d,%d,'%s', %d,  %d, %d)", $r['vote_user_id'], $r['vote_link_id'], $otype, $r_uid, $karma, $r['vote_date_t']);      #db_query("INSERT INTO {simple_karma} VALUES (%d,%d,'%s', %d,  %d, %d)", $r['vote_user_id'], $r['vote_link_id'], $otype, $r_uid, $karma, $r['vote_date_t']);
   
611    }    }
612      drigg_log_msg("\tFinished importing Pligg votes");
613    
614    // That's it!    // That's it!
615    drupal_set_message(t("Data imported!"));    drupal_set_message(t("Data imported!"));
616      drigg_log_msg("\tFinished the Pligg");
617  }  }
618    
619  /////////////////////////////////////////////////////////////////  /////////////////////////////////////////////////////////////////

Legend:
Removed from v.1.1.2.2.2.2  
changed lines
  Added in v.1.1.2.2.2.3

  ViewVC Help
Powered by ViewVC 1.1.2