diff --git a/sites/default/modules/flexiconvert/flexiconvert.module b/sites/default/modules/flexiconvert/flexiconvert.module
index 90e609b..474b449 100644
--- a/sites/default/modules/flexiconvert/flexiconvert.module
+++ b/sites/default/modules/flexiconvert/flexiconvert.module
@@ -3,7 +3,7 @@
/**
* Implementation of hook_help().
*/
-function flexiconvert_help($section) {
+function flexiconvert_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Tool to help convert flexinodes to cck nodes');
@@ -22,7 +22,7 @@ function flexiconvert_help($section) {
'
Create a new CCK type for each old type - each type must have exactly the same name, and each fields must have the same name as the old field.' .
' Run admin/flexiconvert/convert for each node type, selected the matching names in both selectors' .
' Be sure not add categories to the CCK types until after you run the converter, because then cck restructures the node table' .
- ''
+ ''
);
}
}
@@ -35,9 +35,9 @@ function flexiconvert_menu($may_cache) {
$items = array();
if (!$may_cache) {
$items[] = array(
- 'path' => 'admin/flexiconvert/convert',
- 'title' => t('flexiconvert'),
- 'callback' => 'flexiconvert_page',
+ 'path' => 'admin/flexiconvert/convert',
+ 'title' => t('flexiconvert'),
+ 'callback' => 'flexiconvert_page',
'access' => ($user->id == 0),
);
}
@@ -47,21 +47,28 @@ function flexiconvert_menu($may_cache) {
function flexiconvert_form_submit($form_id, $form_values) {
$flexitype = $form_values['flexitype'];
$ccktype = $form_values['ccktype'];
- variable_set( 'flexiconvert_flexitype', $flexitype );
- variable_set( 'flexiconvert_ccktype', $ccktype );
-
+ variable_set( 'flexiconvert_flexitype', $flexitype );
+ variable_set( 'flexiconvert_ccktype', $ccktype );
+
$flexitype_name = 'flexinode-'. $flexitype;
drupal_set_message( "Syncing flexinode: $flexitype_name to cck: $ccktype " );
-
+
$fields = array();
$result = db_query( "SELECT field_id, label FROM {flexinode_field} WHERE ctype_id = ". $flexitype );
while( $row = db_fetch_array( $result ) ) {
$label = $row['label'];
- $cckfield = strtolower( $label );
- $cckfield = 'field_'. str_replace( ' ', '_', $cckfield ); // .'_value';
- $fields[ $row['field_id'] ] = $cckfield;
+
+ //// Copied from content_admin.inc: function _content_admin_field_add_new_submit
+ $cckfield = trim($label);
+ $cckfield = drupal_strtolower($cckfield);
+ $cckfield = str_replace(array(' ', '-'), '_', $cckfield);
+ $cckfield = preg_replace('/[^a-z0-9_]/', '', $cckfield);
+ $cckfield = 'field_'. $cckfield;
+ $cckfield = substr($cckfield, 0, 31);
+
+ $fields[ $row['field_id'] ] = $cckfield;
drupal_set_message( "Mapping $label (flexifield-".$row['field_id'].") to $cckfield" );
- }
+ }
// gather all the field data, ordered per node
$nodes = array();
@@ -91,12 +98,12 @@ function flexiconvert_form_submit($form_id, $form_values) {
// drupal_set_message( $sql );
$result = db_query( $sql );
$count_to_convert = db_num_rows($result);
- drupal_set_message( "There are $count_to_convert items to convert" );
- $fields_str = '';
+ drupal_set_message( "There are $count_to_convert items to convert" );
+ $fields_str = '';
$count = 0;
- while( $row = db_fetch_array( $result ) ) {
+ while( $row = db_fetch_array( $result ) ) {
$count++;
- // INSERT flexinode data as rows in cck table
+ // INSERT flexinode data as rows in cck table
$nid = $row['nid'];
$vid = $row['vid'];
$node = $nodes[$nid];
@@ -105,6 +112,8 @@ function flexiconvert_form_submit($form_id, $form_values) {
//drupal_set_message( "$count: $sql" );
db_query( $sql );
foreach( $node as $cckfield => $value ) {
+
+
// db_query( "UPDATE {%s} SET %s = '%s' WHERE nid = %d", $cck_table, $cckfield . '_value', $value['text'], $nid );
// if( $value['format'] != 0 ) {
// db_query( "UPDATE {%s} SET %s = '%d' WHERE nid = %d", $cck_table, $cckfield . '_format', $value['format'], $nid );
@@ -127,14 +136,14 @@ function flexiconvert_form_submit($form_id, $form_values) {
$file = unserialize($value['file']);
$fid = db_next_id('{files}_fid');
db_query("INSERT into {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s','%s','%s',%d)", $fid, $nid, $file->filename, $file->filepath, $file->filemime, $file->filesize);
- db_query( "UPDATE {%s} SET %s = '%s', %s = '%s', %s = '%s' WHERE nid = %d", $cck_table, $cckfield . '_fid', $fid, $cckfield . '_description', $file->filename, $cckfield . '_list', 0, $nid);
+ db_query( "UPDATE {%s} SET %s = '%s', %s = '%s', %s = '%s' WHERE nid = %d", $cck_table, $cckfield . '_fid', $fid, $cckfield . '_description', $file->filename, $cckfield . '_list', 0, $nid);
}
}
}
$result = db_query( "SELECT nid FROM {$cck_table}" );
$count_converted = db_num_rows($result);
- drupal_set_message( "Inserted '$count_converted' items ($count)" );
+ drupal_set_message( "Inserted '$count_converted' items ($count)" );
if( $count_converted == $count_to_convert ) {
drupal_set_message( "Yay, all nodes converted" );
@@ -142,47 +151,44 @@ function flexiconvert_form_submit($form_id, $form_values) {
$sql = "UPDATE {node} SET type = '$ccktype' WHERE type = '$flexitype_name'";
//drupal_set_message( "Not Done: ". $sql );
db_query( $sql );
- }
+ }
else {
drupal_set_message( "Boo!!");
}
-}
+}
-function flexiconvert_page() {
- drupal_set_title( "Flexiconvert" );
+function flexiconvert_page() {
+ drupal_set_title( "Flexiconvert" );
$types = array();
$result = db_query( "SELECT name, ctype_id FROM {flexinode_type}" );
while( $row = db_fetch_array( $result ) ) {
- $types[ $row['ctype_id'] ] = $row['name'];
+ $types[ $row['ctype_id'] ] = $row['name'];
}
-
+
$form = array();
$form['flexitype'] = array(
'#type' => 'select',
'#title' => t('Flexinode to read from'),
'#options' => $types,
'#default_value' => variable_get( 'flexiconvert_flexitype', NULL ),
- );
+ );
$ccktypes = array();
$result = db_query( "SELECT label, type_name FROM {node_type_content}" );
while( $row = db_fetch_array( $result ) ) {
- $ccktypes[ $row['type_name'] ] = $row['label'];
- }
+ $ccktypes[ $row['type_name'] ] = $row['label'];
+ }
$form['ccktype'] = array(
'#type' => 'select',
'#title' => t('CCK Type to insert into'),
'#options' => $ccktypes,
'#default_value' => variable_get( 'flexiconvert_ccktype', NULL ),
- );
-
+ );
+
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Do It'),
);
-
+
return drupal_get_form('flexiconvert_form', $form);
}
-
-
-