SQL runner and maintenance: gates, undo log, clean-up

Rules of the SQL runner's read and update gates, the undo log, saved queries and logging, and the steps and safeguards of clearing the cache and temporary files.

The SQL runner and the maintenance clear are technical tools for the super administrator. Every endpoint is gated solely by isSuper(); the controller does not check the catalogue key system/sqlrunner + list, so assigning it grants no access.

Data model

Table names carry the installation's own prefix in the database.

TableRole
sqlrunner_querysaved queries (name, text)
sqlrunner_undoundo log: table, affected rows, original values, state (applied, restored)

Reading from any table; changes only on tables with the installation's prefix.

Gates

  1. sqlrunner.run, read gate: comments stripped, forbidden keywords, multiple statements refused; allowed: SELECT, WITH, SHOW, DESCRIBE, EXPLAIN; enforced limit of 500 rows; result list and full copyable result.
  2. Update gate (UPDATE): one table with the installation prefix, required WHERE, simple SET columns, at most 2000 rows. Without confirmation it only counts; with confirm=1 it saves the original values in a transaction and runs; success with an undo entry read back.
  3. sqlrunner.undolist (50 entries), sqlrunner.undorestore: active entries only; rows changed or deleted since are named.
  4. sqlrunner.queries, savequery (new or overwrite, read back), deletequery.

Every run, successful or rejected, goes to the system log and the framework's error log; updates with a masked statement.

Maintenance clear

maintenance.clear (header broom, isSuper() only, no own key):

  1. framework cache, template cache, query cache files, OPcache;
  2. the module's temporary files and the backups' work folders: only files older than 6 hours are removed; partial files of open uploads and the work directory of running iPhone backups are protected (the protected list comes from the backup/iphonebackup model); if the protected list cannot be read, nothing is cleaned.

Reply: removed counts, freed bytes, kept files; a log line.

Permissions

Super administrator only; other users get the no-permission page for the SQL runner. The menu item is also shown to the super administrator only.

Related topics: sql query cache log