You are here

opigno_learning_path.install in Opigno Learning path 8

Same filename and directory in other branches
  1. 3.x opigno_learning_path.install

Install, update and uninstall functions for the module.

File

opigno_learning_path.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the module.
 */
use Drupal\Core\Database\Database;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Config\FileStorage;
use Drupal\opigno_learning_path\LearningPathAccess;
use Drupal\user\Entity\Role;

/**
 * Creates database table for Learning Path group user statuses.
 *
 * On module install.
 */
function opigno_learning_path_install() {
  LearningPathAccess::createUserStatusTable();
  _opigno_learning_path_create_achievements_table();
  _opigno_learning_path_create_step_achievements_table();
  _opigno_learning_path_create_lp_module_availability_table();
  _opigno_learning_path_create_user_lp_status_table();
  _opigno_learning_path_create_user_lp_status_expire_table();
}

/**
 * Creates database table for Learning Path group user statuses.
 *
 * For existing instances.
// */
function opigno_learning_path_update_8002() {
  LearningPathAccess::createUserStatusTable();
}

/**
 * Creates database table for Latest Activity entity type.
 */
function opigno_learning_path_update_8004() {
  $database = \Drupal::database();
  if (!$database
    ->schema()
    ->tableExists('opigno_latest_group_activity')) {
    $entityTypeManager = \Drupal::entityTypeManager();
    $entityTypeManager
      ->clearCachedDefinitions();
    $definition = $entityTypeManager
      ->getDefinition('opigno_latest_group_activity');
    \Drupal::entityDefinitionUpdateManager()
      ->installEntityType($definition);
  }
  else {
    return 'Latest Activity entity already exists';
  }
  return NULL;
}

/**
 * Creates forum field in the learning path group type.
 */
function opigno_learning_path_update_8005() {
}

/**
 * Creates enable forum field in the learning path group type.
 */
function opigno_learning_path_update_8006() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $data = $storage
    ->read('field.storage.group.field_learning_path_enable_forum');
  if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
    FieldStorageConfig::create($data)
      ->save();
  }
  $data = $storage
    ->read('field.field.group.learning_path.field_learning_path_enable_forum');
  if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
    FieldConfig::create($data)
      ->save();
  }
}

/**
 * Creates achievements tables.
 */
function opigno_learning_path_update_8007() {
  _opigno_learning_path_create_achievements_table();
  _opigno_learning_path_create_step_achievements_table();
}

/**
 * Creates achievements table.
 */
function _opigno_learning_path_create_achievements_table() {
  $schema = \Drupal::database()
    ->schema();
  $table_name = 'opigno_learning_path_achievements';
  if (!$schema
    ->tableExists($table_name)) {
    $table = [
      'description' => 'Training Achievements',
      'fields' => [
        'id' => [
          'type' => 'serial',
          'not null' => TRUE,
        ],
        'uid' => [
          'description' => 'User ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'gid' => [
          'description' => 'Training ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'name' => [
          'description' => 'Training Name',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
          'default' => '',
        ],
        'status' => [
          'description' => 'Training Status',
          'type' => 'varchar',
          'length' => 20,
          'not null' => TRUE,
        ],
        'score' => [
          'description' => 'Training Score',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'progress' => [
          'description' => 'Training Progress',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'time' => [
          'description' => 'Time spent',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'registered' => [
          'description' => 'Date of registration',
          'type' => 'varchar',
          'mysql_type' => 'datetime',
          'not null' => TRUE,
        ],
        'completed' => [
          'description' => 'Date of completion',
          'type' => 'varchar',
          'length' => 20,
          'mysql_type' => 'datetime',
          'not null' => FALSE,
        ],
      ],
      'primary key' => [
        'id',
      ],
      'indexes' => [
        'uid' => [
          'uid',
        ],
        'gid' => [
          'gid',
        ],
      ],
      'foreign keys' => [
        'users' => [
          'uid' => 'uid',
        ],
        'groups' => [
          'gid' => 'id',
        ],
      ],
    ];
    $schema
      ->createTable($table_name, $table);
  }
}

/**
 * Creates achievements table.
 */
function _opigno_learning_path_create_step_achievements_table() {
  $schema = \Drupal::database()
    ->schema();
  $table_name = 'opigno_learning_path_step_achievements';
  if (!$schema
    ->tableExists($table_name)) {
    $table = [
      'description' => 'Training Step Achievements',
      'fields' => [
        'id' => [
          'type' => 'serial',
          'not null' => TRUE,
        ],
        'uid' => [
          'description' => 'User ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'entity_id' => [
          'description' => 'Step Entity ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'name' => [
          'description' => 'Step Name',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
          'default' => '',
        ],
        'typology' => [
          'description' => 'Step Typology',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
          'default' => '',
        ],
        'gid' => [
          'description' => 'Parent Training Group ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'parent_id' => [
          'description' => 'Step Parent ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => FALSE,
        ],
        'position' => [
          'description' => 'Position under the parent step or the training',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'status' => [
          'description' => 'Step Status',
          'type' => 'varchar',
          'length' => 20,
          'not null' => TRUE,
        ],
        'score' => [
          'description' => 'Step Score',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'time' => [
          'description' => 'Time spent',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'completed' => [
          'description' => 'Date of completion',
          'type' => 'varchar',
          'length' => 20,
          'mysql_type' => 'datetime',
          'not null' => FALSE,
        ],
        'mandatory' => [
          'description' => 'Is Mandatory',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
      ],
      'primary key' => [
        'id',
      ],
      'indexes' => [
        'uid' => [
          'uid',
        ],
        'gid' => [
          'gid',
        ],
      ],
      'foreign keys' => [
        'users' => [
          'uid' => 'uid',
        ],
        'groups' => [
          'gid' => 'id',
        ],
        'opigno_learning_path_step_achievements' => [
          'parent_id' => 'id',
        ],
      ],
    ];
    $schema
      ->createTable($table_name, $table);
  }
}

/**
 * Create new field in learning_path group type.
 */
function opigno_learning_path_update_8008() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';

  // Update configs from install folder.
  $storage = new FileStorage($config_path);
  $data = $storage
    ->read('field.storage.group.field_learning_path_media_image');
  if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
    FieldStorageConfig::create($data)
      ->save();
  }
  $data = $storage
    ->read('field.field.group.learning_path.field_learning_path_media_image');
  if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
    FieldConfig::create($data)
      ->save();
  }
}

/**
 * Update view and media_browser_widget configs.
 */
function opigno_learning_path_update_8009() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/optional';

  /* @var Drupal\Core\Config\CachedStorage $config_storage */
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $configs = [
    'entity_browser.browser.media_entity_browser_groups',
    'views.view.media_browser_images',
  ];
  foreach ($configs as $item) {
    $data = $storage
      ->read($item);
    $config_storage
      ->write($item, $data);
  }
}

/**
 * Creates required trainings field in the learning path group type.
 */
function opigno_learning_path_update_8010() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $data = $storage
    ->read('field.storage.group.field_required_trainings');
  if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
    FieldStorageConfig::create($data)
      ->save();
  }
  $data = $storage
    ->read('field.field.group.learning_path.field_required_trainings');
  if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
    FieldConfig::create($data)
      ->save();
  }

  /* @var Drupal\Core\Config\CachedStorage $config_storage */
  $config_storage = \Drupal::service('config.storage');
  $configs = [
    'core.entity_form_display.group.learning_path.default',
    'core.entity_view_display.group.learning_path.default',
  ];
  foreach ($configs as $item) {
    $data = $storage
      ->read($item);
    $config_storage
      ->write($item, $data);
  }
}

/**
 * Add "learning_path" field to "user_module_status".
 */
function opigno_learning_path_update_8011() {
  $definition = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Learning path'))
    ->setDescription(t('The learning path whose context the module was taken in.'))
    ->setSetting('target_type', 'group')
    ->setSetting('target_bundles', [
    'learning_path' => 'learning_path',
  ]);
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('learning_path', 'user_module_status', 'opigno_learning_path', $definition);
}

/**
 * Add "uid" field to "opigno_latest_group_activity".
 *
 * Update view block "Latest active training".
 */
function opigno_learning_path_update_8012() {

  // Add new field.
  $definition = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Authored by'))
    ->setDescription(t('The user ID of author of the LatestActivity entity.'))
    ->setSetting('target_type', 'user')
    ->setSetting('handler', 'default');
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('uid', 'opigno_latest_group_activity', 'opigno_latest_group_activity', $definition);

  // Update view block.
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('views.view.latest_active_trainings');
  $config_storage
    ->write('views.view.latest_active_trainings', $data);
}

/**
 * Update Media Browser Images views to remove html tags from fields.
 *
 * Update Group Members views to remove html tags from fields.
 *
 * Update translations.
 */
