/[drupal]/contributions/modules/flexiconvert/flexiconvert.module
ViewVC logotype

Diff of /contributions/modules/flexiconvert/flexiconvert.module

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

revision 1.11, Thu Jun 4 17:13:38 2009 UTC revision 1.12, Thu Jun 4 17:14:40 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: flexiconvert.module,v 1.10 2009/06/04 17:11:03 anarcat Exp $  // $Id: flexiconvert.module,v 1.11 2009/06/04 17:13:38 anarcat Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 303  function flexiconvert_form_validate($for Line 303  function flexiconvert_form_validate($for
303   */   */
304  function flexiconvert_form_submit($form_id, $form_values) {  function flexiconvert_form_submit($form_id, $form_values) {
305    
306    drupal_set_message("entering main flexiconvert process");    drupal_set_message(t("starting main flexiconvert engine"));
307    // Keep track of created fields so we don't get SQL duplication errors.    // Keep track of created fields so we don't get SQL duplication errors.
308    $fields_submitted = array();    $fields_submitted = array();
309    
# Line 333  function flexiconvert_form_submit($form_ Line 333  function flexiconvert_form_submit($form_
333        $type_obj->modified = FALSE;        $type_obj->modified = FALSE;
334        $type_obj->locked = FALSE;        $type_obj->locked = FALSE;
335    
336        drupal_set_message("created new type: ". $ftype['title']);        drupal_set_message(t("creating new CCK type %name", array('%name' => $ftype['title'])));
337        node_type_save($type_obj);        node_type_save($type_obj);
338      }      }
339    } // End type conversion loop...    } // End type conversion loop...
# Line 357  function flexiconvert_form_submit($form_ Line 357  function flexiconvert_form_submit($form_
357            break;            break;
358          }          }
359    
360          drupal_set_message("adding field: $field_name (" . $fd['field_type'] . ")");          drupal_set_message(t("found field %name (%type)", array('%name' => $field_name, '%type' => $fd['field_type'])));
361    
362          $cck_type = _flexiconvert_field_to_cck($fd['field_type']);          $cck_type = _flexiconvert_field_to_cck($fd['field_type']);
363    
# Line 409  function flexiconvert_form_submit($form_ Line 409  function flexiconvert_form_submit($form_
409    
410    // Data conversion    // Data conversion
411    
   // counters: we count down to zero. if we're already at zero, we never stop.  
412    $max_nodes = $form_values['max_nodes'];    $max_nodes = $form_values['max_nodes'];
   $position = $max_nodes;  
413    $count = 0;    $count = 0;
414    
415      if ($max_nodes) {
416        $limit = ' LIMIT %d';
417      } else {
418        $limit = '';
419        $max_nodes = '(no max)';
420      }
421    
422    foreach ($form_values['flexiconvert_type'] as $fdata) {    foreach ($form_values['flexiconvert_type'] as $fdata) {
423      if ($fdata['checked']) {      if ($fdata['checked']) {
424        drupal_set_message("importing $max_nodes nodes from flexinode for " . $fdata['title']);        drupal_set_message(t("importing %count nodes from flexinode for %field", array('%count' => $max_nodes, '%field' => $fdata['title'])));
425        $type = flexiconvert_get_type($fdata['title']);        $type = flexiconvert_get_type($fdata['title']);
426        $q = db_query("SELECT r.*, n.created, n.status, n.changed, n.comment, n.promote, n.moderate, n.sticky FROM {node_revisions} r, {node} n WHERE n.nid=r.nid AND n.type='%s'", ('flexinode-' . $type->ctype_id));        $q = db_query("SELECT r.*, n.created, n.status, n.changed, n.comment, n.promote, n.moderate, n.sticky FROM {node_revisions} r, {node} n WHERE n.nid=r.nid AND n.type='%s' ORDER BY n.nid" . $limit, ('flexinode-' . $type->ctype_id), $max_nodes);
427    
428        while ($position-- != 0 && $node = db_fetch_object($q)) {        while ($node = db_fetch_object($q)) {
429          $resave = new stdClass();          $resave = new stdClass();
430          $resave->nid = $node->nid;          $resave->nid = $node->nid;
431          $resave->vid = $node->vid;          $resave->vid = $node->vid;
# Line 439  function flexiconvert_form_submit($form_ Line 444  function flexiconvert_form_submit($form_
444          $resave->sticky = $node->sticky;          $resave->sticky = $node->sticky;
445    
446          $fq = db_query('SELECT * FROM {flexinode_data} WHERE nid=%d', $resave->nid);          $fq = db_query('SELECT * FROM {flexinode_data} WHERE nid=%d', $resave->nid);
447    
448          // Get the flexinode field data.          // Get the flexinode field data.
   
449          while ($fnode = db_fetch_object($fq)) {          while ($fnode = db_fetch_object($fq)) {
450            foreach ($type->fields as $fd) {            foreach ($type->fields as $fd) {
451              if ($fd['field_id'] == $fnode->field_id) {              if ($fd['field_id'] == $fnode->field_id) {
# Line 463  function flexiconvert_form_submit($form_ Line 468  function flexiconvert_form_submit($form_
468    
469          db_query("UPDATE {node} SET type='%s' WHERE type='%s' AND nid='%d'", _flexiconvert_fix_single_type(strtolower($type->name)), ('flexinode-' . $type->ctype_id), $node->nid);          db_query("UPDATE {node} SET type='%s' WHERE type='%s' AND nid='%d'", _flexiconvert_fix_single_type(strtolower($type->name)), ('flexinode-' . $type->ctype_id), $node->nid);
470          $count++;          $count++;
 //         drupal_set_message("stopping after first conversion");  
 //         break;  
   
471        }        }
472      }      }
473    } // End data conversion loop...    } // End data conversion loop...
# Line 477  function flexiconvert_form_submit($form_ Line 479  function flexiconvert_form_submit($form_
479    if ($image_type_exists && !$image_module_exists) {    if ($image_type_exists && !$image_module_exists) {
480      drupal_set_message(t('All content was converted (including image types) but it was found that your installation contains the content type "image" but the image.module file was not enabled.  If this is true or you don\'t have alternate "image" type, then content of type "image" may cause errors upon viewing and/or editing.  It is strongly advised that you enable the image module and upload all of the respective image files to your files directory.'), 'error');      drupal_set_message(t('All content was converted (including image types) but it was found that your installation contains the content type "image" but the image.module file was not enabled.  If this is true or you don\'t have alternate "image" type, then content of type "image" may cause errors upon viewing and/or editing.  It is strongly advised that you enable the image module and upload all of the respective image files to your files directory.'), 'error');
481    } else {    } else {
482      drupal_set_message(t('%count nodes were converted', array('%count' => $count)), 'status');      drupal_set_message(t('%count out of %max nodes were converted', array('%count' => $count, '%max' => $max_nodes)), 'status');
483    }    }
484  }  }
485    

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.2