We are currently hosting features in ArcGIS Online to be used with the Collector App. We plan to update these features nightly from an SDE environment with Python. Due to some of the network security implementations, we are restricted from using the REST endpoints from an ArcServer instance to create these feature layers. I have written a script to do this, but the issue I am running into is when a user downloads an area for offline use a replica is created. This replica stops the feature's underlying data source (Service Definition File) from updating the feature. A work around I have found is to unregister the replicas then update the feature, but this causes sync errors on the user's collector area when they attempt to re-sync their downloaded area. Does anyone know of a cleaner solution to updating features with outstanding replicas?
# checks if feature exists:
try:
# Gets access to the existing service definition object
sdItems = self.gis.content.search("{0} AND owner:{1}".format(feature.name, self.user), item_type="Service Definition")
sdItem = sdItems[0]
# Updates feature data
sdItem.update(data=sd)
# if feature does not exits...
except IndexError:
# the service definition file is uploaded to ArcGIS Online
sdItem = self.gis.content.add(feature.getProperties(), data=sd)
# Gets access the the feature collection object
featureCollect = self.gis.content.search("{0} AND owner:{1}".format(feature.name, self.user), item_type="Feature Layer Collection")
try:
# Attempts too publish the service definition to the feature layer
featureService = sdItem.publish(overwrite=True)
# if the feature cannot be updated...
except Exception as ex:
# Accesses Feature Collection object
featureService = self.gis.content.get(feature.service_id)
FeatureCollection = FeatureLayerCollection.fromitem(featureService)
# Unregisters outstanding replicas
for replica in FeatureCollection.replicas.get_list():
FeatureCollection.replicas.unregister(replica['replicaID'])
# Disables Syncing
FeatureCollection.manager.update_definition({"syncEnabled": False})
# Publishes Service Definition to Feature Layer
featureService = sdItem.publish(overwrite=True)
# Updates feature tags
featureItem = self.gis.content.get(featureService.id)
featureItem.update(item_properties={'tags': feature.tags})
# Enables Offline Syncing
FeatureCollection = FeatureLayerCollection.fromitem(featureItem)
FeatureCollection.manager.update_definition({"syncEnabled": True,
"serviceDescription":feature.desc,
"description":feature.desc})
# Updates editing capabilities
FeatureCollection.manager.update_definition({"capabilities":feature.capabilities})