Documentation

Restore
in package

Database restore and truncation operations.

Tags
since
3.0.0

Table of Contents

Methods

restoreFile()  : string
Restore the database from a file.
truncateUserDatabase()  : void
Truncate the database, remove all data belonging to the current user.
dropAllLwtTables()  : void
Drop all LWT tables to prepare for a clean restore.
rewriteRestoredUsIdsToCurrentUser()  : void
Reassign all restored content to the current admin in multi-user mode.
truncateAllUsersData()  : void
Delete every row across the eleven content tables.
truncateForUser()  : void
Delete every content row owned by `$userId`.
truncateUserPostHook()  : void
Common cleanup after a truncate (whether scoped to a user or not).
validateMultiUserRestoreContext()  : string|null
Refuse the restore when more than one user lives on this install.

Methods

restoreFile()

Restore the database from a file.

public static restoreFile(resource $handle, string $title[, bool $validateSql = true ]) : string
Parameters
$handle : resource

Backup file handle

$title : string

File title

$validateSql : bool = true

Whether to validate SQL statements (default true)

Tags
since
2.0.3-fork

Function was broken

since
2.5.3-fork

Function repaired

since
2.7.0-fork

$handle should be an uncompressed file.

since
2.9.1-fork

It can read SQL with more or less than one instruction a line

since
3.0.0

Added SQL validation for security hardening

Return values
string

Human-readable status message

truncateUserDatabase()

Truncate the database, remove all data belonging to the current user.

public static truncateUserDatabase() : void

In multi-user mode with an authenticated user, only that user's rows are deleted (across the 11 content tables, plus the per-user currenttext setting). Single-user installs keep the legacy "wipe everything" behaviour. Settings are kept.

dropAllLwtTables()

Drop all LWT tables to prepare for a clean restore.

private static dropAllLwtTables() : void

This is needed to ensure migrations run on a clean slate and don't fail due to partial state from previous attempts.

rewriteRestoredUsIdsToCurrentUser()

Reassign all restored content to the current admin in multi-user mode.

private static rewriteRestoredUsIdsToCurrentUser() : void

restoreFile runs after the multi-user guard above, so when this fires we know the install has at most one real account. Rewrite every UsID column on the user-scoped tables to that account so the freshly-loaded rows are visible — backups from a different install or made before multi-user mode existed otherwise carry UsIDs that don't correspond to any local user. Safe to no-op when no current user is set (single-user mode reaches the same behaviour by skipping the rewrite entirely).

truncateAllUsersData()

Delete every row across the eleven content tables.

private static truncateAllUsersData() : void

Order matters: child tables with FKs to multiple parents go first, then the parent tables. Used in single-user mode and as the destructive base step of restoreFile() (which then loads a new dump on top of the empty schema).

truncateForUser()

Delete every content row owned by `$userId`.

private static truncateForUser(int $userId) : void

The link/map/derived tables don't carry a UsID column of their own, so they're scoped via a subquery on the parent table (texts / words / news_feeds). FK CASCADE would handle most of these implicitly — explicit deletes guarantee the same result on schemas where the cascade is missing or disabled.

Parameters
$userId : int

Owner UsID

truncateUserPostHook()

Common cleanup after a truncate (whether scoped to a user or not).

private static truncateUserPostHook(int|null $_userId) : void

Optimises tables and clears the in-process tag caches so the next page load doesn't return ghost tag names.

Parameters
$_userId : int|null

Reserved for future per-user cache busting

validateMultiUserRestoreContext()

Refuse the restore when more than one user lives on this install.

private static validateMultiUserRestoreContext() : string|null

Returning a non-null string aborts restoreFile early. Single-user installs always pass. The check looks at the users table because BACKUP_RESTORE_ENABLED=true may have been set by an admin who understood the single-user case but didn't realise the dump+drop step nukes every account.

Return values
string|null

Error message to surface, or null when safe


        
On this page

Search results