0

This question already has an answer here:

I am running a drupal 7 site and i have the following problem : I have multiple audio files (1000+) and i need to create a custom node for each of them.

I managed to do it (almost) but i don't know how to send the field_fisier_display value for the column. The initial table was created (automatically by drupal) to not allow NULL and to have a 1 as default value. But when i run my script I get a PDO statemnt error that says i cannot insert NULL in that field.

I fixed it (for now) by changing the tables drp7_field_data_field_fisier and drp7_field_revision_field_fisier to allow NULL and to run an UPDATE statement after the node ceration. I don't like this fix.

Please share your wisdome with me in solving this problem.

My current script is :

for ($i = 0; $i < count($predici_neprocesate); $i++) {
    $predica = $predici_neprocesate[$i];
    $new_node = new stdClass();
    $new_node->type = 'predica';
    node_object_prepare($new_node);

    $new_node->uid = 1;
    $new_node->title = $predica;
    $new_node->body['und'][0]['value'] = "value";
    $new_node->body['und'][0]['format'] = 'filtered_html';
    $file_path = drupal_realpath($predica);
    $file = (object) array(
                'uid' => 1,
                'uri' => $file_path,
                'filemime' => file_get_mimetype($file_path),
                'status' => 1,
                'filename' => $predica,
                'type' => 'audio'
    );
    $file = file_copy($file, 'address');
    $new_node->field_fisier['und'][0] = (array) $file;

    node_submit($new_node);
    $new = node_save($new_node);

    unlink($file_path);
    $sql = "UPDATE drp7_field_revision_field_fisier SET field_fisier_display = 1 WHERE entity_id = " . $new_node->nid;
    executeSQL($sql);
    $sql = "UPDATE drp7_field_data_field_fisier SET field_fisier_display = 1 WHERE entity_id = " . $new_node->nid;
    executeSQL($sql);
}

Please let me know what information do you need, in order to give me an ideea (table structure / content type structure etc).

marked as duplicate by mpdonadio Mar 2 '14 at 12:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Browse other questions tagged or ask your own question.