1
0
Prechádzať zdrojové kódy

Update 'db/upgrade.php'

Version: 1.5.3 2021/10/10
+ Fixed several string concatenation from '+' to '.'
+ Since now is allowed null file associated to "test" activity, fixed UPDATE do "filesid=file" with try/catch and 'WHERE file IS NOT NULL"'
leo 3 rokov pred
rodič
commit
671301a526
1 zmenil súbory, kde vykonal 27 pridanie a 18 odobranie
  1. 27 18
      db/upgrade.php

+ 27 - 18
db/upgrade.php

@@ -13,9 +13,13 @@
  * will tell you what you need to do.
  * The commands in here will all be database-neutral,
  * using the functions defined in lib/ddllib.php
- * 
+ *
+ * - v 1.5.3 2021/10/10
+ *     + Fixed several string concatenation from '+' to '.'
+ *     + Since now is allowed null file associated to "test" activity,
+ *       fixed UPDATE do "filesid=file" with try/catch and 'WHERE file IS NOT NULL"'
  * - v 1.5.2 2020/08/03
- *     + Fixed 'ALTER TABLE' of 'iassign_submission.grade' from BIGINT(11) to REAL 
+ *     + Fixed 'ALTER TABLE' of 'iassign_submission.grade' from BIGINT(11) to REAL
  *     + New version of iHanoi 1.0.20200803
  * - v 1.5.1 2020/05/28-30
  *     + Avoid to update one iLM causing colision with other instance of the same iLM
@@ -104,7 +108,7 @@ function xmldb_iassign_upgrade ($oldversion) {
           if ($iassign->name == $record['name'] && strtolower($iassign->type) == $record_type) {
             if ($iassign->version == $record['version']) { // or with the one with the same version
               $exists = 1; // iLM found - exit with the last one, same version
-              $strNot_installed += "\n" + '  <li>' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + ' </li>' + "\n";
+              $strNot_installed .= "\n" . '  <li>' . $record['name'] . ';' . $record['type'] . ';' . $record['version'] . ' </li>' . "\n";
               break;
               }
             }
@@ -117,12 +121,12 @@ function xmldb_iassign_upgrade ($oldversion) {
         }
       } // foreach ($records as $record)
     if ($strNot_installed != '') { // ATTENTION: this implies that Moodle administrator updated this iLM, please verify if it is really the current one.
-      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
+      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' . "\n";
       print get_string('upgrade_alert_exists', 'iassign'); // iLM previouly existent
-      print ' <ul style="margin-top: 1rem;">' + "\n";
+      print ' <ul style="margin-top: 1rem;">' . "\n";
       print $strNot_installed;
-      print ' </ul>' + "\n";
-      print '</div>' + "\n";
+      print ' </ul>' . "\n";
+      print '</div>' . "\n";
       }
 
     // Verify if each iLM previously installed is present in fresh new iAssign. This does not means problem, perhaps the admin installed a particular iLM.
@@ -148,14 +152,14 @@ function xmldb_iassign_upgrade ($oldversion) {
       } // if ($iassign_ilm)
 
     if ($strNot_found != '') {
-      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
+      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' . "\n";
       print get_string('upgrade_alert_iMA_msg', 'iassign'); // Updated but some previous iLM installed are not available in fresh iAssign
-      print '<ul style="margin-top: 1rem;">' + "\n";
+      print '<ul style="margin-top: 1rem;">' . "\n";
       print $strNot_found;
-      print '</ul>' + "\n";
+      print '</ul>' . "\n";
       print get_string('upgrade_alert_iMA_solution_pt1', 'iassign');
       print '<a href="'.new moodle_url('/admin/settings.php?section=modsettingiassign').'">' . get_string('upgrade_alert_iMA_solution_pt2', 'iassign') . '</a>.' . "\n";
-      print '</div>' + "\n";
+      print '</div>' . "\n";
       }
 
     } // if ($oldversion < 2020070613)
@@ -243,7 +247,7 @@ function xmldb_iassign_upgrade ($oldversion) {
               $last_id = $iassign->id; // last ID => last version (hopefully)
             if ($iassign->version == $record['version']) { // or with the one with the same version
               $exists = 1; // iLM found - exit with the last one, same version
-              $strNot_installed += "\n" + '  <li>' + $record['name'] + ';' + $record['type'] + ';' + $record['version'] + ' </li>' + "\n";
+              $strNot_installed .= "\n" . '  <li>' . $record['name'] . ';' . $record['type'] . ';' . $record['version'] . ' </li>' . "\n";
               break;
               }
             }
@@ -256,12 +260,12 @@ function xmldb_iassign_upgrade ($oldversion) {
       } // foreach ($records as $record)
 
     if ($strNot_installed != '') {
-      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' + "\n";
+      print '<div class="alert alert-warning alert-block fade in " role="alert" data-aria-autofocus="true" tabindex="0" >' . "\n";
       print get_string('upgrade_alert_exists', 'iassign'); // iLM previouly existent
-      print ' <ul style="margin-top: 1rem;">' + "\n";
+      print ' <ul style="margin-top: 1rem;">' . "\n";
       print $strNot_installed;
-      print ' </ul>' + "\n";
-      print '</div>' + "\n";
+      print ' </ul>' . "\n";
+      print '</div>' . "\n";
       }
 
     // iassign_ilm: atualizou iHanoi existente, mas nao era isso! Deveria ter inserido novo!
@@ -291,13 +295,17 @@ function xmldb_iassign_upgrade ($oldversion) {
     $table = new xmldb_table('iassign_statement');
 
     $field_filesid = new xmldb_field('filesid', XMLDB_TYPE_CHAR, '255', null, null, null, null, null);
+    // field_filesid=xmldb_field Object ( [type:protected] => 4 [length:protected] => 255 [notnull:protected] => [default:protected] => [sequence:protected] => [decimals:protected] => [name:protected] => 
+    // filesid [comment:protected] => [previous:protected] => [next:protected] => [hash:protected] => [loaded:protected] => [changed:protected] => [errormsg:protected] => [precision] => 4 ) 	  
 
     if (!$dbman->field_exists($table, $field_filesid))
       $dbman->add_field($table, $field_filesid);
     
     // Updating all registers from iassing_statement.filesid
-    $DB->execute("UPDATE {iassign_statement} SET filesid = file");
-
+    try {
+      //2021/10/10: $DB->execute("UPDATE {iassign_statement} SET filesid = file");
+      $DB->execute("UPDATE {iassign_statement} SET filesid = file WHERE file IS NOT NULL"); //2021/10/10: 
+    } catch (Exception $ex) { } // avoid error with 'text' activity (activity with no file!)
 
     // 1. encontrar os contextos dos arquivos do itarefa:
     $iassign_contexts_list = $DB->get_records_sql("SELECT DISTINCT contextid FROM {files} f WHERE component='mod_iassign'");
@@ -346,6 +354,7 @@ function xmldb_iassign_upgrade ($oldversion) {
           } // if ($files)
         } // foreach ($contexts as $context)
       } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
+
     } // if ($oldversion < 2020120500)
 
   /// @Igor - adicionar a tabela iassign_allsubmissions