| 1 |
<?php |
<?php |
| 2 |
// $Id: flexiconvert.module,v 1.8 2008/08/19 02:34:40 aj045 Exp $ |
// $Id: flexiconvert.module,v 1.9 2009/06/04 17:09:54 anarcat Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 276 |
'#suffix' => '</div><div id="flexiconvert_title"><em>Check all</em></div></div>', |
'#suffix' => '</div><div id="flexiconvert_title"><em>Check all</em></div></div>', |
| 277 |
); |
); |
| 278 |
|
|
| 279 |
|
|
| 280 |
|
$form['max_nodes'] = array('#type' => 'textfield', '#size' => 3, '#title' => t('Sample size'), '#description' => t("Number of nodes to process in the current run. Leave blank to process all nodes that can be completed within the PHP max_execution_time or memory_limit.")); |
| 281 |
|
|
| 282 |
$form['submit'] = array( |
$form['submit'] = array( |
| 283 |
'#type' => 'submit', |
'#type' => 'submit', |
| 284 |
'#value' => 'Convert', |
'#value' => 'Convert', |
| 302 |
* Implementation of hook_form_submit(). |
* Implementation of hook_form_submit(). |
| 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"); |
| 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 |
|
|
| 332 |
$type_obj->custom = TRUE; |
$type_obj->custom = TRUE; |
| 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']); |
| 337 |
node_type_save($type_obj); |
node_type_save($type_obj); |
| 338 |
} |
} |
| 339 |
} // End type conversion loop... |
} // End type conversion loop... |
| 343 |
if ($ffield['checked']) { |
if ($ffield['checked']) { |
| 344 |
$type = flexiconvert_get_type($ffield['title']); |
$type = flexiconvert_get_type($ffield['title']); |
| 345 |
foreach($type->fields as $fd) { |
foreach($type->fields as $fd) { |
| 346 |
// Much of the code that appears below is straight from the CCK module. |
// Much of the code that appears below is straight from the CCK module. |
| 347 |
// The code is quite messy and a bit hard to read but it gets the job done. |
// The code is quite messy and a bit hard to read but it gets the job done. |
| 348 |
$field_name = trim($fd['label']); |
$field_name = trim($fd['label']); |
| 349 |
$field_name = drupal_strtolower($field_name); |
$field_name = drupal_strtolower($field_name); |
| 350 |
$field_name = str_replace(array(' ', '-'), '_', $field_name); |
$field_name = str_replace(array(' ', '-'), '_', $field_name); |
| 356 |
// Prevent unnecessary duplication of fields. |
// Prevent unnecessary duplication of fields. |
| 357 |
break; |
break; |
| 358 |
} |
} |
| 359 |
|
|
| 360 |
|
drupal_set_message("adding field: $field_name (" . $fd['field_type'] . ")"); |
| 361 |
|
|
| 362 |
$cck_type = _flexiconvert_field_to_cck($fd['field_type']); |
$cck_type = _flexiconvert_field_to_cck($fd['field_type']); |
| 363 |
|
|
| 364 |
db_query("INSERT INTO {node_field} (field_name, type, global_settings, required, multiple, db_storage) VALUES ('%s', '%s', '%s', %d, %d, %d)", |
db_query("INSERT INTO {node_field} (field_name, type, global_settings, required, multiple, db_storage) VALUES ('%s', '%s', '%s', %d, %d, %d)", |
| 408 |
} // End field conversion loop... |
} // End field conversion loop... |
| 409 |
|
|
| 410 |
// Data conversion |
// Data conversion |
| 411 |
|
|
| 412 |
|
// counters: we count down to zero. if we're already at zero, we never stop. |
| 413 |
|
$max_nodes = $form_values['max_nodes']; |
| 414 |
|
$position = $max_nodes; |
| 415 |
|
$count = 0; |
| 416 |
|
|
| 417 |
foreach ($form_values['flexiconvert_type'] as $fdata) { |
foreach ($form_values['flexiconvert_type'] as $fdata) { |
| 418 |
if ($fdata['checked']) { |
if ($fdata['checked']) { |
| 419 |
|
drupal_set_message("importing $max_nodes nodes from flexinode for " . $fdata['title']); |
| 420 |
$type = flexiconvert_get_type($fdata['title']); |
$type = flexiconvert_get_type($fdata['title']); |
| 421 |
$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'", ('flexinode-' . $type->ctype_id)); |
| 422 |
|
|
| 423 |
while ($node = db_fetch_object($q)) { |
while ($position-- != 0 && $node = db_fetch_object($q)) { |
| 424 |
$resave = new stdClass(); |
$resave = new stdClass(); |
| 425 |
$resave->nid = $node->nid; |
$resave->nid = $node->nid; |
| 426 |
$resave->vid = $node->vid; |
$resave->vid = $node->vid; |
| 460 |
// No need to resave the node again-- it already exists! |
// No need to resave the node again-- it already exists! |
| 461 |
// So instead we go straight to CCK because it will need |
// So instead we go straight to CCK because it will need |
| 462 |
// to populate the content type tables. |
// to populate the content type tables. |
| 463 |
|
|
| 464 |
|
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); |
| 465 |
|
$count++; |
| 466 |
|
// drupal_set_message("stopping after first conversion"); |
| 467 |
|
// break; |
| 468 |
|
|
| 469 |
} |
} |
| 470 |
} |
} |
|
db_query("UPDATE {node} SET type='%s' WHERE type='%s'", _flexiconvert_fix_single_type(strtolower($type->name)), ('flexinode-' . $type->ctype_id)); |
|
| 471 |
} // End data conversion loop... |
} // End data conversion loop... |
| 472 |
|
|
| 473 |
menu_rebuild(); |
menu_rebuild(); |
| 476 |
// file does not, we've got problems. |
// file does not, we've got problems. |
| 477 |
if ($image_type_exists && !$image_module_exists) { |
if ($image_type_exists && !$image_module_exists) { |
| 478 |
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'); |
| 479 |
|
} else { |
| 480 |
|
drupal_set_message(t('%count nodes were converted', array('%count' => $count)), 'status'); |
| 481 |
} |
} |
| 482 |
} |
} |
| 483 |
|
|