mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 08:54:53 +01:00
integrate new will remove old representations if republishing version and set new repres IDs to those previous
This commit is contained in:
parent
c71b8dbf2c
commit
c0584eded7
1 changed files with 23 additions and 1 deletions
|
|
@ -207,6 +207,7 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
|
|||
'parent': subset["_id"],
|
||||
'name': next_version
|
||||
})
|
||||
existing_repres = None
|
||||
if existing_version is None:
|
||||
version_id = io.insert_one(version).inserted_id
|
||||
else:
|
||||
|
|
@ -217,6 +218,11 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
|
|||
}, {'$set': version}
|
||||
)
|
||||
version_id = existing_version['_id']
|
||||
existing_repres = {repre["name"]: repre for repre in io.find({
|
||||
"type": "representation",
|
||||
"parent": version_id
|
||||
})}
|
||||
|
||||
instance.data['version'] = version['name']
|
||||
|
||||
# Write to disk
|
||||
|
|
@ -249,6 +255,7 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
|
|||
if 'transfers' not in instance.data:
|
||||
instance.data['transfers'] = []
|
||||
|
||||
new_repre_names = []
|
||||
for idx, repre in enumerate(instance.data["representations"]):
|
||||
|
||||
# Collection
|
||||
|
|
@ -419,8 +426,16 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
|
|||
continue
|
||||
repre_context[key] = template_data[key]
|
||||
|
||||
repre_name = repre['name']
|
||||
new_repre_names.append(repre_name)
|
||||
# Use previous
|
||||
if existing_repres and repre_name in existing_repres:
|
||||
repre_id = existing_repres[repre_name]["_id"]
|
||||
else:
|
||||
repre_id = io.ObjectId()
|
||||
|
||||
representation = {
|
||||
"_id": io.ObjectId(),
|
||||
"_id": repre_id,
|
||||
"schema": "pype:representation-2.0",
|
||||
"type": "representation",
|
||||
"parent": version_id,
|
||||
|
|
@ -446,6 +461,13 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin):
|
|||
representations.append(representation)
|
||||
self.log.debug("__ representations: {}".format(representations))
|
||||
|
||||
# Remove old representations if there are any (before insertion of new)
|
||||
if existing_repres:
|
||||
repre_ids_to_remove = []
|
||||
for repre in existing_repres.values():
|
||||
repre_ids_to_remove.append(repre["_id"])
|
||||
io.delete_many({"_id": {"$in": repre_ids_to_remove}})
|
||||
|
||||
self.log.debug("__ representations: {}".format(representations))
|
||||
for rep in instance.data["representations"]:
|
||||
self.log.debug("__ represNAME: {}".format(rep['name']))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue