Add Phase 3: account-level import #560
No reviewers
Labels
No labels
antville.org
bug
compatibility
dependency
duplicate
enhancement
help wanted
invalid
java
javascript
major
needs feedback
needs work
no-issue-activity
runtime
security
urgent
usability
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
antville/antville!560
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "phase3-account-import"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on #559 — Phase 3, the last phase of the importer rewrite: account-level import (
Importer.restoreAccount), completing what #557/#558/#559 built for sites.What's here
Exporter.saveAccountgets the same per-export HMAC key +accounts.jsonmechanismsaveSitealready had (PR #558) — without it,Importer.previewwould have nothing to match against for an account export, and every creator/modifier would fall back to a placeholder.Importer.restoreSite's per-entity logic (skins, stories, comments, images, files, polls, votes, tags, memberships) into sharedImporter.restore*(rows, ctx)functions, parameterized by an asset-path prefix —saveSitezips assets understatic/..., butsaveAccountzips them under<originalSiteName>/...instead, so the same restore logic needs to know which convention it's reading back.Importer.restoreAccount(user, tempDir, accountMap)loops those same functions over every site the account owned (persites.json'srolecolumn — sites where the account was only a subscriber/contributor never had their metadata exported at all, so they're skipped, not recreated, since there's nothing to restore and re-creating someone else's site wouldn't make sense anyway). Site names may already be taken (restoring into the same instance the export came from, or an unrelated collision), so creation retries with a numbered suffix rather than dropping the site. A poll's own single vote (allsaveAccountever exports — no separatevotes.json, unlike a site export) is replayed directly by the sharedrestorePollsfunction instead of a separate step.User.prototype.import_actionmirrorsSite's own two-step preview/confirm flow, reusingImporter.preview/mergeOverrides/renderReviewHtmlunchanged (the last one moved fromSitetoImporter, since both prototypes need it now). UnlikeSite,Userhas no naturalfilescollection to attach an uploaded archive to, so the upload handling followsLayout.prototype.import_action's simpler precedent instead (straight to a plain temp file, noFileobject at all).Members.prototype.import_actionproxy, plus adding'import'to the samegetPermissioncase listexport/editalready use — confirmed live that "act on your own account" only works through an explicit per-action proxy toUser.prototype.<action>.call(session.user), there's no generic passthrough.A Phase 1 bug this testing happened to expose
While testing this, found that
image.setMetadata(row.metadata)/file.setMetadata(row.metadata)inImporter.restoreImages/restoreFiles(from PR #558) were re-applying the export's oldfileName/contentType/etc. right afterImage.add/File.add's ownupdate()had already correctly regenerated those exact fields from the actual re-uploaded bytes — silently overwriting the fresh, correct value with one that doesn't exist on disk under the new site, so every restored image/file 404s. That's a Phase 1 bug, not something Phase 3 introduced, so the fix lives in its own commit onnative-site-restore(now merged into this stack) rather than bundled here — see PR #558 for detail. Caught by exporting and re-importing an account owning many sites: the same file, restored independently into several different sites across earlier test runs, ended up with every one of those distinctFilerows sharing the literal samefileNamein the metadata table despite genuinely different bytes on disk under each site.Verified end-to-end (ct 3998, see
~/.claude/plans/kind-sauteeing-goblet.md)admin's full account (11 owned sites, including a duplicate row and several already-taken names) and re-imported it into the same account: every site was recreated under a de-conflicted name (-imported-Nsuffix) with its content restored, exercising the collision-retry path thoroughly.fileNamecorrectly matches what's actually on disk, and is byte-identical to the source.Known gaps
tools/antclick), not the MariaDB path production actually runs.saveAccountdoesn't export either) — acceptable, not a bug: tags aren't meaningfully scoped to one creator, and the only membership that matters (the owner) is already established when each site is created.Test plan
Update: cross-account attribution now actually tested
The original test only ever restored
admin's own export back intoadminitself — genuine cross-account restore (into a different, pre-existing target account) was untested. Fixed that: registered a second real account (seconduser, via a scoped SQL toggle ofroot.loginScopethen reverted, and grantedPRIVILEGEDstatus the same way —site.getPermission('import')requires it regardless of ownership, a gap the original plan flagged but never resolved, worth a separate decision), then logged in asseconduserand importedadmin's account export.Confirmed via direct DB query: every newly-created site is owned by
seconduser(correct — they triggered the restore), but the actual content underneath is attributed toadmin(the only distinct creator across all of it) — original authorship is correctly preserved via name+e-mail matching, not collapsed onto whoever performs the restore. Same result confirmed for a site-level cross-account import too (PR #558's mechanism).The previous fix retried User.add inside a try/catch after a collision, but User.add's user.map({...}) persists the account row immediately — before the later root.users.add(user) collision check even runs. That left a stray, unblocked, orphaned account behind for every name it had to give up on. Verified via a live re-import: the try/catch version left 'macnearney'/'sandy' duplicate rows (status regular, not blocked) next to the correctly-created 'macnearney-imported-1'/'sandy-imported-1' placeholders. Checking User.getByName first avoids ever calling User.add with a name that's going to collide.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.