Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: FileBone.refresh() should fix serving_url #1404

Merged
Merged
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
59 changes: 40 additions & 19 deletions src/viur/core/bones/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,27 +287,48 @@ def refresh(self, skel, boneName):
references in the bone value, imports the blobs from ViUR 2, and recreates the file entries if
needed using the inner function.
"""
from viur.core.skeleton import skeletonByKind

def recreateFileEntryIfNeeded(val):
# Recreate the (weak) filenetry referenced by the relation *val*. (ViUR2 might have deleted them)
skel = skeletonByKind("file")()
if skel.read(val["key"]): # This file-object exist, no need to recreate it
return
skel["key"] = val["key"]
skel["name"] = val["name"]
skel["mimetype"] = val["mimetype"]
skel["dlkey"] = val["dlkey"]
skel["size"] = val["size"]
skel["width"] = val["width"]
skel["height"] = val["height"]
skel["weak"] = True
skel["pending"] = False
skel.write()

from viur.core.modules.file import importBlobFromViur2
super().refresh(skel, boneName)

for _, _, value in self.iter_bone_value(skel, boneName):
# Patch any empty serving_url when public file
if (
value
and (value := value["dest"])
and value["public"]
and value["mimetype"]
and value["mimetype"].startswith("image/")
and not value["serving_url"]
):
logging.info(f"Patching public image with empty serving_url {value['key']!r} ({value['name']!r})")
try:
file_skel = value.read()
except ValueError:
continue

file_skel.patch(lambda skel: skel.refresh(), update_relations=False)
value["serving_url"] = file_skel["serving_url"]

# FIXME: REMOVE THIS WITH VIUR4
if conf.viur2import_blobsource:
from viur.core.modules.file import importBlobFromViur2
from viur.core.skeleton import skeletonByKind

def recreateFileEntryIfNeeded(val):
# Recreate the (weak) filenetry referenced by the relation *val*. (ViUR2 might have deleted them)
skel = skeletonByKind("file")()
if skel.read(val["key"]): # This file-object exist, no need to recreate it
return
skel["key"] = val["key"]
skel["name"] = val["name"]
skel["mimetype"] = val["mimetype"]
skel["dlkey"] = val["dlkey"]
skel["size"] = val["size"]
skel["width"] = val["width"]
skel["height"] = val["height"]
skel["weak"] = True
skel["pending"] = False
skel.write()

# Just ensure the file get's imported as it may not have an file entry
val = skel[boneName]
if isinstance(val, list):
Expand Down
7 changes: 2 additions & 5 deletions src/viur/core/bones/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,11 +1027,8 @@ def refresh(self, skel: "SkeletonInstance", name: str) -> None:
if not skel[name] or self.updateLevel == RelationalUpdateLevel.OnValueAssignment:
return

for idx, lang, value in self.iter_bone_value(skel, name):
if value is None:
continue

if value["dest"]:
for _, _, value in self.iter_bone_value(skel, name):
if value and value["dest"]:
try:
target_skel = value["dest"].read()
except ValueError:
Expand Down