Migrate/Field Collection

Mo., 01/10/2012 - 20:32
Body
Wozu Migrate? Migrate ist ein Hilfsmodul mit dem man 3rd party Daten in Drupal migrieren kann. ACHTUNG man muss hier programmieren.

Dokumentation

http://drupal.org/node/415260

Artikel

http://www.davidreig.com/article/drupal-migrate-module-tutorial-migrating-multilingual-content http://www.gizra.com/content/data-migration-part-1 http://www.slideshare.net/SrijanOne/typo3-to-drupalmigratemodule http://www.gizra.com/content/data-migration-part-2

Video

http://denver2012.drupal.org/program/sessions/getting-it-drupal-migrate

Entity relation migration

http://janezurevc.name/relation-migrate-integration-and-reference-upgrade-path Modul als Beispiel http://drupal.org/project/entityreference_migration http://drupal.org/node/1536914

Field Collection

http://pingv.com/blog/drupal-migration-tips-handlers-field-collections-process-preprocess http://nikro.me/articles/professional/drupal-field-collections

WARNUNG

Eine Fieldcollection mit Entityreferencen zu migrieren geht nicht wirklich und wenn nur mit workarounds usw. Ich hab jetzt bald 10 Stunden in den Sand gesetzt und mach das nun manuell d.h Node anlegen per code und füllen...

Field Collection programmatisch anlegen

Weg 1

  1. <?php
  2. // Create node
  3. $node = new stdClass();
  4. $node->type = 'article';
  5. node_object_prepare($node);
  6. $node->title = 'Testing Article Creation';
  7. $node->language = LANGUAGE_NONE;
  8. $node->status = 1;
  9. $node->uid = 1;
  10. node_save($node);
  11.  
  12. // Create and save field collection for node
  13. $field_collection_item = entity_create('field_collection_item', array('field_name' => 'bir_collection'));
  14. $field_collection_item->setHostEntity('node', $node);
  15. $field_collection_item->bir_collection_node[LANGUAGE_NONE][]['nid'] = 99999;
  16. $field_collection_item->save();
  17. ?>

Weg 2

http://drupal.org/node/1477186
  1. <?php
  2. function foo_log_activity($node, $message, $uid = NULL) {
  3.   // Load the controller class file.
  4.   module_load_include('inc', 'entity', 'includes/entity.controller');
  5.  
  6.   // Use the currently logged in user if a $uid argument is not defined.
  7.   global $user;
  8.   if (empty($uid)) {
  9.     $uid = $user->uid;
  10.   }
  11.  
  12.   // Grab the current time in the format required by our date field. We need
  13.   // gmdate() here to get a time in UTC which is how everything is stored
  14.   // internally.
  15.   $now = gmdate('Y-m-d H:i:s');
  16.  
  17.   // Setup the values in the structure expected by the field_collection entity.
  18.   $values = array(
  19.     'field_name' => 'field_activity_log',
  20.     'field_activity_log_date' => array(
  21.       LANGUAGE_NONE => array(array('value' => $now)),
  22.     ),
  23.     'field_activity_log_message' => array(
  24.       LANGUAGE_NONE => array(array('value' => $message)),
  25.     ),
  26.     'field_activity_log_user' => array(
  27.       LANGUAGE_NONE => array(array('uid' => $uid)),
  28.     ),
  29.   );
  30.   $entity = entity_create('field_collection_item', $values);
  31.  
  32.   // Attach the field_collection entity to the application node. This has to
  33.   // happen separately so that it actually works -- you can't just specify
  34.   // this via the $values array.
  35.   $entity->setHostEntity('node', $node);
  36.  
  37.   // Save the entity. Since it's attached to the right application node, this
  38.   // will both create the field_collection entity and update the application
  39.   // node to point to the new field_activity_log record.
  40.   $entity->save();
  41. }
  42. ?>

Entity API

http://drupal.org/node/1842304 http://rajanmayekar.com/blog/programmatically-creating-deleting-modifying-field-collection-item-node | SUPER ARTIKEL
Drupal
Add new comment
The content of this field is kept private and will not be shown publicly.

Plain text

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <drupal-entity data-*>
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.