public function to_XML() { $xml = new DOMDocument('1.0', "UTF-8"); $element = $xml->createElement("TestSection"); $xml->appendChild($element); $counter = $xml->createElement("counter", htmlspecialchars($this->counter, ENT_QUOTES, "UTF-8")); $element->appendChild($counter); $parent = $xml->createElement("parent_counter", htmlspecialchars($this->parent_counter, ENT_QUOTES, "UTF-8")); $element->appendChild($parent); $tstid = $xml->createElement("TestSectionType_id", htmlspecialchars($this->TestSectionType_id, ENT_QUOTES, "UTF-8")); $element->appendChild($tstid); $end = $xml->createElement("end", htmlspecialchars($this->end, ENT_QUOTES, "UTF-8")); $element->appendChild($end); $tsv = $xml->createElement("TestSectionValues"); $element->appendChild($tsv); $sv = TestSectionValue::from_property(array("TestSection_id" => $this->id)); foreach ($sv as $v) { $elem = $v->to_XML(); $elem = $xml->importNode($elem, true); $tsv->appendChild($elem); } return $element; }
public static function update_db($simulate = false, $only_recalculate_hash = false, $only_repopulate_TestTemplate = false, $only_validate_column_names = false, $only_create_db = false) { require '../Ini.php'; $ini = new Ini(); if ($only_create_db) { return self::create_db_structure(); } if ($only_recalculate_hash) { OModule::calculate_all_xml_hashes(); return json_encode(array("result" => 0)); } if ($only_repopulate_TestTemplate) { TestTemplate::repopulate_table(); return json_encode(array("result" => 0)); } if ($only_validate_column_names) { $result = TableColumn::validate_columns_name(); return json_encode(array("result" => $result ? 0 : 1)); } $versions_to_update = array(); $previous_version = Setting::get_setting("version"); if ($previous_version == null) { $previous_version = Ini::$version; } $recalculate_hash = false; $repopulate_TestTemplate = false; $validate_column_names = false; if (Ini::does_patch_apply("3.3.0", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.3.0"); } else { ///COMPATIBILITY FIX FOR V3.0.0 START $sql = "SHOW COLUMNS FROM `User` WHERE `Field`='last_activity'"; $z = mysql_query($sql); if (mysql_num_rows($z) > 0) { $sql = "ALTER TABLE `User` CHANGE `last_activity` `last_login` timestamp NOT NULL default '0000-00-00 00:00:00';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //DS_TableColumnType - numeric split to integer and float $id_4_found = false; $sql = "SELECT * FROM `DS_TableColumnType`"; $z = mysql_query($sql); while ($r = mysql_fetch_array($z)) { switch ($r['id']) { case 2: if ($r['name'] != "integer") { $sql2 = "UPDATE `DS_TableColumnType` SET `name`='integer', value='integer' WHERE `id`=2"; if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } } break; case 3: if ($r['name'] != "float") { $sql2 = "UPDATE `DS_TableColumnType` SET `name`='float', value='float' WHERE `id`=3"; if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } } break; case 4: $id_4_found = true; if ($r['name'] != "HTML") { $sql2 = "UPDATE `DS_TableColumnType` SET `name`='HTML', value='HTML' WHERE `id`=4"; if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } } break; } } if (!$id_4_found) { $sql2 = "INSERT INTO `DS_TableColumnType` SET `id`=4, `name`='HTML', value='HTML', `position`=4"; if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } } //TableColumn - change numeric and float MySQL type $sql = sprintf("SELECT * FROM `TableColumn`"); $z = mysql_query($sql); while ($r = mysql_fetch_array($z)) { $table = Table::from_mysql_id($r['Table_id']); if ($table == null) { continue; } if (!$table->has_table()) { $table->mysql_delete(); continue; } $table_name = $table->get_table_name(); $type = "TEXT NOT NULL"; switch ($r['TableColumnType_id']) { case 2: $type = "BIGINT NOT NULL"; break; case 3: $type = "DOUBLE NOT NULL"; break; } $old_name = $r['name']; $new_name = Table::format_column_name($old_name); if ($r['TableColumnType_id'] == 3) { $sql2 = sprintf("UPDATE `TableColumn` SET `TableColumnType_id`='%d' WHERE `id`='%d'", 4, $r['id']); if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } } if ($old_name != $new_name) { $sql2 = sprintf("ALTER TABLE `%s` CHANGE `%s` `%s` %s;", $table_name, $old_name, $new_name, $type); $i = 1; while (!mysql_query($sql2)) { $new_name = "col" . $i; $sql2 = sprintf("ALTER TABLE `%s` CHANGE `%s` `%s` %s;", $table_name, $old_name, $new_name, $type); $i++; } $sql2 = sprintf("UPDATE `TableColumn` SET `name`='%s' WHERE `id`='%d'", $new_name, $r['id']); if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } } } Setting::set_setting("version", "3.3.0"); return json_encode(array("result" => 0, "param" => "3.3.0")); } } if (Ini::does_patch_apply("3.4.0", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.4.0"); } else { //Test - add session_count field $sql = "SHOW COLUMNS FROM `Test` WHERE `Field`='session_count'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Test` ADD `session_count` bigint(20) NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSectionValue - indexes changes $sql = sprintf("SELECT `TestSection`.`id`, `TestSection`.`TestSectionType_id` FROM `TestSection` WHERE `TestSectionType_id` IN (%d,%d,%d)", DS_TestSectionType::LOAD_HTML_TEMPLATE, DS_TestSectionType::SET_VARIABLE, DS_TestSectionType::CUSTOM); $z = mysql_query($sql); while ($r = mysql_fetch_array($z)) { set_time_limit(0); switch ($r[1]) { case DS_TestSectionType::LOAD_HTML_TEMPLATE: $params_count = 0; $returns_count = 0; $sql2 = sprintf("SELECT `index`,`value` FROM `%s` WHERE `TestSection_id`=%d AND (`index`=1 OR `index`=2) ", TestSectionValue::get_mysql_table(), $r[0]); $z2 = mysql_query($sql2); while ($r2 = mysql_fetch_array($z2)) { if ($r2['index'] == 1) { $params_count = $r2['value']; } if ($r2['index'] == 2) { $returns_count = $r2['value']; } } $delete_index = 3 + $params_count + 1; for ($i = 0; $i < $returns_count; $i++) { $sql2 = sprintf("DELETE FROM `%s` WHERE `TestSection_id`=%d AND `index` IN (%d,%d)", TestSectionValue::get_mysql_table(), $r[0], $delete_index, $delete_index + 1); if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } $sql2 = sprintf("UPDATE `%s` SET `index`=`index`-2 WHERE `TestSection_id`=%d AND `index`>%d", TestSectionValue::get_mysql_table(), $r[0], $delete_index); if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } $delete_index++; } break; case DS_TestSectionType::SET_VARIABLE: $sql2 = sprintf("DELETE FROM `%s` WHERE `TestSection_id`=%d AND `index` IN (4,5)", TestSectionValue::get_mysql_table(), $r[0]); if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } $sql2 = sprintf("UPDATE `%s` SET `index`=`index`-2 WHERE `TestSection_id`=%d AND `index`>%d", TestSectionValue::get_mysql_table(), $r[0], 5); if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } break; case DS_TestSectionType::CUSTOM: $params_count = 0; $returns_count = 0; $csid = 0; $sql2 = sprintf("SELECT `value` FROM `%s` WHERE `TestSection_id`=%d AND `index`=0 ", TestSectionValue::get_mysql_table(), $r[0]); $z2 = mysql_query($sql2); $r2 = mysql_fetch_array($z2); $csid = $r2['value']; $sql2 = sprintf("SELECT * FROM `%s` WHERE `CustomSection_id`=%d AND `type`=0", CustomSectionVariable::get_mysql_table(), $csid); $params_count = mysql_num_rows(mysql_query($sql2)); $sql2 = sprintf("SELECT * FROM `%s` WHERE `CustomSection_id`=%d AND `type`=1", CustomSectionVariable::get_mysql_table(), $csid); $returns_count = mysql_num_rows(mysql_query($sql2)); $delete_index = 1 + $params_count + 1; for ($i = 0; $i < $returns_count; $i++) { $sql2 = sprintf("DELETE FROM `%s` WHERE `TestSection_id`=%d AND `index` IN (%d,%d)", TestSectionValue::get_mysql_table(), $r[0], $delete_index, $delete_index + 1); if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } $sql2 = sprintf("UPDATE `%s` SET `index`=`index`-2 WHERE `TestSection_id`=%d AND `index`>%d", TestSectionValue::get_mysql_table(), $r[0], $delete_index); if (!mysql_query($sql2)) { return json_encode(array("result" => 1, "param" => $sql2)); } $delete_index++; } break; } } //TestSession - added new fields $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='status'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `status` tinyint(4) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='time_limit'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `time_limit` int(11) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='HTML'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `HTML` text NOT NULL default '';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='Template_id'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `Template_id` bigint(20) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='time_tamper_prevention'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `time_tamper_prevention` INT NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='hash'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `hash` text NOT NULL default '';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='r_type'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `r_type` TINYINT( 1 ) NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.4.0"); return json_encode(array("result" => 0, "param" => "3.4.0")); } } if (Ini::does_patch_apply("3.4.1", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.4.1"); } else { //TestSession - added Template_TestSection_id field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='Template_TestSection_id'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `Template_TestSection_id` bigint(20) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.4.1"); return json_encode(array("result" => 0, "param" => "3.4.1")); } } if (Ini::does_patch_apply("3.4.3", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.4.3"); } else { //TestSection - added end field $sql = "SHOW COLUMNS FROM `TestSection` WHERE `Field`='end'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSection` ADD `end` tinyint(1) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - added new fields $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='debug'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `debug` tinyint(1) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='release'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `release` tinyint(1) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='serialized'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `serialized` tinyint(1) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.4.3"); return json_encode(array("result" => 0, "param" => "3.4.3")); } } if (Ini::does_patch_apply("3.5.0", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.5.0"); } else { $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='serialized'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `serialized` tinyint(1) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Table - added description field $sql = "SHOW COLUMNS FROM `Table` WHERE `Field`='description'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Table` ADD `description` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TableColumn - fix Timestamp fields names $sql = "SHOW COLUMNS FROM `TableColumn` WHERE `Field`='created' OR `Field`='udpated'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 2) { $sql = "ALTER TABLE `TableColumn` CHANGE `created` `updated_temp` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } $sql = "ALTER TABLE `TableColumn` CHANGE `udpated` `created` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } $sql = "ALTER TABLE `TableColumn` CHANGE `updated_temp` `updated` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Template - added description field $sql = "SHOW COLUMNS FROM `Template` WHERE `Field`='description'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Template` ADD `description` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Test - added description field $sql = "SHOW COLUMNS FROM `Test` WHERE `Field`='description'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Test` ADD `description` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSection - fix Timestamp fields $sql = "SHOW COLUMNS FROM `TestSection` WHERE `Field`='created' OR `Field`='updated'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 2) { $sql = "ALTER TABLE `TestSection` CHANGE `created` `updated_temp` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } $sql = "ALTER TABLE `TestSection` CHANGE `updated` `created` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } $sql = "ALTER TABLE `TestSection` CHANGE `updated_temp` `updated` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSectionValue - fix Timestamp fields $sql = "SHOW COLUMNS FROM `TestSectionValue` WHERE `Field`='created' OR `Field`='updated'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 2) { $sql = "ALTER TABLE `TestSectionValue` CHANGE `created` `updated_temp` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } $sql = "ALTER TABLE `TestSectionValue` CHANGE `updated` `created` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } $sql = "ALTER TABLE `TestSectionValue` CHANGE `updated_temp` `updated` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.5.0"); return json_encode(array("result" => 0, "param" => "3.5.0")); } } if (Ini::does_patch_apply("3.5.2", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.5.2"); } else { //TestSection - fixed name of r_type field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='r_typ'"; $z = mysql_query($sql); if (mysql_num_rows($z) > 0) { $sql = "ALTER TABLE `TestSession` CHANGE `r_typ` `r_type` tinyint(1) NOT NULL default '0';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.5.2"); return json_encode(array("result" => 0, "param" => "3.5.2")); } } if (Ini::does_patch_apply("3.6.0", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.6.0"); } else { //DS_TestSectionType - added loop and test inclusion section $sql = "INSERT INTO `DS_TestSectionType` SET `id`=10, `name`='loop', `value`='10', `position`=10;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "msg" => $sql)); } $sql = "INSERT INTO `DS_TestSectionType` SET `id`=11, `name`='test inclusion', `value`='11', `position`=11;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } //Template - added head field $sql = "SHOW COLUMNS FROM `Template` WHERE `Field`='head'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Template` ADD `head` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.6.0"); return json_encode(array("result" => 0, "param" => "3.6.0")); } } if (Ini::does_patch_apply("3.6.2", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.6.2"); } else { //CustomSection - added xml_hash $sql = "SHOW COLUMNS FROM `CustomSection` WHERE `Field`='xml_hash'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `CustomSection` ADD `xml_hash` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Table - added xml_hash $sql = "SHOW COLUMNS FROM `Table` WHERE `Field`='xml_hash'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Table` ADD `xml_hash` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Template - added xml_hash $sql = "SHOW COLUMNS FROM `Template` WHERE `Field`='xml_hash'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Template` ADD `xml_hash` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Test - added xml_hash $sql = "SHOW COLUMNS FROM `Test` WHERE `Field`='xml_hash'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Test` ADD `xml_hash` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.6.2"); return json_encode(array("result" => 0, "param" => "3.6.2")); } } if (Ini::does_patch_apply("3.6.7", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.6.7"); } else { //User - added new fields $sql = "SHOW COLUMNS FROM `User` WHERE `Field`='UserInstitutionType_id'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `User` ADD `UserInstitutionType_id` int(11) NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } $sql = "SHOW COLUMNS FROM `User` WHERE `Field`='institution_name'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `User` ADD `institution_name` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //UserType - changed Sharing_id of standard user type to public $sql = "UPDATE `UserType` SET `Sharing_id`=3 WHERE `id`=4;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } Setting::set_setting("version", "3.6.7"); return json_encode(array("result" => 0, "param" => "3.6.7")); } } if (Ini::does_patch_apply("3.6.8", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.6.8"); } else { //TestSectionValue - indexes changes $sections = TestSection::from_property(array("TestSectionType_id" => DS_TestSectionType::LOAD_HTML_TEMPLATE)); foreach ($sections as $section) { $sql = sprintf("DELETE FROM `%s` WHERE `TestSection_id`=%d AND `index`>=3", TestSectionValue::get_mysql_table(), $section->id); $vals = $section->get_values(); $template = Template::from_mysql_id($vals[0]); if ($template == null) { continue; } $inserts = $template->get_inserts(); $returns = $template->get_outputs(); $j = 3; $i = 3; foreach ($inserts as $ins) { $tsv = new TestSectionValue(); $tsv->TestSection_id = $section->id; $tsv->index = $j; $tsv->value = $ins; $tsv->mysql_save(); $tsv = new TestSectionValue(); $tsv->TestSection_id = $section->id; $tsv->index = $j + 1; $tsv->value = isset($vals[$i]) ? $vals[$i] : $ins; $tsv->mysql_save(); $j = $j + 2; $i++; } foreach ($returns as $ret) { $tsv = new TestSectionValue(); $tsv->TestSection_id = $section->id; $tsv->index = $j; $tsv->value = $ret['name']; $tsv->mysql_save(); $tsv = new TestSectionValue(); $tsv->TestSection_id = $section->id; $tsv->index = $j + 1; $tsv->value = isset($vals[$i]) ? $vals[$i] : $ret['name']; $tsv->mysql_save(); $j = $j + 2; $i++; } } Setting::set_setting("version", "3.6.8"); return json_encode(array("result" => 0, "param" => "3.6.8")); } $validate_column_names = true; } if (Ini::does_patch_apply("3.6.10", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.6.10"); } else { //User - change of password field $sql = "SHOW COLUMNS FROM `User` WHERE `Field`='md5_password'"; $z = mysql_query($sql); if (mysql_num_rows($z) > 0) { $sql = "ALTER TABLE `User` CHANGE `md5_password` `password` text NOT NULL default '';"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.6.10"); return json_encode(array("result" => 0, "param" => "3.6.10")); } } if (Ini::does_patch_apply("3.6.11", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.6.11"); } else { //DS_TestSectionType - add new section type $sql = "\r\n INSERT INTO `DS_TestSectionType` (`id`, `name`, `value`, `position`) VALUES\r\n (12, 'lower level R code', '12', 12);\r\n "; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } Setting::set_setting("version", "3.6.11"); return json_encode(array("result" => 0, "param" => "3.6.11")); } } if (Ini::does_patch_apply("3.7.2", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.7.2"); } else { //DS_Module - add new module type $sql = "\r\n INSERT INTO `DS_Module` (`id`, `name`, `value`, `position`) VALUES\r\n (8, 'QTI assessment item', 'QTIAssessmentItem', 8);\r\n "; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } //UserTypeRight - add default user type rights for new module $sql = "\r\n INSERT INTO `UserTypeRight` (`id`, `updated`, `created`, `Module_id`, `UserType_id`, `read`, `write`, `ownership`) VALUES\r\n (21, '2012-01-18 18:59:34', '2012-01-18 18:59:34', 8, 1, 5, 5, 1),\r\n (22, '2012-02-03 18:29:48', '2012-02-03 18:29:48', 8, 4, 3, 3, 0);\r\n "; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } Setting::set_setting("version", "3.7.2"); return json_encode(array("result" => 0, "param" => "3.7.2")); } } if (Ini::does_patch_apply("3.7.3", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.7.3"); } else { //DS_TestSectionType - add new section types $sql = "\r\n INSERT INTO `DS_TestSectionType` (`id`, `name`, `value`, `position`) VALUES\r\n (13, 'QTI item initialization', '13', 13),\r\n (14, 'QTI item response processing', '14', 14);\r\n "; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } Setting::set_setting("version", "3.7.3"); return json_encode(array("result" => 0, "param" => "3.7.3")); } } if (Ini::does_patch_apply("3.7.4", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.7.4"); } else { //Test - add open field $sql = "SHOW COLUMNS FROM `Test` WHERE `Field`='open'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Test` ADD `open` tinyint(1) NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.7.4"); return json_encode(array("result" => 0, "param" => "3.7.4")); } } if (Ini::does_patch_apply("3.7.5", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.7.5"); } else { //TestSectionValue - custom section values $ts = TestSection::from_property(array("TestSectionType_id" => DS_TestSectionType::CUSTOM)); foreach ($ts as $custom) { $value = TestSectionValue::from_property(array("TestSection_id" => $custom->id, "index" => 0), false); $custom->delete_values(); $value->id = 0; $value->mysql_save(); $value->id = 0; $value->index = 1; $value->value = 0; $value->mysql_save(); $value->id = 0; $value->index = 2; $value->value = 0; $value->mysql_save(); } Setting::set_setting("version", "3.7.5"); return json_encode(array("result" => 0, "param" => "3.7.5")); } } if (Ini::does_patch_apply("3.7.6", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.7.6"); } else { //TestSectionValue - test section values $ts = TestSection::from_property(array("TestSectionType_id" => DS_TestSectionType::TEST)); foreach ($ts as $custom) { $value = TestSectionValue::from_property(array("TestSection_id" => $custom->id, "index" => 0), false); $custom->delete_values(); $value->id = 0; $value->mysql_save(); $value->id = 0; $value->index = 1; $value->value = 0; $value->mysql_save(); $value->id = 0; $value->index = 2; $value->value = 0; $value->mysql_save(); } Setting::set_setting("version", "3.7.6"); return json_encode(array("result" => 0, "param" => "3.7.6")); } } if (Ini::does_patch_apply("3.8.6", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.8.6"); } else { //Test - add loader_Template_id field $sql = "SHOW COLUMNS FROM `Test` WHERE `Field`='loader_Template_id'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Test` ADD `loader_Template_id` bigint(20) NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Template - add effect_show field $sql = "SHOW COLUMNS FROM `Template` WHERE `Field`='effect_show'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Template` ADD `effect_show` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Template - add effect_hide field $sql = "SHOW COLUMNS FROM `Template` WHERE `Field`='effect_hide'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Template` ADD `effect_hide` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Template - add effect_show_options field $sql = "SHOW COLUMNS FROM `Template` WHERE `Field`='effect_show_options'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Template` ADD `effect_show_options` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //Template - add effect_hide_options field $sql = "SHOW COLUMNS FROM `Template` WHERE `Field`='effect_hide_options'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `Template` ADD `effect_hide_options` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } /// //TestTemplate - add effect_show field $sql = "SHOW COLUMNS FROM `TestTemplate` WHERE `Field`='effect_show'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestTemplate` ADD `effect_show` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestTemplate - add effect_hide field $sql = "SHOW COLUMNS FROM `TestTemplate` WHERE `Field`='effect_hide'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestTemplate` ADD `effect_hide` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestTemplate - add effect_show_options field $sql = "SHOW COLUMNS FROM `TestTemplate` WHERE `Field`='effect_show_options'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestTemplate` ADD `effect_show_options` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestTemplate - add effect_hide_options field $sql = "SHOW COLUMNS FROM `TestTemplate` WHERE `Field`='effect_hide_options'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestTemplate` ADD `effect_hide_options` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } /// //TestSession - add effect_show field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='effect_show'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `effect_show` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - add effect_hide field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='effect_hide'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `effect_hide` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - add effect_show_options field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='effect_show_options'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `effect_show_options` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - add effect_hide_options field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='effect_hide_options'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `effect_hide_options` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } /// //TestSession - add loader_effect_show field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='loader_effect_show'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `loader_effect_show` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - add loader_effect_hide field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='loader_effect_hide'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `loader_effect_hide` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - add loader_effect_show_options field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='loader_effect_show_options'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `loader_effect_show_options` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - add loader_effect_hide_options field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='loader_effect_hide_options'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `loader_effect_hide_options` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - add loader_Template_id field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='loader_Template_id'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `loader_Template_id` bigint(20) NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - add loader_HTML field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='loader_HTML'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `loader_HTML` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TestSession - add loader_head field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='loader_head'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TestSession` ADD `loader_head` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.8.6"); return json_encode(array("result" => 0, "param" => "3.8.6")); } $repopulate_TestTemplate = true; } if (Ini::does_patch_apply("3.8.7", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.8.7"); } else { //TableColumn - add type field $sql = "SHOW COLUMNS FROM `TableColumn` WHERE `Field`='type'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TableColumn` ADD `type` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TableColumn - add length field $sql = "SHOW COLUMNS FROM `TableColumn` WHERE `Field`='length'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TableColumn` ADD `length` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TableColumn - add default_value field $sql = "SHOW COLUMNS FROM `TableColumn` WHERE `Field`='default_value'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TableColumn` ADD `default_value` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TableColumn - add attributes field $sql = "SHOW COLUMNS FROM `TableColumn` WHERE `Field`='attributes'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TableColumn` ADD `attributes` text NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TableColumn - add null field $sql = "SHOW COLUMNS FROM `TableColumn` WHERE `Field`='null'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TableColumn` ADD `null` tinyint(1) NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TableColumn - add auto_increment field $sql = "SHOW COLUMNS FROM `TableColumn` WHERE `Field`='auto_increment'"; $z = mysql_query($sql); if (mysql_num_rows($z) == 0) { $sql = "ALTER TABLE `TableColumn` ADD `auto_increment` tinyint(1) NOT NULL;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } //TableColumn - fill type column text $sql = "UPDATE `TableColumn` SET `type`='text' WHERE `TableColumnType_id`=1 OR `TableColumnType_id`=4"; $z = mysql_query($sql); if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } //TableColumn - fill type column integer $sql = "UPDATE `TableColumn` SET `type`='bigint' WHERE `TableColumnType_id`=2"; $z = mysql_query($sql); if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } //TableColumn - fill type column double $sql = "UPDATE `TableColumn` SET `type`='double' WHERE `TableColumnType_id`=3"; $z = mysql_query($sql); if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } //TableColumn - remove DS_TableColumnType_id $sql = "SHOW COLUMNS FROM `TableColumn` WHERE `Field`='TableColumnType_id'"; $z = mysql_query($sql); if (mysql_num_rows($z) > 0) { $sql = "ALTER TABLE `TableColumn` DROP `TableColumnType_id`;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.8.7"); return json_encode(array("result" => 0, "param" => "3.8.7")); } } if (Ini::does_patch_apply("3.8.8", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.8.8"); } else { Setting::set_setting("version", "3.8.8"); return json_encode(array("result" => 0, "param" => "3.8.8")); } $recalculate_hash = true; } if (Ini::does_patch_apply("3.9.0", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.9.0"); } else { ///TestSession - removing r_type field $sql = "SHOW COLUMNS FROM `TestSession` WHERE `Field`='r_type'"; $z = mysql_query($sql); if (mysql_num_rows($z) > 0) { $sql = "ALTER TABLE `TestSession` DROP `r_type`;"; if (!mysql_query($sql)) { return json_encode(array("result" => 1, "param" => $sql)); } } Setting::set_setting("version", "3.9.0"); return json_encode(array("result" => 0, "param" => "3.9.0")); } } if (Ini::does_patch_apply("3.9.2", $previous_version)) { if ($simulate) { array_push($versions_to_update, "3.9.2"); } else { //DS_TestSectionType - adding two new loop sections $sql = "INSERT INTO `DS_TestSectionType` (`id`, `name`, `value`, `position`) VALUES \r\n (15, 'FOR loop', '15', 15),\r\n (16, 'WHILE loop', '16', 16)"; $z = mysql_query($sql); Setting::set_setting("version", "3.9.2"); return json_encode(array("result" => 0, "param" => "3.9.2")); } } if ($simulate) { return json_encode(array("versions" => $versions_to_update, "validate_column_names" => $validate_column_names, "repopulate_TestTemplate" => $repopulate_TestTemplate, "recalculate_hash" => $recalculate_hash, "create_db" => self::create_db_structure(true))); } return json_encode(array("result" => 2)); }