Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/tagstudio/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1898,21 +1898,34 @@ def mirror_entry_fields(self, *entries: Entry) -> None:
"""Mirror fields among multiple Entry items."""
fields = {}
# load all fields
existing_fields = {field.type_key for field in entries[0].fields}
for entry in entries:
for entry_field in entry.fields:
fields[entry_field.type_key] = entry_field

# assign the field to all entries
# assign the fields to all entries
for entry in entries:
for field_key, field in fields.items(): # pyright: ignore[reportUnknownVariableType]
existing_fields = {entry_field.type_key for entry_field in entry.fields}
if field_key not in existing_fields:
self.add_field_to_entry(
entry_id=entry.id,
field_id=field.type_key,
value=field.value,
)

def mirror_entry_tags(self, *entries: Entry) -> None:
"""Mirror tags among multiple Entry items."""
tag_ids_set = set()
entry_ids = []
# load all entries and tags
for entry in entries:
entry_ids.append(entry.id)
for tag in entry.tags:
tag_ids_set.add(tag.id)
tag_ids = list(tag_ids_set)
# assign the tags to all entries
self.add_tags_to_entries(entry_ids, tag_ids)

def merge_entries(self, from_entry: Entry, into_entry: Entry) -> bool:
"""Add fields and tags from the first entry to the second, and then delete the first."""
success = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,29 @@ def refresh_dupe_files(self, results_filepath: str | Path):
path_relative = file_path.relative_to(library_dir)
except ValueError:
# The file is not in the library directory
logger.error("File not in library directory", file_path=file_path)
continue

results = self.library.search_library(
BrowsingState.from_path(path_relative), 500
)
entries = self.library.get_entries(results.ids)

if not results:
# file not in library
logger.error("No Entry matching file", path_relative=path_relative)
continue

files.append(entries[0])
entry = self.library.get_entry_full(results.ids[0])

if not entry:
# file not in library
logger.error(
"Unable to get entry",
entry_id=results.ids[0],
path_relative=path_relative,
)
continue
files.append(entry)

if not len(files) > 1:
# only one file in the group, nothing to do
Expand Down
2 changes: 2 additions & 0 deletions src/tagstudio/qt/mixed/mirror_entries_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def mirror_entries_runnable(self):
mirrored: list = []
lib = self.driver.lib
for i, entries in enumerate(self.tracker.groups):
# mirror tags and fields
lib.mirror_entry_tags(*entries)
lib.mirror_entry_fields(*entries)
sleep(0.005)
yield i
Expand Down