You are here

function opigno_lms_update_7112 in Opigno LMS 7

Change the modules used for discussing with the LRS (learning locker -> opigno tincan api)

File

./opigno_lms.install, line 843
Install, update and uninstall functions for the Opigno LMS installation profile.

Code

function opigno_lms_update_7112(&$sandbox) {

  // Installs latest H5P Libraries
  if (module_exists("h5p")) {
    drupal_flush_all_caches();
    $path = file_get_contents(drupal_get_path("profile", "opigno_lms") . "/h5plib/libraries.h5p");
    $temporary_file_path = 'public://' . variable_get('h5p_default_path', 'h5p') . '/temp/' . uniqid('h5p-');
    $prepare = file_prepare_directory($temporary_file_path, FILE_CREATE_DIRECTORY);
    $temporary_file_name = $temporary_file_path . "/libraries.h5p";
    $file = file_save_data($path, $temporary_file_name, FILE_EXISTS_REPLACE);
    $_SESSION['h5p_upload'] = drupal_realpath($file->uri);
    $_SESSION['h5p_upload_folder'] = drupal_realpath($temporary_file_path);
    $validator = _h5p_get_instance('validator');
    $isvalid = $validator
      ->isValidPackage(TRUE, FALSE);
    $h5p_core = _h5p_get_instance('storage');
    $save_package = $h5p_core
      ->savePackage(NULL, NULL, TRUE);
    unset($_SESSION['h5p_upload'], $_SESSION['h5p_upload_folder']);
  }

  /////////////////////////////////////////////////////////////////////

  // Update the modules that are about the LRS
  $modules_to_enable = array();
  $modules_to_disable = array();
  if (module_exists('opigno_learning_locker_stats_app_in_house_training')) {
    $modules_to_disable[] = 'opigno_learning_locker_stats_app_in_house_training';
    $modules_to_enable[] = 'opigno_tincan_api_in_house_training_statements';
  }
  if (module_exists('opigno_learning_locker_stats_app_openbadges')) {
    $modules_to_disable[] = 'opigno_learning_locker_stats_app_openbadges';
    $modules_to_enable[] = 'opigno_tincan_api_openbadges_statements';
  }
  if (module_exists('opigno_learning_locker_stats_app')) {
    $modules_to_disable[] = 'opigno_learning_locker_stats_app';
    $modules_to_enable[] = 'opigno_tincan_api_stats';
    $modules_to_enable[] = 'opigno_tincan_api_opigno_statements';
  }
  if (module_exists('tincanapi_quiz')) {

    // Verify the dependencies before disabling
    if (_opigno_lms_install_module_has_dependent('tincanapi_quiz', $modules_to_disable) === false) {
      $modules_to_disable[] = 'tincanapi_quiz';
    }
    $modules_to_enable[] = 'opigno_tincan_api_quizfileupload_statements';
    $modules_to_enable[] = 'opigno_tincan_api_quiz_drag_drop_statements';
    $modules_to_enable[] = 'opigno_tincan_api_opigno_scorm_statements';
    $modules_to_enable[] = 'opigno_tincan_api_cloze_statements';
    $modules_to_enable[] = 'opigno_tincan_api_quiz_statements';
  }
  if (module_exists('tincanapi_content_types')) {
    if (_opigno_lms_install_module_has_dependent('tincanapi_content_types', $modules_to_disable)) {
      $modules_to_disable[] = 'tincanapi_content_types';
    }
    $modules_to_enable[] = 'opigno_tincan_api_node_views_statements';
  }
  if (module_exists('h5p_tincan_bridge')) {

    // Verify the dependencies before disabling
    if (_opigno_lms_install_module_has_dependent('h5p_tincan_bridge', $modules_to_disable)) {
      $modules_to_disable[] = 'h5p_tincan_bridge';
    }
    $modules_to_enable[] = 'opigno_tincan_api_h5p_statements';
  }
  if (module_exists('tincanapi')) {

    // Verify the dependencies before disabling
    if (_opigno_lms_install_module_has_dependent('tincanapi', $modules_to_disable)) {
      $modules_to_disable[] = 'tincanapi';
    }
  }
  $modules_to_enable[] = 'opigno_tincan_api';
  module_disable($modules_to_disable);
  module_enable(array_reverse($modules_to_enable));
  opigno_lms_refresh_strings_and_import(array(
    'field',
  ));
  drupal_flush_all_caches();
}