fix: A1-2 delete translation files from disk when parent post is deleted
This commit is contained in:
@@ -11,7 +11,7 @@ Gap categories: **SC** = spec correct, fix code | **CS** = code correct, update
|
||||
| ID | Gap | Spec | Code | Path |
|
||||
|---|---|---|---|---|
|
||||
| A1-1 | ~~No `archived→draft` or `archived→published` transition~~ | post.allium:121-122 | `unarchive_post/1` implemented, `publish_post` already handled archived→published | **Resolved:** `unarchive_post/1` in posts.ex restores content from disk, UI wired via quick actions, 4 tests added |
|
||||
| A1-2 | `DeletePost` must delete translations + translation files | post.allium:209-212 | `delete_post/1` skips translation cleanup | Fix code: delete PostTranslation rows + files |
|
||||
| A1-2 | ~~`DeletePost` must delete translations + translation files~~ | post.allium:209-212 | `delete_post/1` now fetches translations before cascade-delete and removes their files from disk | **Resolved:** translation file cleanup added to `delete_post/1` in posts.ex, test added |
|
||||
| A1-3 | Publish must delete old file when path changes | engine_side_effects.allium:73-74 | `publish_post` does not delete old file | Fix code: add old file deletion on path change |
|
||||
| A1-4 | `doNotTranslate: false` written to frontmatter despite "only when true" | frontmatter.allium:398 | `lib/bds/frontmatter.ex:38-39` writes false | Fix code: omit `doNotTranslate` when false |
|
||||
| A1-5 | Auto-save after 3000ms idle | editor_post.allium:183-188 | No auto-save timer | Fix code: implement auto-save on idle + unmount + tab switch |
|
||||
|
||||
@@ -309,8 +309,11 @@ defmodule BDS.Posts do
|
||||
select: pm.media_id
|
||||
)
|
||||
|
||||
{:ok, translations} = Translations.list_post_translations(post.id)
|
||||
|
||||
case Repo.delete(post) do
|
||||
{:ok, deleted_post} ->
|
||||
Enum.each(translations, &FileSync.delete_translation_file/1)
|
||||
delete_post_file(deleted_post)
|
||||
Embeddings.remove_post(deleted_post.id)
|
||||
PostLinks.delete_post_links(deleted_post.id)
|
||||
|
||||
@@ -228,6 +228,43 @@ defmodule BDS.PostsTest do
|
||||
assert {:error, :not_found} = BDS.Posts.delete_post(post.id)
|
||||
end
|
||||
|
||||
test "delete_post deletes translation records and their files from disk" do
|
||||
temp_dir =
|
||||
Path.join(System.tmp_dir!(), "bds-post-del-trans-#{System.unique_integer([:positive])}")
|
||||
|
||||
File.mkdir_p!(temp_dir)
|
||||
on_exit(fn -> File.rm_rf(temp_dir) end)
|
||||
|
||||
assert {:ok, project} =
|
||||
BDS.Projects.create_project(%{name: "DelTrans", data_path: temp_dir})
|
||||
|
||||
assert {:ok, post} =
|
||||
BDS.Posts.create_post(%{
|
||||
project_id: project.id,
|
||||
title: "Parent Post",
|
||||
content: "Body"
|
||||
})
|
||||
|
||||
assert {:ok, translation} =
|
||||
BDS.Posts.upsert_post_translation(post.id, "de", %{
|
||||
title: "Elternbeitrag",
|
||||
content: "Inhalt"
|
||||
})
|
||||
|
||||
assert {:ok, _published} = BDS.Posts.publish_post(post.id)
|
||||
|
||||
published_translation = BDS.Posts.get_post_translation!(translation.id)
|
||||
translation_path = Path.join(temp_dir, published_translation.file_path)
|
||||
assert File.exists?(translation_path)
|
||||
|
||||
assert {:ok, :deleted} = BDS.Posts.delete_post(post.id)
|
||||
|
||||
assert BDS.Repo.get(BDS.Posts.Post, post.id) == nil
|
||||
assert {:ok, []} = BDS.Posts.list_post_translations(post.id)
|
||||
|
||||
refute File.exists?(translation_path)
|
||||
end
|
||||
|
||||
test "delete_post returns not_found for nonexistent post" do
|
||||
assert {:error, :not_found} = BDS.Posts.delete_post(Ecto.UUID.generate())
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user