You are here

function yamlform_update_8080 in YAML Form 8

Issue #2837090: Undefined function call webform_schema.

File

./yamlform.install, line 284
Install, update and uninstall functions for the YAML Form module.

Code

function yamlform_update_8080() {

  // Fix key_value.collection which was no updated during the migration.
  $module_handler = \Drupal::moduleHandler();
  $database_type = Database::getConnection('default')
    ->databaseType();
  if ($module_handler
    ->moduleExists('webform') && !$module_handler
    ->moduleExists('yamlform') && $database_type == 'mysql') {
    $database = \Drupal::database();
    $select = $database
      ->select('key_value', 'kv');
    $select
      ->fields('kv', [
      'collection',
      'name',
      'value',
    ]);
    $select
      ->condition('collection', '%yamlform%', 'LIKE');
    $result = $select
      ->execute();
    while ($record = $result
      ->fetchAssoc()) {
      $old_collection = $record['collection'];
      $new_collection = str_replace('yamlform', 'webform', $record['collection']);
      $collection_select = $database
        ->select('key_value', 'kv');
      $collection_select
        ->fields('kv', [
        'collection',
        'name',
        'value',
      ]);
      $collection_select
        ->condition('collection', $new_collection);
      $collection_result = $collection_select
        ->execute();

      // Only insert the new record if there the collection does not exist.
      if (!$collection_result
        ->fetchAll()) {
        $record['collection'] = $new_collection;
        $database
          ->insert('key_value')
          ->fields([
          'collection',
          'name',
          'value',
        ])
          ->values(array_values($record))
          ->execute();
      }

      // Delete the old record.
      $database
        ->delete('key_value')
        ->condition('collection', $old_collection)
        ->execute();
    }
  }
}