Skip to content

Feat/content maintenance tools#26

Open
Z4phxr wants to merge 3 commits into
mainfrom
feat/content-maintenance-tools
Open

Feat/content maintenance tools#26
Z4phxr wants to merge 3 commits into
mainfrom
feat/content-maintenance-tools

Conversation

@Z4phxr

@Z4phxr Z4phxr commented Jun 16, 2026

Copy link
Copy Markdown
Owner

This pull request introduces several improvements and new features to the admin media management functionality, enhances flashcard deck deletion handling, and refactors media usage logic for better performance and maintainability. The most important changes are grouped below:

Media Usage Analysis and Management Enhancements:

  • Refactored media usage logic by removing the inlined usage analysis from admin/media/page.tsx and delegating it to shared utilities in @/lib/media-usage, improving maintainability and performance. Now, usage stats (including a new flashcardsCount) are fetched for all visible media at once using getMediaUsageForIds, and utility functions like isMediaInUse and mediaUsageTotal are used throughout the UI. [1] [2] [3] [4] [5] [6] [7] [8]
  • Added a new admin action to bulk-delete all unused media files (deleteAllUnusedMedia) and a corresponding UI button (MediaDeleteUnusedButton), allowing admins to efficiently clean up unused uploads. [1] [2]
  • Implemented a new admin action (countUnusedMedia) to count unused media files, supporting bulk deletion and reporting.

Flashcard Deck Deletion Improvements:

  • Enhanced the admin flashcard deck deletion logic to also remove all subdecks and associated flashcards from the UI state when a main deck is deleted, ensuring consistency and preventing orphaned UI elements.

API and Performance Improvements:

These changes collectively improve the admin experience for managing media, ensure data consistency, and streamline code for future maintenance.

Z4phxr added 2 commits May 17, 2026 21:15
…enhance media usage tracking

- Introduced `MediaDeleteUnusedButton` component for bulk deletion of unused media files.
- Implemented `countUnusedMedia` and `deleteAllUnusedMedia` functions to facilitate media management.
- Enhanced media usage tracking by adding `flashcardsCount` to the `MediaUsage` interface and updating related logic.
- Updated `AdminMediaPage` to utilize new media usage functions for improved performance.
- Added scripts for wiping content in Docker and Prisma, ensuring a clean state for development.
…s, tags, and flashcards

- Added new export scripts for courses, tags, and flashcards, enabling users to back up and migrate content.
- Introduced helper functions for exporting course structures and flashcard decks, ensuring compatibility with import processes.
- Updated documentation to include new export commands and usage instructions.
- Enhanced existing scripts to support dry-run and output directory options for better user control during exports.
Copilot AI review requested due to automatic review settings June 16, 2026 09:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the LearningPlatform’s content maintenance and admin tooling by adding export/wipe scripts, improving flashcard deck deletion consistency, and refactoring admin media usage analysis into shared utilities (including flashcard media usage).

Changes:

  • Added content maintenance scripts: export runners (tags/courses/flashcards + export-all) and destructive wipe tooling (TS/SQL + Docker helper), with documentation updates.
  • Refactored admin media usage analysis into lib/media-usage.ts, added flashcard media usage counting, and introduced “delete all unused media” admin UI/action.
  • Improved flashcard deck deletion behavior (DB cascade for flashcards, API cache revalidation, and client-side state cleanup when deleting main decks).

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
LearningPlatform/test/api/flashcard-decks-and-summary.test.ts Updates tests to mock/assert cache revalidation on deck deletion.
LearningPlatform/scripts/wipe-content.ts Adds a TS runner to wipe CMS course content + Prisma flashcards/progress (guarded by confirmation).
LearningPlatform/scripts/wipe-content.sql Adds SQL wipe script for Docker/Postgres to truncate content-related tables.
LearningPlatform/scripts/wipe-content-docker.ps1 Adds a PowerShell helper to run the SQL wipe against the Docker DB container.
LearningPlatform/scripts/imports/runners/export-tags.js Adds tag export runner (supports “used tags only”).
LearningPlatform/scripts/imports/runners/export-flashcards.js Adds flashcard decks/cards export runner.
LearningPlatform/scripts/imports/runners/export-courses.js Adds course export runner from Payload, including structure/media references.
LearningPlatform/scripts/imports/runners/export-all.js Adds a convenience runner to export tags → courses → flashcards.
LearningPlatform/scripts/imports/helpers/flashcard-export.js Adds helper to build import-shaped flashcard export payloads and used-tag collection.
LearningPlatform/scripts/imports/helpers/export-utils.js Adds shared export utilities (arg parsing, safe filenames, JS export writer, media mapping, etc.).
LearningPlatform/scripts/imports/helpers/course-export.js Adds course structure exporter (subjects/course/modules/lessons/tasks) from Payload.
LearningPlatform/prisma/schema.prisma Changes Flashcard→Deck FK to onDelete: Cascade.
LearningPlatform/prisma/migrations/20260517120000_flashcard_deck_cascade_delete/migration.sql Adds migration to enforce DB-level cascade delete for flashcards by deck.
LearningPlatform/package.json Adds npm scripts for content export and wipe workflows.
LearningPlatform/lib/media-usage.ts Introduces shared media usage utilities (including flashcard media references) with caching.
LearningPlatform/documentation/CONTENT_IMPORTS.md Documents export workflows and re-import steps.
LearningPlatform/components/admin/media-delete-unused-button.tsx Adds UI button to count and bulk-delete unused media.
LearningPlatform/app/api/flashcard-decks/[id]/route.ts Adds cache tag revalidation after deck deletion.
LearningPlatform/app/(admin)/admin/media/page.tsx Refactors to use shared media-usage helpers; adds “delete unused” button; shows flashcard usage count.
LearningPlatform/app/(admin)/admin/flashcards/admin-flashcards-client.tsx Improves client state cleanup when deleting a main deck (also removes subdecks/cards from UI state).
LearningPlatform/app/(admin)/admin/actions/media.ts Adds countUnusedMedia + deleteAllUnusedMedia admin actions and supporting media ID enumeration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +51 to +60
const payload = tags.map((t) => ({
name: t.name,
slug: t.slug,
...(t.main ? { main: true } : {}),
}))

writeJsExport(path.join(tagsDir, 'exported-tags.js'), payload, { dryRun: opts.dryRun })
console.log(`[INFO] Exported ${payload.length} tag(s)`)
await disconnect()
return 0
Comment on lines +55 to +67
const getCachedLessonsTasksCourses = unstable_cache(
async () => {
const payload = await getPayload({ config })
const [lessonsResult, tasksResult, coursesResult] = await Promise.all([
payload.find({ collection: 'lessons', limit: 1000, depth: 0 }),
payload.find({ collection: 'tasks', limit: 5000, depth: 1 }),
payload.find({ collection: 'courses', limit: 500, depth: 0 }),
])
return { lessons: lessonsResult.docs, tasks: tasksResult.docs, courses: coursesResult.docs }
},
['admin-media-usage-data-v2'],
{ revalidate: 30 },
)
…dles

- Introduced `ContentBundleImportPanel` component for importing course bundles, allowing users to manage course content more efficiently.
- Added `CourseExportButton` component for exporting courses as bundles, including associated media and metadata.
- Implemented backend logic for zipping and importing course bundles, enhancing content sharing capabilities.
- Updated documentation to include instructions for using the new import/export features and bundle structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants