You are here

mongodb_migrate.module in MongoDB 7

The mongodb_migrate module provides SQL to MongoDB migration helpers.

File

mongodb_migrate/mongodb_migrate.module
View source
<?php

/**
 * @file
 * The mongodb_migrate module provides SQL to MongoDB migration helpers.
 */

/**
 * Load entity with fields from SQL storage.
 *
 * @param string $entity_type
 *   The entity type.
 * @param array $entities
 *   The entities to load.
 * @param string $age
 *   Likely FIELD_LOAD_CURRENT.
 * @param array $fields
 *   The fields to load on the entities.
 * @param array $options
 *   Load options.
 */
function mongodb_migrate_load_helper($entity_type, array $entities, $age, array &$fields, array $options) {
  $all_types = variable_get('mongodb_migrate_types', array());
  $migrate_fields = variable_get('mongodb_migrate_fields', array());
  if (defined('DRUSH_VERSION') && $age == FIELD_LOAD_CURRENT && in_array($entity_type, $all_types)) {
    $field_info = field_info_field_by_ids();
    $sql_fields = array();
    foreach ($fields as $field_id => $ids) {
      $field_name = $field_info[$field_id]['field_name'];
      if (isset($migrate_fields[$field_name])) {
        $sql_fields[$field_id] = $ids;
        unset($fields[$field_id]);
      }
    }
    if ($sql_fields) {
      field_sql_storage_field_storage_load($entity_type, $entities, $age, $sql_fields, $options);
    }
  }
}

/**
 * Mark migrated entity as having its fields deleted in SQL storage.
 *
 * @param string $entity_type
 *   The type of the entity to update.
 * @param int $entity_id
 *   The ID of the entity to update.
 */
function mongodb_migrate_write_helper($entity_type, $entity_id) {
  $migrate_fields = variable_get('mongodb_migrate_fields', []);
  foreach ($migrate_fields as $field_name => $v) {
    $field = field_info_field($field_name);
    db_update(_field_sql_storage_tablename($field))
      ->fields([
      'deleted' => 2,
    ])
      ->condition('entity_type', $entity_type)
      ->condition('entity_id', $entity_id)
      ->execute();
  }
}

Functions

Namesort descending Description
mongodb_migrate_load_helper Load entity with fields from SQL storage.
mongodb_migrate_write_helper Mark migrated entity as having its fields deleted in SQL storage.