def get_layer_info_from_source(self,id): gisconn = self.connect(GIS,self.migrate_env.get("connection_from_id"),self.use_proxy) item = self.get_item_by_id(id, None, gisconn) itype = item.type if itype == 'Map Service': itype = 'Map Image Layer' return (item.title,itype) def get_layer_id(self,layer): #for the to environment, get the layer id id = None try: layer_source = self.get_layer_info_from_source(layer["itemId"]) item = self.get_item(self.migrate_env.get("owner"),layer_source[0],layer_source[1], self.gisconn) id = item["id"] except: print('Layer {} missing item link!'.format(layer.title)) pass return id def update_layer(self,layer): change=False name = self.migrate_env.get("name") name_from = self.migrate_env.get("name_from") url_before = layer["url"] url = url_before.replace(name_from,name) if name == 'mysite': url = url.replace('mysitedev.net','mysite.net') url = url.replace('mysitetest.net','mysite.net') if url_before!=url: layer["url"] = url #do this so that when they click description for an item in a map etc they will land on the item page, otherwise they go to the rest endpoint layer["itemId"] = self.get_layer_id(layer) change = True special_url = self.get_special_url(url) #some urls do not change NFHL for instance but we have a different itemid for that item. Grab the id from config for script. if special_url[0]: itemId_before = layer["itemId"] itemId = self.get_layer_id(layer) if itemId is None: itemId = special_url[1] if itemId!=itemId_before: layer["itemId"] = itemId change = True return (layer,change) def fix_maps(self): #get maps from environment self.initialize_config() conn_id = self.migrate_env.get("connection_id") maps=[] self.gisconn = self.connect(GIS,conn_id,self.use_proxy) #maps = self.gisconn.content.search('title:some webmap','Web Map',max_items=100) maps = self.gisconn.content.search('','Web Map',max_items=100) for m in maps: print("Start processing MAP[{}]".format(m.title)) change = False web_map_obj = WebMap(m) for l in web_map_obj.layers: lobj = self.update_layer(l) if lobj[1]==True: change = True l = lobj[0] if change: #update the map here.. web_map_obj.update() print("MAP[{}] urls have been updated.".format(m.title)) print("Finished processing MAP[{}]".format(m.title)) return def fix_apps(self): #get maps from environment self.initialize_config() conn_id = self.migrate_env.get("connection_id") from_env = self.migrate_env.get("name_from") to_env = self.migrate_env.get("name") from_url = self.dev_test_url_base.replace('{server}',from_env) has_change_data = from_url if to_env.upper() == 'GIS': has_change = self.prod_url_base maps=[] self.gisconn = self.connect(GIS,conn_id,self.use_proxy) #apps = self.gisconn.content.search("title:some web app AND owner:{} AND type:Web Mapping Application".format(self.set_env_migrate.get("owner")),max_items=100) apps = self.gisconn.content.search("owner:{} AND type:Web Mapping Application".format(self.migrate_env.get("owner")),max_items=100) for a in apps: data_str = json.dumps(a.get_data()) has_change = not (data_str.find(has_change_data)==-1) if not has_change: data_str = data_str.replace(from_env,to_env) if to_env.upper()=='MYSITE': #red to orange data_str = data_str.replace('#ff0000','#ff9900') item_data = json.loads(data_str) r=a.update(item_properties={'text':item_data}) print("APP[{}] urls have been update".format(a.title)) return