Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Fix - renaming or deleting tasks in Ftrack wasn't synced
Browse files Browse the repository at this point in the history
Part for syncing through Event server
  • Loading branch information
kalisp committed Oct 7, 2020
1 parent ce24026 commit c08a6ad
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pype/modules/ftrack/events/action_sync_to_avalon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SyncToAvalonServer(BaseAction):
- Data(dictionary):
- VisualParent(ObjectId) - Avalon Id of parent asset
- Parents(array of string) - All parent names except project
- Tasks(array of string) - Tasks on asset
- Tasks(dictionary of dictionaries) - Tasks on asset
- FtrackId(string)
- entityType(string) - entity's type on Ftrack
* All Custom attributes in group 'Avalon'
Expand Down
82 changes: 62 additions & 20 deletions pype/modules/ftrack/events/event_sync_to_avalon.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,16 @@ def filter_updated(self, updates):
return filtered_updates

def get_ent_path(self, ftrack_id):
"""
Looks for entity in FTrack with 'ftrack_id'. If found returns
concatenated paths from its 'link' elemenent's names. Describes
location of entity in tree.
Args:
ftrack_id (string): entityId of FTrack entity
Returns:
(string) - example : "/test_project/assets/my_asset"
"""
entity = self.ftrack_ents_by_id.get(ftrack_id)
if not entity:
entity = self.process_session.query(
Expand All @@ -491,7 +501,7 @@ def launch(self, session, event):
self.process_session.commit()
except Exception:
self.set_process_session(session)

self.log.debug("start launch")
# Reset object values for each launch
self.reset_variables()
self._cur_event = event
Expand All @@ -502,7 +512,7 @@ def launch(self, session, event):
"move": {},
"add": {}
}

self.log.debug("event_data:: {}".format(event["data"]))
entities_info = event["data"]["entities"]
found_actions = set()
for ent_info in entities_info:
Expand Down Expand Up @@ -741,8 +751,9 @@ def process_removed(self):
avalon_ent["data"]["tasks"]
)

if removed_name in self.task_changes_by_avalon_id[mongo_id]:
self.task_changes_by_avalon_id[mongo_id].remove(
if removed_name in self.task_changes_by_avalon_id[mongo_id].\
keys():
self.task_changes_by_avalon_id[mongo_id].pop(
removed_name
)

Expand Down Expand Up @@ -1068,11 +1079,13 @@ def create_entity_in_avalon(self, ftrack_ent, parent_avalon):
)

# Tasks
tasks = []
tasks = {}
for child in ftrack_ent["children"]:
if child.entity_type.lower() != "task":
continue
tasks.append(child["name"])
self.log.debug("child:: {}".format(child))
task_type = self._get_task_type(child['entityId'])
tasks[child["name"]] = {"type": task_type}

# Visual Parent
vis_par = None
Expand Down Expand Up @@ -1423,8 +1436,8 @@ def process_renamed(self):
avalon_ent["data"]["tasks"]
)

if old_name in self.task_changes_by_avalon_id[mongo_id]:
self.task_changes_by_avalon_id[mongo_id].remove(old_name)
if old_name in self.task_changes_by_avalon_id[mongo_id].keys():
self.task_changes_by_avalon_id[mongo_id].pop(old_name)
else:
parent_ftrack_ent = self.ftrack_ents_by_id.get(parent_id)
if not parent_ftrack_ent:
Expand All @@ -1442,17 +1455,21 @@ def process_renamed(self):
continue
child_names.append(child["name"])

tasks = [task for task in (
self.task_changes_by_avalon_id[mongo_id]
)]
for task in tasks:
if task not in child_names:
self.task_changes_by_avalon_id[mongo_id].remove(
task
tasks = copy.deepcopy(
self.task_changes_by_avalon_id[mongo_id].keys()
)

for task_name in tasks:
if task_name not in child_names:
self.task_changes_by_avalon_id[mongo_id].pop(
task_name
)

if new_name not in self.task_changes_by_avalon_id[mongo_id]:
self.task_changes_by_avalon_id[mongo_id].append(new_name)
task_type = self._get_task_type(ent_info['entityId'])
if new_name not in self.task_changes_by_avalon_id[mongo_id].keys():
self.task_changes_by_avalon_id[mongo_id][new_name] = {
"type": task_type
}

# not_found are not processed since all not found are
# not found because they are not synchronizable
Expand Down Expand Up @@ -1688,8 +1705,12 @@ def process_added(self):
self.regex_failed.append(ent_info["entityId"])
continue

if new_name not in self.task_changes_by_avalon_id[mongo_id]:
self.task_changes_by_avalon_id[mongo_id].append(new_name)
task_type = self._get_task_type(ent_info['entityId'])
if new_name not in \
self.task_changes_by_avalon_id[mongo_id].keys():
self.task_changes_by_avalon_id[mongo_id][new_name] = {
"type": task_type
}

def _mongo_id_configuration(
self,
Expand Down Expand Up @@ -2293,7 +2314,9 @@ def update_entities(self):
mongo_changes_bulk = []
for mongo_id, changes in self.updates.items():
filter = {"_id": mongo_id}
change_data = avalon_sync.from_dict_to_set(changes)
avalon_ent = self.avalon_ents_by_id[mongo_id]
is_project = avalon_ent["type"] == "project"
change_data = avalon_sync.from_dict_to_set(changes, is_project)
mongo_changes_bulk.append(UpdateOne(filter, change_data))

if not mongo_changes_bulk:
Expand Down Expand Up @@ -2477,6 +2500,25 @@ def report(self):
)
return True

def _get_task_type(self, entityId):
"""
Returns task type ('Props', 'Art') from Task 'entityId'
Args:
entityId (string): entityId of Task
Returns:
(string) - None if Task not found
"""
task_type = None
entity = self.process_session.query(
self.entities_query_by_id.format(
self.cur_project["id"], entityId
)
).first()
if entity:
task_type = entity["type"]["name"]
return task_type


def register(session, plugins_presets):
'''Register plugin. Called when used as an plugin.'''
Expand Down

0 comments on commit c08a6ad

Please sign in to comment.