Browse Source

Added simple model_move (untested)

Yentl Van Tendeloo 7 years ago
parent
commit
bd87ebfb30
2 changed files with 29 additions and 0 deletions
  1. BIN
      bootstrap/bootstrap.m.gz
  2. 29 0
      bootstrap/core_algorithm.alc

BIN
bootstrap/bootstrap.m.gz


+ 29 - 0
bootstrap/core_algorithm.alc

@@ -1093,6 +1093,33 @@ String function cmd_help():
 
 	return result!
 
+String function cmd_model_move(source : String, target : String):
+	String source_id
+	source_id = get_entry_id(source)
+	if (source_id != ""):
+		if (get_entry_id(target) == ""):
+			// Create folders on path to the target
+			create_folders(current_user_id, get_foldername(target))
+
+			// Change location, first the name
+			instantiate_attribute(core, source_id, "name", target)
+
+			// Now the folder links
+			Element links
+			links = allIncomingAssociationInstances(core, "contains", source_id)
+			while (set_len(links) > 0):
+				model_delete_element(core, set_pop(links))
+			instantiate_link(core, "contains", "", get_entry_id(get_foldername(target)), source_id)
+
+			// Flush caches
+			dict_add(caches["models"], target, caches["models"][source])
+			dict_delete(caches["models"], source)
+
+		else:
+			return "Model exists: " + target!
+	else:
+		return "Model does not exist: " + source!
+
 String function cmd_model_add(type : String, name : String, code : String):
 	// Model addition operation, which uses model upload commands of the compiler
 	String location
@@ -2367,6 +2394,8 @@ Void function user_function_skip_init(user_id : String):
 			output(cmd_help())
 		elif (cmd == "model_add"):
 			output(cmd_model_add(single_input("Model type?"), single_input("Model name?"), single_input("Model textual representation?")))
+		elif (cmd == "model_move"):
+			output(cmd_model_move(single_input("Model name?"), single_input("New location?")))
 		elif (cmd == "process_execute"):
 			output(cmd_process_execute(single_input("Process to execute?"), dict_input("Model bindings to use?")))
 		elif (cmd == "process_signature"):