Import annotations from wallabag JSON exports - #8928
Conversation
Wallabag JSON exports include an `annotations` array for each entry, but the wallabag importers only read `url`, `title`, `tags`, etc. and silently dropped the annotations. Re-importing an export therefore lost all highlights/notes. Parse the `annotations` key in `WallabagImport::parseEntry()` and recreate each `Annotation` (text, quote, ranges) attached to the imported entry and the current user. Also initialize `Entry::$annotations` in the constructor so a freshly created entry exposes a proper collection. Fixes wallabag#8643 Co-Authored-By: Claude Fable 5 <[email protected]>
✅ Deploy Preview for wallabag-doc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Once the constructor initializes it as an ArrayCollection, inferPrivatePropertyTypeFromConstructor inferred an empty collection. Type the property (mirroring $tags) and align getAnnotations() docblock. Co-Authored-By: Claude <[email protected]>
|
Fixed the PHPStan failure: typing |
| */ | ||
| protected function parseAnnotation(Entry $entry, $importedAnnotation): ?Annotation | ||
| { | ||
| if (!\is_array($importedAnnotation) || empty($importedAnnotation['text'])) { |
There was a problem hiding this comment.
A note can be empty (if we only want to highlight some text)
| if (!\is_array($importedAnnotation) || empty($importedAnnotation['text'])) { | |
| if (!\is_array($importedAnnotation) || !\array_key_exists('text', $importedAnnotation)) { |
| $annotation->setQuote($importedAnnotation['quote'] ?? ''); | ||
| $annotation->setRanges(\is_array($importedAnnotation['ranges'] ?? null) ? $importedAnnotation['ranges'] : []); | ||
|
|
||
| return $annotation; |
There was a problem hiding this comment.
Also, maybe you can force the created/updated at so it won't be lost after import
Following review: - an annotation with an empty text is legitimate (a highlight without a note), so only skip entries which have no `text` key at all; - restore `created_at` / `updated_at` from the imported file instead of stamping them with the import date. `EntityTimestampsTrait` now only fills `updated_at` on insert when it wasn't set, the same way it already did for `created_at`, so an explicit date survives the `prePersist` callback; - annotation dates were not part of the JSON export (they carry no serialization group), so add them, otherwise there is nothing to restore when re-importing a wallabag export.
|
Good catch on the empty note, applied your suggestion. For the dates: One thing I ran into: the annotation dates aren't in the JSON export at all — they have no serialization group, so |
Wallabag JSON exports include an
annotationsarray for every entry, but the wallabag importers only readurl,title,tags, etc. and silently dropped the annotations. Re-importing an export therefore lost every highlight/note.This parses the
annotationskey inWallabagImport::parseEntry()and recreates eachAnnotation(text, quote, ranges) attached to the imported entry and the current user, following the same flow asAnnotationController::postAnnotationAction().Entry::$annotationsis now initialized in the constructor (like$tags) so a freshly created entry exposes a proper collection.Added a unit test (
testImportWithAnnotations) with a dedicated fixture (80 tests / 405 assertions pass acrosstests/unit/Import+EntryTest); the existing wallabag-v2 fixtures (annotations empty) are unaffected. php-cs-fixer clean.Note: imported annotations currently receive an import-time
created_at(the entity has nocreatedAtsetter); happy to preserve original dates if preferred.Fixes #8643
Disclosure: prepared with AI assistance (Claude); authored/verified by me. Tests and php-cs-fixer run locally and pass.