You are here

function commerce_migrate_ubercart_update_8201 in Commerce Migrate 3.1.x

Same name and namespace in other branches
  1. 8.2 modules/ubercart/commerce_migrate_ubercart.module \commerce_migrate_ubercart_update_8201()
  2. 3.0.x modules/ubercart/commerce_migrate_ubercart.module \commerce_migrate_ubercart_update_8201()

Update map table for the d7 field migration to migrate field values.

File

modules/ubercart/commerce_migrate_ubercart.module, line 61
Contains commerce_migrate_ubercart.module.

Code

function commerce_migrate_ubercart_update_8201(&$sandbox) {
  $migrations = \Drupal::service('plugin.manager.migration')
    ->createInstances([]);
  if (empty($migrations)) {
    return;
  }

  // Ensure that any migration using the uc7 Field source plugin has a column
  // for the commerce_product flag.
  // See https://www.drupal.org/project/commerce_migrate/issues/3052488.
  $schema = \Drupal::database()
    ->schema();
  foreach ($migrations as $migration) {
    $source = $migration
      ->getSourcePlugin();
    if (Utility::classInArray($source, [
      Uc7Field::class,
    ])) {
      $table_name = $migration
        ->getIdMap()
        ->mapTableName();
      if ($schema
        ->tableExists($table_name)) {
        $count = count($source
          ->getIds());
        $field_name = "sourceid{$count}";
        if (!$schema
          ->fieldExists($table_name, $field_name)) {
          $schema
            ->addField($table_name, "sourceid{$count}", [
            'type' => 'int',
            'length' => 11,
            'not null' => FALSE,
          ]);
        }
      }
    }
  }
}