Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello
I have a code to insert values in nodes of field collection which works no problem:
function pdf_app_node_insert($node) {
if($node->type == 'article') {
$node_wrapper = entity_metadata_wrapper('node', $node);
$pdf = $node_wrapper->field_pdf->value();
$filex = file_load($node->field_pdf['und'][0]['fid']);
$filenamess = $filex->filename;
$filenames = "/sites/default/files/pdf/".$filenamess;
foreach ($node_wrapper->field_chapitres->value() as $library) {
$library_wrapper = entity_metadata_wrapper('field_collection_item', $library);
$ffp = $library_wrapper->field_from_page->value();
$ftp = $library_wrapper->field_to_page->value();
$fp = $library_wrapper->field_pdf_title->value();
$password = $library_wrapper->field_pdf_password->value();
$xx = "sites/default/files/pdf/".$filenamess;
$pdff = concatenate_pdf($xx, 'split/',$ffp,$ftp);
$pdfnews = upload_file_to_node($node, $pdff, $password);
$library_wrapper->field_pdf_uploaded = $pdfnews;
$library_wrapper->save();
$books = $library_wrapper->field_subchapters->value();
foreach($books as $book){
$book_wrapper = entity_metadata_wrapper('field_collection_item', $book);
$title = $book_wrapper->field_pdf_title2->value();
$ffp2 =$book_wrapper->field_from_page2->value();
$ftp2 = $book_wrapper->field_to_page2->value();
$password = $book_wrapper->field_pdf_password2->value();
$xx = "sites/default/files/pdf/".$filenamess;
$pdff2 = concatenate_pdf($xx, 'split/',$ffp2,$ftp2);
$pdfnews = upload_file_to_node($node, $pdff2, $password);
$book_wrapper->field_pdf_uploaded2 = $pdfnews;
$book_wrapper->save();
}
}
}
}
the problem is that it is not working when updating nodes only when creating new nodes. I tried to add the same code with hook node update but there are errors. What could be done? I think there is a problem of memory of too many files opened.... when doing updating ... it does wrapper save too many times...
Comments
Comment #2
rebeccamantel CreditAttribution: rebeccamantel commentedComment #3
apadernoComment #4
nakedscientist CreditAttribution: nakedscientist commentedWas any progress made with this? I have a similar problem and it's driving me nuts. I can populated Fc values in nodes just fine, but when I try to update them I get API errors. Bizarrely, if I wait a few hours, it works fine, so I don't think this is my code, which is similar to the above and just uses a wrapper to load the relevant node and then access the field collection. This suggests that something is being stored that shouldn't be - perhaps in the Fc tables somewhere - and is getting cleared by cron run?
Comment #5
apaderno