You are here

public static function ConvertBundles::convertFieldTables in Convert Bundles 8

File

src/ConvertBundles.php, line 205

Class

ConvertBundles
ConvertBundles.

Namespace

Drupal\convert_bundles

Code

public static function convertFieldTables($field_table_names, $ids, $to_type, $update_fields, &$context) {
  $message = 'Converting Field Tables...';
  $results = [];
  $db = Database::getConnection();

  // Field tables have 'entity_id' and 'bundle' columns.
  foreach ($field_table_names as $field_name => $table_name) {
    if ($db
      ->schema()
      ->tableExists($table_name)) {

      // Only do this when from and to fields are the same.
      if (in_array(str_replace('_revision', '', $field_name), $update_fields)) {
        $results[] = $db
          ->update($table_name)
          ->fields([
          'bundle' => $to_type,
        ])
          ->condition('entity_id', $ids, 'IN')
          ->execute();
      }
    }
  }
  $context['message'] = $message;
  $context['results'] = $results;
}