MySqlBackupRepository
in package
implements
BackupRepositoryInterface
MySQL repository for backup operations.
Provides database access for backup/restore functionality.
Tags
Table of Contents
Interfaces
- BackupRepositoryInterface
- Repository interface for backup operations.
Constants
- BACKUP_TABLES = ['feed_links', 'languages', 'word_occurrences', 'news_feeds', 'sentences', 'settings', 'tags', 'text_tags', 'texts', 'text_tag_map', 'words', 'word_tag_map']
- Tables to include in backup.
- OFFICIAL_BACKUP_TABLES = ['languages', 'sentences', 'settings', 'tags', 'text_tags', 'word_occurrences', 'texts', 'text_tag_map', 'words', 'word_tag_map']
- Tables for official LWT backup format.
Methods
- generateBackupSql() : string
- Get backup SQL for all tables.
- generateOfficialBackupSql() : string
- Get official LWT format backup SQL.
- getBackupTables() : array<string|int, string>
- Get list of tables to backup.
- getDatabaseName() : string
- Get the database name.
- getOfficialBackupTables() : array<string|int, string>
- Get list of tables for official backup format.
- restoreFromHandle() : string
- Restore database from a file handle.
- truncateUserTables() : void
- Truncate all user data tables (keep settings).
- buildScopedSelectAll() : string
- Build a `SELECT * FROM <table>` filtered to the current user's data.
- getOfficialTableSchema() : string
- Get the official table schema for a given table.
- officialBackupUserScope() : array<string, string>
- Build the per-table WHERE-clause suffix for the official backup.
Constants
BACKUP_TABLES
Tables to include in backup.
private
array<string|int, string>
BACKUP_TABLES
= ['feed_links', 'languages', 'word_occurrences', 'news_feeds', 'sentences', 'settings', 'tags', 'text_tags', 'texts', 'text_tag_map', 'words', 'word_tag_map']
OFFICIAL_BACKUP_TABLES
Tables for official LWT backup format.
private
array<string|int, string>
OFFICIAL_BACKUP_TABLES
= ['languages', 'sentences', 'settings', 'tags', 'text_tags', 'word_occurrences', 'texts', 'text_tag_map', 'words', 'word_tag_map']
Methods
generateBackupSql()
Get backup SQL for all tables.
public
generateBackupSql() : string
Return values
string —SQL dump content
generateOfficialBackupSql()
Get official LWT format backup SQL.
public
generateOfficialBackupSql() : string
Return values
string —SQL dump in official format
getBackupTables()
Get list of tables to backup.
public
getBackupTables() : array<string|int, string>
Return values
array<string|int, string> —Table names
getDatabaseName()
Get the database name.
public
getDatabaseName() : string
Return values
string —Database name
getOfficialBackupTables()
Get list of tables for official backup format.
public
getOfficialBackupTables() : array<string|int, string>
Return values
array<string|int, string> —Table names
restoreFromHandle()
Restore database from a file handle.
public
restoreFromHandle(mixed $handle, string $fileName) : string
Parameters
- $handle : mixed
-
File handle to read from
- $fileName : string
-
File name for logging
Return values
string —Status message
truncateUserTables()
Truncate all user data tables (keep settings).
public
truncateUserTables() : void
buildScopedSelectAll()
Build a `SELECT * FROM <table>` filtered to the current user's data.
private
buildScopedSelectAll(string $table) : string
In single-user mode (or when no user is authenticated) the SELECT is unfiltered, matching legacy behaviour. In multi-user mode it returns only rows owned by the caller — directly via the table's UsID column for user-scoped tables, or via a subquery on the parent table for link/map tables that don't carry their own owner column.
Parameters
- $table : string
-
Table name from BACKUP_TABLES.
Return values
string —SQL string ready for Connection::querySelect.
getOfficialTableSchema()
Get the official table schema for a given table.
private
getOfficialTableSchema(string $table) : string
Parameters
- $table : string
-
Table name
Return values
string —SQL CREATE TABLE statement
officialBackupUserScope()
Build the per-table WHERE-clause suffix for the official backup.
private
officialBackupUserScope() : array<string, string>
Single-user (or unauthenticated) installs get empty suffixes,
preserving legacy behaviour. Multi-user installs get an AND … = ?
fragment for the languages SELECT (which already has a base WHERE)
and a fresh WHERE … fragment for everything else, indirect link
tables included.
Return values
array<string, string> —Per-table SQL suffix keyed by OFFICIAL_BACKUP_TABLES name.