You are here

function _commerce_migrate_ubercart_get_product_node_types 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_get_product_node_types()
  2. 3.0.x modules/ubercart/commerce_migrate_ubercart.module \_commerce_migrate_ubercart_get_product_node_types()

Get the node types that are products.

Parameters

array $migrations: An array of all migrations.

Return value

array An array of node types that are product types.

1 call to _commerce_migrate_ubercart_get_product_node_types()
commerce_migrate_ubercart_migration_plugins_alter in modules/ubercart/commerce_migrate_ubercart.module
Implements hook_migration_plugins_alter().

File

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

Code

function _commerce_migrate_ubercart_get_product_node_types(array $migrations) {
  $source_plugin = \Drupal::service('plugin.manager.migration')
    ->createStubMigration($migrations['uc6_store'])
    ->getSourcePlugin();
  $product_node_types = [];
  $connection = NULL;
  try {
    $connection = $source_plugin
      ->getDatabase();
  } catch (RequirementsException $e) {

    // It is possible the commerce_migrate is enabled to use the supplied
    // plugins, but the migrations are not configured. In this case, the
    // exported configurations are not available to swap out the default
    // sql source key of 'migrate'.
  }
  if ($connection) {
    if ($connection
      ->schema()
      ->tableExists('node_type')) {
      $query = $connection
        ->select('node_type', 'nt')
        ->fields('nt', [
        'type',
      ])
        ->condition('module', 'uc_product%', 'LIKE')
        ->distinct();
      $product_node_types = $query
        ->execute()
        ->fetchCol();
    }
  }
  return $product_node_types;
}