Hi all,
I am in the process of migrating a Portal to another portal. I am using the clone_item() function to migrate the items unlike this clone users, groups, and content . This works great. The only issue I have is when I try to share items with groups, org or everyone. Although my script does update the sharing for some, I often get this error Item has a Relationship Type that does not allow this. (Error Code: 500).
Any idea what I can do to update sharing for an item and its related items?
Here is my current code:
#source content
source_users = source.users.search('!esri_ & !admin')
#target content
target_users = target.users.search('!esri_ & !admin & !system_publisher')
#source groups
source_groups = source.groups.search("!owner:esri_* & !Basemaps")
#target groups
target_groups = target.groups.search("!owner:esri_* & !Basemaps")
for user in source_users:
if user.username == "ITPublisher1":
tester_content = source.content.search("owner:"+ user.username, max_items=500)
for item in tester_content:
print(item.access)
if item.access == "shared":
for group in source_groups:
for group_item in group.content():
if group_item.itemid == item.itemid:
print(group)
target_group = target.groups.search(group.title)
for tg in target_group:
target_item = target.content.search(item.title)
print(tg.groupid)
for ti in target_item:
print(ti)
ti.share(everyone=False, org=False, groups=tg.groupid)
else:
print("not in target portal ")
#elif item.access == "public":
# target_item = target.content.search(item.title)
# for ti in target_item:
# print(ti)
# ti.share(everyone=True, org=False)
elif item.access == "org":
target_item = target.content.search(item.title)
for ti in target_item:
print(ti)
ti.share(everyone=False, org=True)
Solved! Go to Solution.
Hi @Alex_Gole ,
One of the requirements of cloning is establishing the same relationship between source and target items.
The following link provides a useful step by step process of establishing relationships when cloning (section: Establish relationship between items);
Hi @Alex_Gole ,
One of the requirements of cloning is establishing the same relationship between source and target items.
The following link provides a useful step by step process of establishing relationships when cloning (section: Establish relationship between items);
Doesn't clone_items(). Take care of the relationship. In the demo you point to, I notice that they dont use clone_items() when they copy the items. they use:
what i use:
cloned_items = target.content.clone_items(items=[item], folder=f['title'], copy_data=False, group_mapping)
what is used by the sample:
target_item = target.content.add(item_properties, data_file, thumbnail_file, metadata_file, source_item.owner, folder_name)
It looked like the relationship between items was taken care of by clone_items().
Thanks,
No it doesn't.
These are the steps required for items to be cloned properly:
Items
Copying items consists of multiple steps as explained in the following section of the sample:
OK thanks!