You are here

function certificate_update_7005 in Certificate 7.3

Same name and namespace in other branches
  1. 8.3 certificate.install \certificate_update_7005()

Migrate node certificates to entities.

File

./certificate.install, line 615
Install the Certificate module.

Code

function certificate_update_7005() {
  module_enable(array(
    'entity',
  ));
  $nodes = node_load_multiple(array(), array(
    'type' => 'certificate',
  ));
  $certificate_settings = db_select('certificate_node_settings', 'c')
    ->fields('c')
    ->execute()
    ->fetchAllKeyed(0, 1);
  foreach ($nodes as $node) {

    /* @var $certificate Entity */
    $certificate = entity_create('certificate', array(
      'cid' => $node->nid,
      'title' => $node->title,
      'name' => $node->nid,
      'certificate_body' => $node->body,
      'orientation' => $certificate_settings[$node->nid],
      'type' => 'certificate',
    ));
    $certificate
      ->save();
    node_delete($node->nid);
  }
  return t('Migrated certificates. New machine names are the original node IDs.');
}