Select to view content in your preferred language

Sharing after using clone_items()

2015
4
Jump to solution
12-30-2020 09:15 AM
Alex_Gole
Occasional Contributor

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)
             

 

 

1 Solution

Accepted Solutions
MehdiPira1
Esri Contributor

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);

https://developers.arcgis.com/python/sample-notebooks/clone-portal-users-groups-and-content/#establi... 

View solution in original post

4 Replies
MehdiPira1
Esri Contributor

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);

https://developers.arcgis.com/python/sample-notebooks/clone-portal-users-groups-and-content/#establi... 

Alex_Gole
Occasional Contributor

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,

0 Kudos
MehdiPira1
Esri Contributor

@Alex_Gole 

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:

  1. For each user create a mapping of itemId to the Item
  2. Prepare sharing information for each item
    Print a mapping of item and its group membership
  3. Copy items one by one
  4. Establish relationship between items
Alex_Gole
Occasional Contributor

OK thanks!

0 Kudos