function opigno_learning_path_update_8013() {

  // Update views.
  $display_name = 'default';
  $field_name = 'name';
  $config_factory = \Drupal::configFactory();
  $view = $config_factory
    ->getEditable('views.view.media_browser_images');
  $displays = $view
    ->get('display');
  $alter_option = $displays[$display_name]['display_options']['fields'][$field_name]['alter'];
  $alter_option['alter_text'] = FALSE;
  $alter_option['text'] = '';
  $base = "display.{$display_name}.display_options.fields.{$field_name}";
  $view
    ->set($base . '.alter', $alter_option);
  $view
    ->save(TRUE);
  $display_name = 'default';
  $field_name = 'group_roles';
  $config_factory = \Drupal::configFactory();
  $view = $config_factory
    ->getEditable('views.view.group_members');
  $base = "display.{$display_name}.display_options.fields.{$field_name}";
  $view
    ->set($base . '.empty', t('none'));
  $view
    ->save(TRUE);
  if (!\Drupal::moduleHandler()
    ->moduleExists('locale')) {
    return;
  }

  // Update translations.
  $db_connection = \Drupal::service('database');

  // Get id of translation.
  try {
    $lid = $db_connection
      ->select('locales_source', 'ls')
      ->fields('ls', [
      'lid',
    ])
      ->condition('source', "<div class=\"media-info\">\r\n<span class=\"media-info--{{ bundle }}\">{{ bundle }}</span>\r\n{{ name }}\r\n</div>")
      ->execute()
      ->fetchField();
    if ($lid) {

      // Remove sourse translation.
      $db_connection
        ->delete('locales_source')
        ->condition('lid', $lid)
        ->execute();

      // Remove target translation.
      $db_connection
        ->delete('locales_target')
        ->condition('lid', $lid)
        ->execute();
    }
  } catch (Exception $e) {
    \Drupal::logger('opigno_learning_path')
      ->error($e
      ->getMessage());
  }
  try {
    $lid = $db_connection
      ->select('locales_source', 'ls')
      ->fields('ls', [
      'lid',
    ])
      ->condition('source', '<div class="item-list"><ul><li>&lt;none&gt;</li></ul></div>')
      ->execute()
      ->fetchField();
    if ($lid) {

      // Remove sourse translation.
      $db_connection
        ->delete('locales_source')
        ->condition('lid', $lid)
        ->execute();

      // Remove target translation.
      $db_connection
        ->delete('locales_target')
        ->condition('lid', $lid)
        ->execute();
    }
  } catch (Exception $e) {
    \Drupal::logger('opigno_learning_path')
      ->error($e
      ->getMessage());
  }
}

/**
 * Creates Guided Navigation field in the learning path group type.
 */
function opigno_learning_path_update_8014() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $data = $storage
    ->read('field.storage.group.field_guided_navigation');
  if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
    FieldStorageConfig::create($data)
      ->save();
  }
  $data = $storage
    ->read('field.field.group.learning_path.field_guided_navigation');
  if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
    FieldConfig::create($data)
      ->save();
  }
}

/**
 * Create database table for Learning Path Module Availability entity.
 */
function opigno_learning_path_update_8015() {
  _opigno_learning_path_create_lp_module_availability_table();
}

/**
 * Creates database table.
 */
function _opigno_learning_path_create_lp_module_availability_table() {
  $database = \Drupal::database();
  if (!$database
    ->schema()
    ->tableExists('lp_module_availability')) {
    $entityTypeManager = \Drupal::entityTypeManager();
    $entityTypeManager
      ->clearCachedDefinitions();
    $definition = $entityTypeManager
      ->getDefinition('lp_module_availability');
    \Drupal::entityDefinitionUpdateManager()
      ->installEntityType($definition);
  }
}

/**
 * Add "module_always_available" field to "lp_module_availability" table.
 */
function opigno_learning_path_update_8016() {
}

/**
 * Replace module availability fields.
 */
function opigno_learning_path_update_8017() {
  $entity_type = 'lp_module_availability';
  $fields = [
    'module_always_available',
    'restrict_to_training',
  ];
  $update_manager = Drupal::service('entity.definition_update_manager');
  foreach ($fields as $field) {
    $definition = $update_manager
      ->getFieldStorageDefinition($field, $entity_type);
    if ($definition) {
      $update_manager
        ->uninstallFieldStorageDefinition($definition);
    }
  }
  $options = [
    0 => t('Always available'),
    1 => t('Restrict to specific dates for that training'),
  ];
  $definition = BaseFieldDefinition::create('list_string')
    ->setLabel(t('Module availability'))
    ->setDescription(t('Set module availability for particular training.'))
    ->setSetting('allowed_values', $options)
    ->setDefaultValue(0);
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('availability', 'lp_module_availability', 'lp_module_availability', $definition);
}

/**
 * Remove module global availability fields.
 */
function opigno_learning_path_update_8018() {
  $entity_type = 'opigno_module';
  $fields = [
    'module_always',
    'open_date',
    'close_date',
  ];
  $update_manager = Drupal::service('entity.definition_update_manager');
  foreach ($fields as $field) {
    $definition = $update_manager
      ->getFieldStorageDefinition($field, $entity_type);
    if ($definition) {
      $update_manager
        ->uninstallFieldStorageDefinition($definition);
    }
  }
}

/**
 * Delete deprecated cache context for group-memberships.
 */
function opigno_learning_path_update_8019() {
  $config_factory = \Drupal::configFactory();

  // Update "group_members" view.
  $config = $config_factory
    ->getEditable('views.view.group_members');
  $displays = $config
    ->get('display');
  foreach ($displays as &$display) {
    $contexts =& $display['cache_metadata']['contexts'];
    if (is_array($contexts)) {
      $index = array_search('group_membership.roles.permissions', $contexts);
      if ($index !== FALSE) {

        // Delete deprecated cache context.
        array_splice($contexts, $index, 1);
      }
    }
  }
  $config
    ->set('display', $displays);
  $config
    ->save(TRUE);

  // Update "subgroups" view.
  $config = $config_factory
    ->getEditable('views.view.subgroups');
  $displays = $config
    ->get('display');
  foreach ($displays as &$display) {
    $contexts =& $display['cache_metadata']['contexts'];
    if (is_array($contexts)) {
      $index = array_search('group_membership.roles.permissions', $contexts);
      if ($index !== FALSE) {

        // Delete deprecated cache context.
        array_splice($contexts, $index, 1);
      }
    }
  }
  $config
    ->set('display', $displays);
  $config
    ->save(TRUE);
}

/**
 * Delete invalid records about latest active training's.
 */
function opigno_learning_path_update_8020() {
  $db_connection = \Drupal::service('database');
  try {
    $db_connection
      ->delete('opigno_latest_group_activity')
      ->condition('uid', NULL, 'IS NULL')
      ->execute();
  } catch (Exception $e) {
    \Drupal::logger('opigno_learning_path')
      ->error($e
      ->getMessage());
  }
}

/**
 * Reload Learning Path Media Entity Browser config to fix translations.
 */
function opigno_learning_path_update_8021() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/optional';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('entity_browser.browser.media_entity_browser_groups');
  $config_storage
    ->write('entity_browser.browser.media_entity_browser_groups', $data);
}

/**
 * Create Group Members Table view.
 */
function opigno_learning_path_update_8022() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $configs = [
    'views.view.opigno_group_members_table',
  ];
  foreach ($configs as $item) {
    $data = $storage
      ->read($item);
    $config_storage
      ->write($item, $data);
  }
}

/**
 * Update Group Members Table view.
 */
function opigno_learning_path_update_8023() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $configs = [
    'views.view.opigno_group_members_table',
  ];
  foreach ($configs as $item) {
    $data = $storage
      ->read($item);
    $config_storage
      ->write($item, $data);
  }
}

/**
 * Creates databases table for User Learning Path Status.
 */
function opigno_learning_path_update_8025() {
  _opigno_learning_path_create_user_lp_status_table();
  _opigno_learning_path_create_user_lp_status_expire_table();
}

/**
 * Creates User Learning Path Status database table.
 */
function _opigno_learning_path_create_user_lp_status_table() {
  $database = \Drupal::database();
  if (!$database
    ->schema()
    ->tableExists('user_lp_status')) {
    $entityTypeManager = \Drupal::entityTypeManager();
    $entityTypeManager
      ->clearCachedDefinitions();
    $definition = $entityTypeManager
      ->getDefinition('user_lp_status');
    \Drupal::entityDefinitionUpdateManager()
      ->installEntityType($definition);
  }
}

/**
 * Creates User Learning Path Status expire database table.
 */
function _opigno_learning_path_create_user_lp_status_expire_table() {
  $schema = \Drupal::database()
    ->schema();
  $table_name = 'user_lp_status_expire';
  if (!$schema
    ->tableExists($table_name)) {
    $table = [
      'description' => 'User Learning Path Status expire',
      'fields' => [
        'id' => [
          'type' => 'serial',
          'not null' => TRUE,
        ],
        'uid' => [
          'description' => 'User ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'gid' => [
          'description' => 'Training ID',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'latest_cert_date' => [
          'description' => 'Latest re-certification timestamp',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'expire' => [
          'description' => 'Expire timestamp',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ],
        'notified' => [
          'description' => 'If user was notified',
          'type' => 'int',
          'size' => 'tiny',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ],
      ],
      'primary key' => [
        'id',
      ],
      'indexes' => [
        'uid' => [
          'uid',
        ],
        'gid' => [
          'gid',
        ],
        'latest_cert_date' => [
          'latest_cert_date',
        ],
        'expire' => [
          'expire',
        ],
      ],
    ];
    $schema
      ->createTable($table_name, $table);
  }
}

/**
 * Add training certificate expire fields.
 */
function opigno_learning_path_update_8026() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $data = $storage
    ->read('field.storage.group.field_certificate_expire');
  if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
    FieldStorageConfig::create($data)
      ->save();
  }
  $data = $storage
    ->read('field.field.group.learning_path.field_certificate_expire');
  if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
    FieldConfig::create($data)
      ->save();
  }
  $module_handler = \Drupal::moduleHandler();
  $config_storage = new FileStorage($module_handler
    ->getModule('opigno_learning_path')
    ->getPath() . '/config/install');
  foreach ([
    'field.storage.group.field_certificate_expire_results',
    'field.field.group.learning_path.field_certificate_expire_results',
  ] as $config_name) {
    $config_record = $config_storage
      ->read($config_name);
    $entity_type = \Drupal::service('config.manager')
      ->getEntityTypeIdByName($config_name);

    /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
    $storage = \Drupal::entityTypeManager()
      ->getStorage($entity_type);
    $entity = $storage
      ->createFromStorageRecord($config_record);
    $entity
      ->save();
  }
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $configs = [
    'core.entity_form_display.group.learning_path.default',
    'core.entity_view_display.group.learning_path.default',
  ];
  foreach ($configs as $item) {
    $data = $storage
      ->read($item);
    $config_storage
      ->write($item, $data);
  }
}

/**
 * Hide block title.
 */
function opigno_learning_path_update_8027() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/optional';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('block.block.opigno_training_catalog_filter');
  $config_storage
    ->write('block.block.opigno_training_catalog_filter', $data);
}

/**
 * Add user "notified" field to the learning path status expired table.
 */
function opigno_learning_path_update_8028() {
  $table = 'user_lp_status_expire';
  $field = 'notified';
  $connection = Database::getConnection();
  $schema = $connection
    ->schema();
  if ($schema
    ->tableExists($table) && !$schema
    ->fieldExists($table, $field)) {
    $spec = [
      'description' => 'If user was notified',
      'type' => 'int',
      'size' => 'tiny',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ];
    $schema
      ->addField($table, $field, $spec);
  }
}

/**
 * Update certificate expire period labels.
 */
function opigno_learning_path_update_8029() {
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('field.storage.group.field_certificate_expire_results');
  $config_storage
    ->write('field.storage.group.field_certificate_expire_results', $data);
}

/**
 * Implements hook_update_N().
 *
 * Change image style for display default.
 */
function opigno_learning_path_update_8030() {

  // Install configs from optional folder.
  $config_optional_path = drupal_get_path('module', 'opigno_learning_path') . '/config/optional';
  $storage = new FileStorage($config_optional_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('core.entity_view_display.group.learning_path.default');
  $config_storage
    ->write('core.entity_view_display.group.learning_path.default', $data);
}

/**
 * Creates create cronjobs.
 */
function opigno_learning_path_update_8031() {

  // Enable ultimate_cron.
  if (!\Drupal::moduleHandler()
    ->moduleExists('ultimate_cron')) {
    \Drupal::service('module_installer')
      ->install([
      'ultimate_cron',
    ]);
  }

  // Enable new module opigno_cron.
  if (!\Drupal::moduleHandler()
    ->moduleExists('opigno_cron')) {
    \Drupal::service('module_installer')
      ->install([
      'opigno_cron',
    ]);
  }

  // Add new cron configuretions.
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('ultimate_cron.job.opigno_learning_path_cron');
  $config_storage
    ->write('ultimate_cron.job.opigno_learning_path_cron', $data);
}

/**
 * Add alternative text to training catalog.
 */
function opigno_learning_path_update_8032() {

  // Add new cron configuretions.
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('views.view.opigno_training_catalog');
  $config_storage
    ->write('views.view.opigno_training_catalog', $data);
}

/**
 * Add access to contectual links.
 */
function opigno_learning_path_update_8033() {

  // Grand users for access to contextual links.
  $permission = 'access contextual links';
  $role = Role::load('content_manager');
  if ($role) {
    $role
      ->grantPermission($permission);
    $role
      ->save();
  }
  $role = Role::load('user_manager');
  if ($role) {
    $role
      ->grantPermission($permission);
    $role
      ->save();
  }
  $permission = 'bypass group access';
  $role = Role::load('content_manager');
  if ($role) {
    $role
      ->grantPermission($permission);
    $role
      ->save();
  }
}

/**
 * Add access to dropzone upload files.
 */
function opigno_learning_path_update_8034() {

  // Grand users for access to contextual links.
  $permission = 'dropzone upload files';
  $role = Role::load('content_manager');
  if ($role) {
    $role
      ->revokePermission($permission);
    $role
      ->save();
  }
  $role = Role::load('user_manager');
  if ($role) {
    $role
      ->revokePermission($permission);
    $role
      ->save();
  }
  $role = Role::load('authenticated');
  if ($role) {
    $role
      ->grantPermission($permission);
    $role
      ->save();
  }
}

/**
 * Add alternative text to training catalog.
 */
function opigno_learning_path_update_8035() {

  // Add new cron configuretions.
  $config_path = drupal_get_path('module', 'opigno_learning_path') . '/config/install';
  $storage = new FileStorage($config_path);
  $config_storage = \Drupal::service('config.storage');
  $data = $storage
    ->read('group.role.learning_path-member');
  $config_storage
    ->write('group.role.learning_path-member', $data);
}

Functions

Namesort descending Description
opigno_learning_path_install Creates database table for Learning Path group user statuses.
opigno_learning_path_update_8002 Creates database table for Learning Path group user statuses.
opigno_learning_path_update_8004 Creates database table for Latest Activity entity type.
opigno_learning_path_update_8005 Creates forum field in the learning path group type.
opigno_learning_path_update_8006 Creates enable forum field in the learning path group type.
opigno_learning_path_update_8007 Creates achievements tables.
opigno_learning_path_update_8008 Create new field in learning_path group type.
opigno_learning_path_update_8009 Update view and media_browser_widget configs.
opigno_learning_path_update_8010 Creates required trainings field in the learning path group type.
opigno_learning_path_update_8011 Add "learning_path" field to "user_module_status".
opigno_learning_path_update_8012 Add "uid" field to "opigno_latest_group_activity".
opigno_learning_path_update_8013 Update Media Browser Images views to remove html tags from fields.
opigno_learning_path_update_8014 Creates Guided Navigation field in the learning path group type.
opigno_learning_path_update_8015 Create database table for Learning Path Module Availability entity.
opigno_learning_path_update_8016 Add "module_always_available" field to "lp_module_availability" table.
opigno_learning_path_update_8017 Replace module availability fields.
opigno_learning_path_update_8018 Remove module global availability fields.
opigno_learning_path_update_8019 Delete deprecated cache context for group-memberships.
opigno_learning_path_update_8020 Delete invalid records about latest active training's.
opigno_learning_path_update_8021 Reload Learning Path Media Entity Browser config to fix translations.
opigno_learning_path_update_8022 Create Group Members Table view.
opigno_learning_path_update_8023 Update Group Members Table view.
opigno_learning_path_update_8025 Creates databases table for User Learning Path Status.
opigno_learning_path_update_8026 Add training certificate expire fields.
opigno_learning_path_update_8027 Hide block title.
opigno_learning_path_update_8028 Add user "notified" field to the learning path status expired table.
opigno_learning_path_update_8029 Update certificate expire period labels.
opigno_learning_path_update_8030 Implements hook_update_N().
opigno_learning_path_update_8031 Creates create cronjobs.
opigno_learning_path_update_8032 Add alternative text to training catalog.
opigno_learning_path_update_8033 Add access to contectual links.
opigno_learning_path_update_8034 Add access to dropzone upload files.
opigno_learning_path_update_8035 Add alternative text to training catalog.
_opigno_learning_path_create_achievements_table Creates achievements table.
_opigno_learning_path_create_lp_module_availability_table Creates database table.
_opigno_learning_path_create_step_achievements_table Creates achievements table.
_opigno_learning_path_create_user_lp_status_expire_table Creates User Learning Path Status expire database table.
_opigno_learning_path_create_user_lp_status_table Creates User Learning Path Status database table.