Created
December 24, 2009 17:36
-
-
Save anarchivist/263279 to your computer and use it in GitHub Desktop.
Programmatic Drupal CCK node creation from CSV files using node_save()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* The long and the short of it, for Drupal 6 - use content_insert(), which | |
should be fired anyway but isn't. See "node_save() with CCK fields" [1] for | |
more details. drupal_execute() is too robust for me - I just needed to import | |
a SQL Server table with 4500+ rows quickly. Requires parsecsv for PHP [2]. | |
[1] http://drupal.org/node/218862#comment-726058 | |
[2] http://code.google.com/p/parsecsv-for-php/ | |
*/ | |
include_once('./includes/bootstrap.inc'); | |
include_once('./includes/form.inc'); | |
include_once('./modules/node/content_types.inc'); | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | |
bootstrap_invoke_all('init'); | |
ini_set('memory_limit', '512M'); | |
user_authenticate('user','password'); | |
require_once('parsecsv.lib.php'); | |
$csv = new parseCSV(); | |
$csv->auto('manu_collections.uniq.csv'); | |
module_load_include('inc', 'node', 'node.pages'); | |
$i = 0; | |
//print_r($csv->data); | |
foreach ($csv->data as $row) { | |
$node = new stdClass(); | |
#$node = array('type'=>'amatimport'); | |
$form_state = array(); | |
$node->type = 'amatimport'; | |
$node->title = $row['ManuscriptTitle']; | |
//$node->name = 'mmatienzo'; | |
$node->language = 'en'; | |
//$node->uid = '1'; | |
$node->field_arms_amat_id[0]['value'] = $row['Id']; | |
$node->field_arms_findingaids[0]['value'] = $row['FindingAids']; | |
$node->field_arms_amat_printfindingaid[0]['value'] = $row['PrintFindingAid']; | |
$node->field_arms_catnyp_old[0]['value'] = $row['CatnypLink']; | |
$node->field_arms_amat_project_link[0]['value'] = $row['ProjectLink']; | |
$node->field_arms_amat_seealso[0]['value'] = $row['SeeAlso']; | |
$node->field_arms_closed['value'] = $row['Closed']; | |
$node->field_arms_amat_location[0]['value'] = $row['Location']; | |
$node->field_arms_sgmcatnyp[0]['value'] = $row['SgmCatnyp']; | |
$node->field_arms_sgmead[0]['value'] = $row['SgmEad']; | |
$node->field_arms_seeref[0]['value'] = $row['SeeRef']; | |
$node->field_arms_creator[0]['value'] = $row['ManuscriptAuthor']; | |
$node->field_arms_mssdbid[0]['value'] = $row['MSS_ID']; | |
$node->op = t('Save'); | |
if ($row['Wilson'] = 'TRUE') { | |
$wilson = 1; | |
} else { | |
$wilson = 0; | |
} | |
$node->field_arms_amat_wilson['value'] = $wilson; | |
content_presave($node); | |
node_save($node); | |
content_insert($node); | |
$i++; | |
print $i . '<br/>'; | |
#break; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment