You are here

function opigno_lms_update_7109 in Opigno LMS 7

Install the updated h5p libraries

File

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

Code

function opigno_lms_update_7109(&$sandbox) {

  // Installs latest H5P Libraries
  if (module_exists("h5p")) {
    $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']);
  }

  /////////////////////////////////////////////////////////////////////
  variable_set('site_404', 'r4032login');
  $settings = variable_get('theme_platon_settings');
  if (!empty($settings['platon_home_page_markup'])) {
    $value = $settings['platon_home_page_markup']['value'];
    $format = $settings['platon_home_page_markup']['format'];
  }
  $background = $settings['platon_home_page_image_path'];

  // default datas for new homepage slide
  $path = drupal_get_path('theme', 'platon');
  $default_theme_settings = variable_get('theme_platon_settings', array());
  $default_theme_settings[1]['platon_home_page_markup'] = array(
    'format' => isset($format) ? $format : 'html',
    'value' => isset($value) ? $value : st("<h1>Welcome to your new Opigno platform</h1><p>You may change this front page by logging in and going to <a href='?q=user&amp;destination=admin/appearance/settings/platon'>Administration &gt; Appearance &gt; Manage site display</a>.</p>"),
    'background' => !empty($background) ? $background : '../../../profiles/opigno_lms/themes/platon/img/homepage-background-1.jpg',
  );
  $default_theme_settings[2]['platon_home_page_markup'] = array(
    'format' => 'html',
    'value' => st("<h1>Welcome to your new Opigno platform</h1><p>You may change this front page by logging in and going to <a href='?q=user&amp;destination=admin/appearance/settings/platon'>Administration &gt; Appearance &gt; Manage site display</a>.</p>"),
    'background' => '../../../profiles/opigno_lms/themes/platon/img/homepage-background-2.jpg',
  );
  $default_theme_settings[3]['platon_home_page_markup'] = array(
    'format' => 'html',
    'value' => st("<h1>Welcome to your new Opigno platform</h1><p>You may change this front page by logging in and going to <a href='?q=user&amp;destination=admin/appearance/settings/platon'>Administration &gt; Appearance &gt; Manage site display</a>.</p>"),
    'background' => '../../../profiles/opigno_lms/themes/platon/img/homepage-background-3.jpg',
  );
  variable_set('theme_platon_settings', $default_theme_settings);

  // move login block
  $default_theme = variable_get('theme_default', 'platon');
  db_update('block')
    ->fields(array(
    'region' => 'header_login',
  ))
    ->condition('module', 'user', '=')
    ->condition('delta', 'login', '=')
    ->condition('theme', $default_theme)
    ->execute();

  ////////////////////////////
  opigno_lms_refresh_strings_and_import(array(
    'field',
  ));
  drupal_flush_all_caches();
}