Example #1
0
 /**
  * Called post install and after every upgrade to the artefact.
  * @param string $prevversion the previously installed version of this artefact.
  */
 public static function postinst($prevversion)
 {
     if ($prevversion == 0) {
         // Since this is the first time, we need to
         // create the default settings and the static
         // table data for aretfact_annotation_deletedby.
         set_config_plugin('artefact', 'annotation', 'commenteditabletime', 10);
         foreach (ArtefactTypeAnnotationfeedback::deleted_by_types() as $index => $type) {
             insert_record('artefact_annotation_deletedby', (object) array('id' => (int) $index + 1, 'name' => $type));
         }
         // If elasticsearch is installed, update the artefacttypesmap field to include
         // annotation and annotationfeedback.
         $sql = "SELECT value FROM {search_config} WHERE plugin='elasticsearch' AND field='artefacttypesmap'";
         if ($result = get_field_sql($sql, array())) {
             $elasticsearchartefacttypesmap = explode("\n", $result);
             // add annotation and annotationfeedback fields.
             $elasticsearchartefacttypesmap[] = "annotation|Annotation|Text";
             $elasticsearchartefacttypesmap[] = "annotationfeedback|Annotation|Text";
             // Now save the data including the new annotation fields.
             set_config_plugin('search', 'elasticsearch', 'artefacttypesmap', implode("\n", $elasticsearchartefacttypesmap));
         }
         // Now install the blocktype annotation only if Mahara was previously installed.
         // Otherwise, the Mahara installer will install everything.
         if (get_config('installed')) {
             if ($upgrade = check_upgrades('blocktype.annotation/annotation')) {
                 upgrade_plugin($upgrade);
             }
         }
     }
 }