Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. /**
  2. * Set value for field_seccion_general to the nodes that not have this field set.
  3. */
  4. function incae_custom_functions_update_7003(&$sandbox) {
  5.  
  6. if (!isset($sandbox['progress'])) {
  7. $entities = incae_custom_functions_get_unset_field_seccion_genenal_entities('node');
  8. $sandbox['max'] = count($entities) - 1;
  9. $sandbox['limit'] = 100;
  10. $sandbox['entities'] = array_values(node_load_multiple($entities));
  11. $sandbox['progress'] = 0;
  12. }
  13. watchdog('sandbox p', serialize($sandbox['progress']));
  14. $chunk = array_slice($sandbox['entities'], $sandbox['progress'], $sandbox['limit']);
  15. if (count($chunk)) {
  16. foreach ($chunk as $key => $entity) {
  17. $wrapper = entity_metadata_wrapper('node', $entity);
  18. $wrapper->field_seccion_general = array('masters');
  19. $wrapper->save();
  20. $sandbox['progress'] = $key;
  21. if ($key == $sandbox['max']) {
  22. $sandbox['#finish'] = 1;
  23. }
  24. else {
  25. $sandbox['#finish'] = -1;
  26. }
  27. }
  28. }
  29. if ($sandbox['#finish'] === TRUE) {
  30. return 'the last procced node was ' . $sandbox['progress'];
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement