Skip to content

Commit

Permalink
fix: auto-repair default icons when there is a orphan file resource […
Browse files Browse the repository at this point in the history
…DHIS2-18606] (#19424)
  • Loading branch information
jbee authored Dec 10, 2024
1 parent 1d49336 commit 5efe952
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -114,11 +115,13 @@ public String addDefaultIconImage(@Nonnull String key, @Nonnull DefaultIcon orig
try {
FileResource fr = FileResource.ofKey(ICON, key, MEDIA_TYPE_SVG);
fr.setUid(fileResourceId);
Optional<FileResource> existing = fileResourceService.findByStorageKey(fr.getStorageKey());
if (existing.isPresent()) fr = existing.get();
fr.setAssigned(true);
try (InputStream image = resource.getInputStream()) {
fileResourceService.syncSaveFileResource(fr, image);
}
return fileResourceId;
return fr.getUid();
} catch (IOException ex) {
ignoredAfterFailure.add(origin);
throw new ConflictException("Failed to create default icon resource: " + ex.getMessage());
Expand Down

0 comments on commit 5efe952

Please sign in to comment.