Skip to content

Add restoreDeletedCategory.php script for comprehensive category restoration#13926

Open
MosheMaorKaltura with Copilot wants to merge 5 commits into
Venus-22.18.0from
copilot/restore-deleted-category-relations
Open

Add restoreDeletedCategory.php script for comprehensive category restoration#13926
MosheMaorKaltura with Copilot wants to merge 5 commits into
Venus-22.18.0from
copilot/restore-deleted-category-relations

Conversation

Copilot AI commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Please complete the following before submitting:

General notes -

  • I have tested the changes locally.
  • I have written unit tests where applicable.
  • I have updated documentation where needed.
  • I have added comments to complex code.
  • This PR follows the coding style guidelines.
  • I have updated release notes with new feature

New Kaltura Types

  • I have created new clients
  • I have notified related apps - KMCNG / KMS / EP .... about new clients

New Kaltura Services / Actions

  • I have added a deployment script

Questions

  1. What is the purpose of this PR?

    • Adds a utility script to restore a deleted category and all related data lost during deletion (child categories, entry associations, user memberships, hierarchy fields, counts).
  2. Does this change affect production code or infrastructure?

    • Yes
    • No
  3. If yes, what is the rollback plan?

    • Script is additive only. Remove alpha/scripts/utils/restoreDeletedCategory.php to rollback. If executed with realrun, restored records would need manual re-deletion.

Summary

New script restoreDeletedCategory.php performs full category restoration based on getDeletedAt() timestamp matching.

What it restores

  • Category hierarchy: Main category + child categories (recursive, depth-ordered)
  • Category entries: categoryEntry records deleted within time delta
  • Category users: categoryKuser records for InheritanceType::MANUAL categories only
  • Hierarchy fields: reSetFullIds(), reSetDepth(), reSetFullName()
  • Counts: entries, direct entries, members, pending members, sub-categories
  • Search index: Triggers indexToSearchIndex() for all restored categories
  • Parent updates: Updates parent category's directSubCategoriesCount

Usage

php restoreDeletedCategory.php <categoryId> [realrun|dryrun] [timeDeltaSeconds]

# Preview
php restoreDeletedCategory.php 12345 dryrun

# Execute with 120s time window
php restoreDeletedCategory.php 12345 realrun 120

Key implementation details

  • Time-based matching via deleted_at/updated_at within configurable delta (default 60s)
  • LIKE pattern escaped to prevent SQL injection on FULL_IDS prefix matching
  • Batch processing with configurable sizes to manage memory
  • Dry run mode for safe preview before execution

Copilot AI and others added 5 commits April 19, 2026 05:49
…nd their relations

Agent-Logs-Url: https://github.com/kaltura/server/sessions/07c7b26d-48dc-494f-b8d7-7c07b76b860c

Co-authored-by: MosheMaorKaltura <10695851+MosheMaorKaltura@users.noreply.github.com>
Agent-Logs-Url: https://github.com/kaltura/server/sessions/07c7b26d-48dc-494f-b8d7-7c07b76b860c

Co-authored-by: MosheMaorKaltura <10695851+MosheMaorKaltura@users.noreply.github.com>
Agent-Logs-Url: https://github.com/kaltura/server/sessions/07c7b26d-48dc-494f-b8d7-7c07b76b860c

Co-authored-by: MosheMaorKaltura <10695851+MosheMaorKaltura@users.noreply.github.com>
- Restore child categories recursively (ordered by depth)
- Restore categoryKuser only for MANUAL inheritance categories
- Rebuild hierarchy fields (reSetFullIds, reSetDepth, reSetFullName)
- Recalculate all counts (entries, directEntries, members, subCategories)
- Update parent category's sub-categories count
- Trigger re-indexing for search

Agent-Logs-Url: https://github.com/kaltura/server/sessions/65e08e9e-09d8-48f6-8b43-4cda3ceae986

Co-authored-by: MosheMaorKaltura <10695851+MosheMaorKaltura@users.noreply.github.com>
…imize batch queries

Agent-Logs-Url: https://github.com/kaltura/server/sessions/65e08e9e-09d8-48f6-8b43-4cda3ceae986

Co-authored-by: MosheMaorKaltura <10695851+MosheMaorKaltura@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants