<?php

/**
 * This file keeps track of upgrades to the nasatlx module
 *
 * Sometimes, changes between versions involve alterations to database
 * structures and other major things that may break installations. The upgrade
 * function in this file will attempt to perform all the necessary actions to
 * upgrade your older installation to the current version. If there's something
 * it cannot do itself, it will tell you what you need to do.  The commands in
 * here will all be database-neutral, using the functions defined in DLL libraries.
 *
 * @package    mod_nasatlx
 * @copyright  2014 LInE - http://line.ime.usp.br
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') || die();

/**
 * Execute nasatlx upgrade from the given old version
 *
 * @param int $oldversion
 * @return bool
 */

function xmldb_nasatlx_upgrade ($oldversion) {
  global $DB;

  $dbman = $DB->get_manager(); // loads ddl manager and xmldb classes

  //D echo "./mod/nasatlx/db/upgrade.php: entrou xmldb_nasatlx_upgrade, oldversion=$oldversion<br/>";

  //D General form to update after new version
  // if ($oldversion < YYYYMMDD00) { //New version in version.php
  //   }

  // add_to_log() has been deprecated, please rewrite your code to the new events API
  // line 50 of /lib/deprecatedlib.php: call to debugging()
  // line 45 of /mod/nasatlx/view.php: call to add_to_log()

  // The initial version of NASA-TLX does not defined capabilities, fix it with 'access.php'!
  if ($oldversion < 2019030100) {

    // get_records_sql
    // get_recordset_sql
    //DEBUG To test NASA-TLX capabilities in table '*_capabilities': id name captype contextlevel component riskbitmask
    //D $list_nasalti_capabilities = $DB->get_records_sql("SELECT * FROM {capabilities} WHERE component='mod_nasatlx';");
    //D $num_cap = sizeof($list_nasalti_capabilities);
    //D echo "./mod/nasatlx/db/upgrade.php: #list_nasalti_capabilities=" . sizeof($list_nasalti_capabilities) . "<br/>";
    //D print_r($list_nasalti_capabilities); echo "<br/>";

    //D exit; // foreach ();

    //D if ($num_cap == 0) {
    //D   $newentry = new stdClass();

    // Final return of upgrade result (true, all went good) to Moodle.
    return true;
    } // if ($oldversion < 2019030400)

  //D echo "./mod/nasatlx/db/upgrade.php: fim 'xmldb_nasatlx_upgrade(...)'<br/>";
  } // function xmldb_nasatlx_upgrade($oldversion)

// First this script is loaded, after it the 'xmldb_nasatlx_upgrade($oldversion)' is executed

//D echo "./mod/nasatlx/db/upgrade.php: fim<br/>";