{= # # # # import_item.cfv # # # # # # # Initiated from client. This template writes the import item data to sessions_cache # and invokes the actual import via exec() so that the client gets an immediate response. # The client then checks periodically the import state by looking at the import item # data in sessions_cache. # # # This template also handles # - Deletes an existing version 8 profile and its database when it becomes overridden by the version 7 profile # - Issue a new version 8 profile_name for every version 7 profile # include "templates.util.base_util"; include "templates.util.encoding"; include "templates.util.node_names"; include "templates.util.rbac.rbac_util"; debug_message("\n#### import_item.cfv START\n\n"); string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); string page_token = v.fp.page_token; # # Check RBAC permissions # if ((is_root_admin or get_admin_feature_permission(session_id, "import_data", "view")) and get_is_valid_page_token(session_id, "import_data", page_token)) then ( debug_message("\n" . node_as_string("v.fp") . "\n"); string import_id = v.fp.import_id; string import_type = v.fp.import_type; int item_index_of_import_item = v.fp.item_index_of_import_item; # debug_message("#### session_id: " . session_id . "\n"); # # # Set common exec variables # # string pid; string cmd = ""; bool wait; # # # # Handle profile deletion and new version 8 profile name (before setting the session data because we add v.fp.new_v8_profile_name!) # # # string new_v8_profile_name = ""; if (import_type eq "profile") then ( bool profile_exists_in_v8 = v.fp.profile_exists_in_v8; string existing_v8_profile_name = v.fp.existing_v8_profile_name; if (profile_exists_in_v8 and ?("profiles." . existing_v8_profile_name)) then ( # # # # Delete existing profile and database # # # # We delete the profile and we delete the database, though # the database is only deleted if it isn't shared with the v7 # profile, respectively if v8_overrides_v7_database is false! bool v8_overrides_v7_database = v.fp.v8_overrides_v7_database; bool delete_v8_database = !v8_overrides_v7_database; delete_node("v.options"); v.options.1 = "background"; v.options.2 = "-dp"; v.options.3 = "templates.admin_pages.import_data.delete_profile_prior_import"; v.options.4 = "volatile.session_id"; v.options.5 = session_id; v.options.6 = "-p"; v.options.7 = existing_v8_profile_name; v.options.8 = "volatile.delete_v8_database"; v.options.9 = delete_v8_database; v.options.10 = "volatile.page_token"; v.options.11 = page_token; # Note that we wait until deletion completes. Deletion should happen instantly anway. wait = true; pid = exec(cmd, "v.options", wait); ); # # # Get new version 8 profile name from version 7 profile label # # string v7_profile_label = v.fp.v7_profile_label; new_v8_profile_name = convert_to_valid_node_name(v7_profile_label); new_v8_profile_name = get_unique_node_name("profiles", new_v8_profile_name); # # Set new_v8_profile_name in v.fp! # v.fp.new_v8_profile_name = new_v8_profile_name; ); # # # # Save import data in sessions_cache # # # string sessions_import_item_path = "sessions_cache." . session_id . ".import." . import_id; clone_node("v.fp", sessions_import_item_path); save_node(sessions_import_item_path); # # # # Start import by initiating import_item_handler.cfv via exec() # # # delete_node("v.options"); v.options.1 = "background"; v.options.2 = "-dp"; v.options.3 = "templates.admin_pages.import_data.import_item_handler"; v.options.4 = "volatile.session_id"; v.options.5 = session_id; v.options.6 = "volatile.import_id"; v.options.7 = import_id; v.options.8 = "v.fp.page_token"; v.options.9 = page_token; # If this is a profile which already exists in version 8 # then set the -p option so that we can erase the existing # database if any. # if ((import_type eq "profile") and @("v.fp.profile_exists_in_v8")) then ( # # # Note, the version 8 profile name may be different than the version 7 profile name, # # hence we use the v8_profile_name in the -p option # # v.options.8 = "-p"; # v.options.9 = v.fp.existing_v8_profile_name; # ); wait = false; pid = exec(cmd, "v.options", wait); # # # # Response # # # string dat = '{'; dat .= add_json("importId", import_id, "string"); dat .= add_json("importType", import_type, "string"); dat .= add_json("itemIndexOfImportItem", item_index_of_import_item, "int"); dat .= add_json("newV8profileName", new_v8_profile_name, "string"); dat = close_json(dat); 'importDataStack.importItemResponse(' . dat . ')\n'; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); debug_message("\n#### import_item.cfv END\n\n"); =}