Documentation

DbToolsController extends Controller
in package

Provides tools for dealing with the database Tools include a sync tool and a structure viewer

Table of Contents

Constants

ALLOW_PRODUCTION  : mixed = TRUE

Properties

$tools  : mixed
List of tools to show in the sidebar and index view
$action_log  : mixed
Should this controller log add/edit/delete actions?
$module_builder_type_guess  : mixed
For a given field name, a type to use which is better than VARCHAR(200)
$template_enabled  : mixed

Methods

__call()  : void
Handles methods that do not exist.
__construct()  : void
Constructor
_run()  : mixed
The router/kohana will invoke this method to invoke an action.
ajaxPageIds()  : void
Render page drop-down for given sub-site
ajaxTableDefn()  : mixed
api()  : void
Render API test form within DB tools
bcryptSpeed()  : mixed
Benchmark the server to find appropriate cost parameter
clearMediaCache()  : void
Force a clear out of the media cache
email()  : mixed
Renders form to send emails
emailSend()  : mixed
Process form submission
exceptionDetail()  : mixed
Browse recent exceptions - details
exceptionLog()  : mixed
Browse and search exceptions
exceptionTest()  : mixed
Test exception handling.
exportAction()  : void
Does the actual export
exportFiles()  : mixed
UI to export all files
exportFilesAction()  : mixed
Action to export all files
exportTables()  : mixed
Export tables to an SQL file
fileBackendMigrate()  : void
Tool to move any files not on the current backend type, to it
fileTypesIndexingSupport()  : mixed
Returns a list of file types which can be indexed for fulltext search
findReplace()  : void
Render a form for performing text find/replace across all CMS content.
findReplaceView()  : void
Find/replace form for a single doomtool instance.
generateModel()  : string
Generate a PHP model file from a PdbTable object
generatePasswordHash()  : mixed
Generate a password hash to store in a config file The username and hash are used by {@see AdminAuth::processLocal}
getAbsModulePath()  : string
Get the absolute path of the current module for this controller.
getCssClassName()  : string
Return the class name for this controller, expressed in CSS style, i.e. with dashes
getModule()  : ModuleInterface|null
Get the module that this controller belongs to.
getModulePath()  : string
Get the a prefix suitable for finding views for this controller.
gettempfile()  : mixed
Allows files to be downloaded from the temporary directory
importAction()  : mixed
Action for importing tables
importFileAction()  : mixed
Action for importing files
importFiles()  : mixed
Imports a files into the cms
importOptions()  : mixed
importSave()  : mixed
importTables()  : mixed
Import database tables from a .sql file
importXML()  : void
Renders form to imoprt Sprout2 Export XML
importXmlAction()  : void
Process Sprout2 Export XML into this CMS
index()  : mixed
Shows a list of database tools
info()  : mixed
Output some sprout and platform info
launchChecks()  : mixed
Run a series of self-tests to ensure everything is configured correctly
listRoutes()  : void
Render table of routes
modelGenerator()  : mixed
Generate a model file from a table.
moduleBuilder()  : mixed
Generates blank modules
moduleBuilderAction()  : mixed
moduleBuilderDb()  : mixed
Generates db_struct.xml content for a module
moduleBuilderExisting()  : mixed
Generates modules from an existing db_struct.xml file
moduleBuilderExistingAction()  : mixed
Generates modules from an existing db_struct.xml file
moduleBuilderExistingForm()  : mixed
Generates modules from an existing db_struct.xml file
moduleBuilderExistingModelAction()  : mixed
Generate and download a PHP Model file based on a DB struct XML file
moduleBuilderExistingUploadAction()  : mixed
Generates modules from an existing db_struct.xml file
modules()  : void
Inspect module information.
mtTransform()  : mixed
Used by the module_template_action method
multimake()  : mixed
Generate multiedit code
openAiDebugOutput()  : void
Render out the debug output based on the type requested
openAiImageOutputBlob()  : void
Render out n image blob response
openAiImageOutputSrc()  : void
Render out n image URL response
openAiLastRequestOutput()  : void
Render out the last request made to Open AI
openAiLastTokensOutput()  : void
Render out the tokens used in the last request
openAiList()  : void
Render a list of items stored with Open AI for a given type
openAiListAction()  : never
List all items for a given type
openAiPurge()  : never
Trigger a delete-all for a given type
openAiTest()  : mixed
Simple test tools for working out Open AI tooling using the client's keys
openAiTestSubmit()  : void
Pass a request to Open AI API and render out the result accordingly
openAiTextOutput()  : void
Render out a text response
openAiTools()  : void
Render a list of tools for managing OpenAI
processAiContentQueue()  : never
Fire the job to process AI Content form the queue
profilingLog()  : mixed
View profiling logs.
profilingLogItem()  : mixed
View a single profile log item.
profilingLogSessionOverride()  : mixed
Update the session override for profiling.
sessionEditor()  : mixed
Edit the $_SESSION
sessionEditorAction()  : mixed
Session Editor Action
sql()  : mixed
Allows the user to execute SQL queries
sqlcsv()  : mixed
struct()  : mixed
Shows table and column definitions
sync()  : mixed
Syncs the db structure to match db_struct.xml
testSkinTemplates()  : void
Simple tool for testing skin templates
testSkinTemplatesAction()  : void
Actual viewing UI for templates
varDump()  : void
Render view to see session and cookie data
autoSetEmptyParam()  : void
Auto-set the "empty" param for fields with foreign keys to be NULL
deleteRecord()  : int
Deletes a record, and logs the deletion This should be used by all _deleteSave methods Starts a transaction and commits it if not already in a transaction when called
findReplaceAction()  : void
Doom tool actions.
generateFormView()  : PhpView
Generates a form view from a JSON config file
jsonExtraValidate()  : void
Do any additional validation prior to saving the record
loadEditJson()  : array<string, array<string|int, array<string, mixed>>>
Loads a JSON config file for an automated edit-type form for this controller
loadFormJson()  : array<string|int, mixed>
Loads a config file for a JsonForm associated with this controller
loadRecord()  : array<string|int, mixed>|bool
Fetches the pre-update record from the database.
logAction()  : int
Stores a history item in the database, recording an add (i.e. insert), edit, or delete.
logAdd()  : int
Logs an add action. This is a wrapper for {@see Controller::logAction}
logAddCategory()  : int
Logs the adding of a record to a category. This is a wrapper for {@see Controller::logAction}
logDelete()  : int
Logs a delete action. This is a wrapper for {@see Controller::logAction}
logDeleteCategory()  : int
Logs the removal of a record from a category. This is a wrapper for {@see Controller::logAction}
logEdit()  : int
Logs an edit action. This is a wrapper for {@see Controller::logAction}
replaceSet()  : void
Inserts records which are in $new_records, but are not in the specified table Deletes records which are in the specified table, but not in $new_records Updates records which are in both
saveJsonData()  : bool
Automatically saves the data associated with a submission on a JSON-generated form
outputSqlResultset()  : int
Renders SQL result set into a table
sessionLoop()  : mixed
List items in an array, along with the tools buttons
sizeToHuman()  : string
Render table data size in human readable form
splitSql()  : mixed
Splits a set of SQL queries into individual queries
template()  : void
Render dbtools template
xmlGetColumns()  : array<string|int, mixed>
xmlGetTables()  : array<string|int, mixed>
xmlLoad()  : mixed

Constants

Properties

$tools

List of tools to show in the sidebar and index view

public static mixed $tools = ['Development' => [['url' => 'dbtools/sql', 'name' => 'SQL', 'desc' => 'Allows the user to execute SQL queries'], ['url' => 'dbtools/sync', 'name' => 'Database sync', 'desc' => 'Syncs the db structure to match db_struct.xml'], ['url' => 'dbtools/struct', 'name' => 'View db structure', 'desc' => 'Shows table and column definitions'], ['url' => 'dbtools/clearMediaCache', 'name' => 'Clear media cache', 'desc' => 'Cleans out all cached media files'], ['url' => 'dbtools/fileBackendMigrate', 'name' => 'File backend migration', 'desc' => 'Migrate all files that are not stored on the current back end'], ['url' => 'dbtools/testSkinTemplates', 'name' => 'Test skin templates', 'desc' => 'Simple tool for testing skin templates'], ['url' => 'dbtools/sessionEditor', 'name' => 'Session editor', 'desc' => 'Edit the $_SESSION'], ['url' => 'dbtools/listRoutes', 'name' => 'Routes inspector', 'desc' => 'View a list of routes'], ['url' => 'admin/extra/worker_job/manual_run', 'name' => 'Manual run worker job', 'desc' => 'Manually run a worker job in a browser'], ['url' => 'admin/extra/cron_job/manual_run', 'name' => 'Manual run cron job', 'desc' => 'Manually run a cron job in a browser'], ['url' => 'admin/style_guide', 'name' => 'Admin style guide', 'desc' => 'View styles of various admin features - form fields, etc']], 'Code generation' => [['url' => 'dbtools/moduleBuilder', 'name' => 'Module builder', 'desc' => 'Generates blank modules'], ['url' => 'dbtools/moduleBuilderDb', 'name' => 'Database struct generator', 'desc' => 'Generates db_struct.xml content for a module'], ['url' => 'dbtools/moduleBuilderExisting', 'name' => 'Module builder from existing', 'desc' => 'Generates modules from an existing db_struct.xml file'], ['url' => 'dbtools/multimake', 'name' => 'Generate multiedit', 'desc' => 'Generate multiedit code'], ['url' => 'dbtools/modelGenerator', 'name' => 'Model Generator', 'desc' => 'Generate a model class from a table in db_struct.xml']], 'AI' => [['url' => 'dbtools/openAiTest', 'name' => 'Open AI Tester', 'desc' => 'Prompt tester for Open AI'], ['url' => 'dbtools/processAiContentQueue', 'name' => 'Process AI Content Queue', 'desc' => 'Worker to process items in AI content queue'], ['url' => 'dbtools/processAiContentQueue?retry=1', 'name' => 'Retry AI Content Queue', 'desc' => 'Process AI content queue and retry any failed items'], ['url' => 'dbtools/openAiTools', 'name' => 'Open AI Content Manager', 'desc' => 'Tools for managing files, assistants etc']], 'Environment' => [['url' => 'dbtools/info', 'name' => 'Env and PHP info', 'desc' => 'Sprout information + phpinfo()'], ['url' => 'dbtools/modules', 'name' => 'Modules', 'desc' => 'View module registrations'], ['url' => 'dbtools/varDump', 'name' => 'Var dump', 'desc' => 'View session, cookie & server data'], ['url' => 'dbtools/email', 'name' => 'Test email', 'desc' => 'Renders form to send emails'], ['url' => 'dbtools/launchChecks', 'name' => 'Launch checks', 'desc' => 'Run a series of self-tests to ensure everything is configured correctly'], ['url' => 'admin/user-agent', 'name' => 'User agent tool', 'desc' => 'Show browser information<br><span>(this link doesn\'t require auth)</span>'], ['url' => 'dbtools/generatePasswordHash', 'name' => 'Generate password hash', 'desc' => 'Generate a password hash to store in a config file'], ['url' => 'dbtools/bcryptSpeed', 'name' => 'Test hashing speed', 'desc' => 'Test hashing speed of bcrypt'], ['url' => 'dbtools/fileTypesIndexingSupport', 'name' => 'File indexing support', 'desc' => 'List of file types which can be indexed for full-text search']], 'Logs' => [['url' => 'dbtools/exceptionLog', 'name' => 'Exception log', 'desc' => 'Browse and search exceptions'], ['url' => 'dbtools/profilingLog', 'name' => 'Profiling', 'desc' => 'Profiling logs'], ['url' => 'admin/intro/cron_job', 'name' => 'Cron job log', 'desc' => 'Cron (scheduled task) log'], ['url' => 'admin/intro/worker_job', 'name' => 'Worker job log', 'desc' => 'Log of worker (background) processes']], 'Migration' => [['url' => 'dbtools/exportFiles', 'name' => 'Export files', 'desc' => 'Exports all files'], ['url' => 'dbtools/exportTables', 'name' => 'Export database', 'desc' => 'Export tables to an SQL file'], ['url' => 'dbtools/importFiles', 'name' => 'Import files', 'desc' => 'Imports a files into the cms'], ['url' => 'dbtools/importTables', 'name' => 'Import database', 'desc' => 'Import database tables from a .sql file'], ['url' => 'dbtools/importXML', 'name' => 'Import XML', 'desc' => 'Import Sprout2 CMS export'], ['url' => 'dbtools/findReplace', 'name' => 'Doom Tool', 'desc' => 'Edit CMS text content on mass']]]

$action_log

Should this controller log add/edit/delete actions?

protected mixed $action_log = false

$module_builder_type_guess

For a given field name, a type to use which is better than VARCHAR(200)

private static mixed $module_builder_type_guess = array('active' => 'TINYINT UNSIGNED', 'amount' => 'DECIMAL(6,2)', 'data' => 'BLOB', 'description' => 'TEXT', 'email' => 'VARCHAR(150)', 'fax' => 'VARCHAR(20)', 'filename' => 'VARCHAR(255)', 'first_name' => 'VARCHAR(100)', 'image' => 'VARCHAR(255)', 'last_name' => 'VARCHAR(100)', 'mobile' => 'VARCHAR(20)', 'notes' => 'TEXT', 'phone' => 'VARCHAR(20)', 'photo' => 'VARCHAR(255)', 'postcode' => 'VARCHAR(10)', 'price' => 'DECIMAL(6,2)', 'state' => 'VARCHAR(50)', 'suburb' => 'VARCHAR(50)', 'text' => 'TEXT', 'visible' => 'TINYINT UNSIGNED')

Methods

__call()

Handles methods that do not exist.

public __call(string $method, array<string|int, mixed> $args) : void
Parameters
$method : string

Method name

$args : array<string|int, mixed>

Arguments

Tags
throws
BadMethodCallException

_run()

The router/kohana will invoke this method to invoke an action.

public _run(mixed $method, mixed $args) : mixed
Parameters
$method : mixed
$args : mixed
Tags
inheritdoc

ajaxPageIds()

Render page drop-down for given sub-site

public ajaxPageIds(int $subsite_id) : void
Parameters
$subsite_id : int
Return values
void —

Echos HTML directly

ajaxTableDefn()

public ajaxTableDefn(mixed $table) : mixed
Parameters
$table : mixed

api()

Render API test form within DB tools

public api(string $class, string $method, string ...$args) : void
Parameters
$class : string
$method : string
$args : string
Return values
void —

Echos HTML directly

bcryptSpeed()

Benchmark the server to find appropriate cost parameter

public bcryptSpeed() : mixed

clearMediaCache()

Force a clear out of the media cache

public clearMediaCache() : void

exceptionDetail()

Browse recent exceptions - details

public exceptionDetail() : mixed

exportAction()

Does the actual export

public exportAction() : void
Tags
post

tables Array of tables

dbms DBMS - MySQL or SQLite

split_tables Split the export per table

split_size Split the export by size

split_amount Split the export by size - size in kb, mb or gb

compress Should the data be compressed

Return values
void —

Outputs HTML directly

exportFilesAction()

Action to export all files

public exportFilesAction() : mixed

fileBackendMigrate()

Tool to move any files not on the current backend type, to it

public fileBackendMigrate() : void

fileTypesIndexingSupport()

Returns a list of file types which can be indexed for fulltext search

public fileTypesIndexingSupport() : mixed

findReplace()

Render a form for performing text find/replace across all CMS content.

public findReplace() : void
Return values
void —

Echos HTML directly

findReplaceView()

Find/replace form for a single doomtool instance.

public findReplaceView() : void

This is identified by the key param.

Return values
void —

Echos HTML directly

generateModel()

Generate a PHP model file from a PdbTable object

public generateModel(PdbTable $table, string $namespace, string $model_name) : string
Parameters
$table : PdbTable
$namespace : string
$model_name : string
Return values
string

generatePasswordHash()

Generate a password hash to store in a config file The username and hash are used by {@see AdminAuth::processLocal}

public generatePasswordHash() : mixed

getAbsModulePath()

Get the absolute path of the current module for this controller.

public getAbsModulePath() : string

TODO this might be too broad. It's only used for loading JSON forms and perhaps encourages bad behaviour. Such as assuming common path structures for all modules, where instead this should be written into the module class.

Return values
string

getCssClassName()

Return the class name for this controller, expressed in CSS style, i.e. with dashes

public getCssClassName() : string

Example: When called from BlogPostController --> 'blog-post-controller'

Return values
string —

Name of this PHP class, in a format suitable for use in CSS

getModulePath()

Get the a prefix suitable for finding views for this controller.

public getModulePath() : string

Do not assume that all modules, or even core sprout live relative to each other or the DOCROOT (as they previously did).

TODO rename this - like getViewPrefix()

Return values
string —

'sprout' or 'modules/AwesomeModule'

gettempfile()

Allows files to be downloaded from the temporary directory

public gettempfile(string $source, string $tempfile[, string $orig = null ]) : mixed

Only certain files from the temp directory can be downloaded. Each 'source' has a regex which is used to restrict downloads to only that particular type of file

Parameters
$source : string

The source of the file, one of 'export-database', 'export-files', 'module-builder'

$tempfile : string

File name in the temporary directory

$orig : string = null

Alternate name to use when providing file to browser

importFileAction()

Action for importing files

public importFileAction() : mixed

importTables()

Import database tables from a .sql file

public importTables() : mixed

importXML()

Renders form to imoprt Sprout2 Export XML

public importXML() : void
Return values
void —

Echos HTML directly

importXmlAction()

Process Sprout2 Export XML into this CMS

public importXmlAction() : void
Return values
void —

Redirects

launchChecks()

Run a series of self-tests to ensure everything is configured correctly

public launchChecks() : mixed

listRoutes()

Render table of routes

public listRoutes() : void
Return values
void —

Echos HTML directly

modelGenerator()

Generate a model file from a table.

public modelGenerator() : mixed

Uses mostly the same views as module builder so we'll just use a param

moduleBuilderDb()

Generates db_struct.xml content for a module

public moduleBuilderDb() : mixed

moduleBuilderExisting()

Generates modules from an existing db_struct.xml file

public moduleBuilderExisting() : mixed

moduleBuilderExistingAction()

Generates modules from an existing db_struct.xml file

public moduleBuilderExistingAction(mixed $input_xml) : mixed
Parameters
$input_xml : mixed

moduleBuilderExistingForm()

Generates modules from an existing db_struct.xml file

public moduleBuilderExistingForm(mixed $input_xml) : mixed
Parameters
$input_xml : mixed

moduleBuilderExistingModelAction()

Generate and download a PHP Model file based on a DB struct XML file

public moduleBuilderExistingModelAction(string $input_xml) : mixed

This is output directly as a PHP file download This way you can quickly iterate the tables on screen

Parameters
$input_xml : string

The name of the XML file to use (in the temp folder)

Tags
@return

void;

moduleBuilderExistingUploadAction()

Generates modules from an existing db_struct.xml file

public moduleBuilderExistingUploadAction() : mixed

modules()

Inspect module information.

public modules() : void
Return values
void —

Echos HTML

mtTransform()

Used by the module_template_action method

public static mtTransform(mixed $text) : mixed
Parameters
$text : mixed

openAiDebugOutput()

Render out the debug output based on the type requested

public openAiDebugOutput(string $debug) : void
Parameters
$debug : string

Setting to output debug data ('', 'tokens' or 'debug')

openAiImageOutputBlob()

Render out n image blob response

public openAiImageOutputBlob(string $response, string $debug) : void
Parameters
$response : string
$debug : string

Setting to output debug data ('', 'tokens' or 'debug')

openAiImageOutputSrc()

Render out n image URL response

public openAiImageOutputSrc(string $response, string $debug) : void
Parameters
$response : string
$debug : string

Setting to output debug data ('', 'tokens' or 'debug')

openAiLastRequestOutput()

Render out the last request made to Open AI

public openAiLastRequestOutput() : void

openAiLastTokensOutput()

Render out the tokens used in the last request

public openAiLastTokensOutput() : void

openAiList()

Render a list of items stored with Open AI for a given type

public openAiList(string $type) : void
Parameters
$type : string

Eg files or assistants

openAiListAction()

List all items for a given type

public openAiListAction(string $type) : never
Parameters
$type : string

as per OpenAiApi::ITEM_TYPES keys

Return values
never

openAiPurge()

Trigger a delete-all for a given type

public openAiPurge(string $type) : never
Parameters
$type : string

as per OpenAiApi::ITEM_TYPES keys

Return values
never

openAiTest()

Simple test tools for working out Open AI tooling using the client's keys

public openAiTest() : mixed

openAiTestSubmit()

Pass a request to Open AI API and render out the result accordingly

public openAiTestSubmit() : void

openAiTextOutput()

Render out a text response

public openAiTextOutput(string $response, string $debug) : void
Parameters
$response : string
$debug : string

Setting to output debug data ('', 'tokens' or 'debug')

openAiTools()

Render a list of tools for managing OpenAI

public openAiTools() : void

processAiContentQueue()

Fire the job to process AI Content form the queue

public processAiContentQueue() : never
Return values
never

profilingLogItem()

View a single profile log item.

public profilingLogItem() : mixed

profilingLogSessionOverride()

Update the session override for profiling.

public profilingLogSessionOverride() : mixed

sessionEditorAction()

Session Editor Action

public sessionEditorAction() : mixed

struct()

Shows table and column definitions

public struct([mixed $arg = '' ]) : mixed
Parameters
$arg : mixed = ''

testSkinTemplates()

Simple tool for testing skin templates

public testSkinTemplates() : void
Return values
void —

Outputs HTML directly

testSkinTemplatesAction()

Actual viewing UI for templates

public testSkinTemplatesAction(string $code, string $filename) : void
Parameters
$code : string

Skin code: 'default'

$filename : string

Template filename: 'inner.php' | 'inner.twig'

Return values
void —

Outputs HTML directly

varDump()

Render view to see session and cookie data

public varDump() : void
Return values
void —

Echos HTML

autoSetEmptyParam()

Auto-set the "empty" param for fields with foreign keys to be NULL

protected autoSetEmptyParam(array<string, array<string|int, array<string, mixed>>> &$conf) : void

This greatly reduces the number of foreign-key constraints hit in day-to-day use, especially with file fields.

Parameters
$conf : array<string, array<string|int, array<string, mixed>>>

Json form configuration

Return values
void —

Array $conf is altered in-place

deleteRecord()

Deletes a record, and logs the deletion This should be used by all _deleteSave methods Starts a transaction and commits it if not already in a transaction when called

protected deleteRecord(string $table, int $record_id[, int $parent_log_id = 0 ]) : int
Parameters
$table : string

Table name

$record_id : int
$parent_log_id : int = 0

ID of a parent entry in the history_items table. This is used when multiple records are deleted by a single action. Undoing that action can then restore all of the deleted data.

Tags
throws
QueryException
Return values
int —

ID of the record inserted into the history_items table (0 if no logging)

findReplaceAction()

Doom tool actions.

protected findReplaceAction(string $redirect) : void
Parameters
$redirect : string
Return values
void —

Redirects

generateFormView()

Generates a form view from a JSON config file

protected generateFormView(mixed $file_name) : PhpView
Parameters
$file_name : mixed
Tags
throws
Exception

If the file is missing or invalid

Return values
PhpView

jsonExtraValidate()

Do any additional validation prior to saving the record

protected jsonExtraValidate(int $id, Validator $validator) : void
Parameters
$id : int

Record ID or 0 for adds

$validator : Validator

Validator instance to attach your errors to

loadEditJson()

Loads a JSON config file for an automated edit-type form for this controller

protected loadEditJson() : array<string, array<string|int, array<string, mixed>>>
Tags
throws
Exception

If the file is missing or invalid

Return values
array<string, array<string|int, array<string, mixed>>>

loadFormJson()

Loads a config file for a JsonForm associated with this controller

protected loadFormJson(string $file_name) : array<string|int, mixed>
Parameters
$file_name : string

The config file name, e.g. 'register.json'

Tags
throws
FileMissingException

If the file is missing

Exception

If the file is invalid

Return values
array<string|int, mixed>

loadRecord()

Fetches the pre-update record from the database.

protected loadRecord(string $table, int $record_id) : array<string|int, mixed>|bool

Used by the action log system, and disabled if the action log system has been turned off

Parameters
$table : string

Name of table to load record from

$record_id : int

ID of record to load

Tags
throws
RowMissingException

If record doesn't exist

Return values
array<string|int, mixed>|bool —

False if not using logging for this controller, else the record row

logAction()

Stores a history item in the database, recording an add (i.e. insert), edit, or delete.

protected logAction(string $table, int $record_id, string $type[, array<string|int, mixed> $data = [] ][, int $parent_log_id = 0 ]) : int

Should be called AFTER the action has been made. N.B. This is a low-level method; the friendlier wrapper methods are preferred; e.g. Controller::logAdd, Controller::logEdit

Parameters
$table : string

The table which had data modified by the query

$record_id : int

The id of the added/edited/deleted record

$type : string

ENUM value from history_items.type

$data : array<string|int, mixed> = []

Data associated with an add/edit. The handling differs based on the $type parameter: 'Add' ignored 'Edit' should be an array of the pre-update data, used to build a diff 'Delete' should contain the complete data of the deleted record 'Add category' should contain ['cat_id' => value] 'Delete category' should contain ['cat_id' => value] 'Change password' should be an empty array

$parent_log_id : int = 0

ID of a parent log entry in the history_items table. This is used when multiple records are deleted by a single action. Undoing that action can then restore all of the deleted data. N.B. This is only relevant for deletes

Tags
throws
QueryException
Return values
int —

ID of the record inserted into the history_items table; 0 if no insert was done; -1 if it failed

logAdd()

Logs an add action. This is a wrapper for {@see Controller::logAction}

protected logAdd(string $table, int $record_id) : int
Parameters
$table : string

The table which had data modified by the query

$record_id : int

The id of the added record

Tags
throws
QueryException
Return values
int —

ID of the record inserted into the history_items table

logAddCategory()

Logs the adding of a record to a category. This is a wrapper for {@see Controller::logAction}

protected logAddCategory(string $table, int $record_id, int $cat_id) : int
Parameters
$table : string

The table which had data modified by the query

$record_id : int

The ID of the record which was added to the category

$cat_id : int

The ID of the category which the record was added to

Tags
throws
QueryException
Return values
int —

ID of the record inserted into the history_items table

logDelete()

Logs a delete action. This is a wrapper for {@see Controller::logAction}

protected logDelete(string $table, int $record_id, array<string|int, mixed> $data[, int $parent_log_id = 0 ]) : int
Parameters
$table : string

The table which contained the deleted record

$record_id : int

The id of the deleted record

$data : array<string|int, mixed>

The complete contents of the record which was deleted, i.e. [field => value], so it can be restored if necessary

$parent_log_id : int = 0

ID of a parent log entry in the history_items table. This is used when multiple records are deleted by a single action. Undoing that action can then restore all of the deleted data.

Tags
throws
QueryException
Return values
int —

ID of the record inserted into the history_items table

logDeleteCategory()

Logs the removal of a record from a category. This is a wrapper for {@see Controller::logAction}

protected logDeleteCategory(string $table, int $record_id, int $cat_id) : int
Parameters
$table : string

The table which contains the record which was removed from the category

$record_id : int

The ID of the record which was removed from the category

$cat_id : int

The ID of the category which the record was removed from

Tags
throws
QueryException
Return values
int —

ID of the record inserted into the history_items table

logEdit()

Logs an edit action. This is a wrapper for {@see Controller::logAction}

protected logEdit(string $table, int $record_id, array<string|int, mixed> $data) : int
Parameters
$table : string

The table which had data modified by the query

$record_id : int

The id of the edited record

$data : array<string|int, mixed>

Pre-update data, used to build a diff

Tags
throws
QueryException
Return values
int —

ID of the record inserted into the history_items table

replaceSet()

Inserts records which are in $new_records, but are not in the specified table Deletes records which are in the specified table, but not in $new_records Updates records which are in both

protected replaceSet(string $table, array<string|int, mixed> $new_records, array<string|int, mixed> $conditions) : void

Matching is done on the 'id' field, as a result the $new_records arrays MUST contain an id field.

Parameters
$table : string

The table name. Do not include prefix.

$new_records : array<string|int, mixed>

The new records for the table. Should be an array of arrays, With each sub-array being the arguments which would normally be passed to Pdb::insert or Pdb::update

$conditions : array<string|int, mixed>

A where clause to use when looking to see what records already exist. Pdb::buildClause

Tags
throws
QueryException

saveJsonData()

Automatically saves the data associated with a submission on a JSON-generated form

protected saveJsonData(array<string, array<string|int, array<string, mixed>>> $conf, int &$item_id[, string $mode = '' ]) : bool
Parameters
$conf : array<string, array<string|int, array<string, mixed>>>

Config loaded from a JSON file

$item_id : int

Database ID of record to store data in. If zero, a new record will be inserted, and as this argument is a reference, it will be updated with the auto-increment ID generated by the insert.

$mode : string = ''

Mode: 'add', 'edit', or something custom (e.g. 'duplicate', 'verify'). If blank, 'add' or 'edit' will be automatically determined, based on $item_id

Return values
bool —

True if the save succeeded. If false is returned, errors will be saved in $_SESSION

outputSqlResultset()

Renders SQL result set into a table

private outputSqlResultset(PDOStatement $results[, mixed|null $headings = null ]) : int
Parameters
$results : PDOStatement

Query result

$headings : mixed|null = null
Return values
int —

Number of rows

sessionLoop()

List items in an array, along with the tools buttons

private sessionLoop(mixed &$a, mixed $depth, mixed $keys) : mixed
Parameters
$a : mixed
$depth : mixed
$keys : mixed

sizeToHuman()

Render table data size in human readable form

private sizeToHuman(int $size) : string
Parameters
$size : int
Return values
string —

HTML

splitSql()

Splits a set of SQL queries into individual queries

private splitSql(mixed $all) : mixed
Parameters
$all : mixed

template()

Render dbtools template

private template(string $main_title[, string|null $html = null ]) : void
Parameters
$main_title : string
$html : string|null = null

HTML

Return values
void —

Echos HTML directly

xmlGetColumns()

private static xmlGetColumns(DOMDocument $doc, mixed $table_name) : array<string|int, mixed>
Parameters
$doc : DOMDocument
$table_name : mixed
Return values
array<string|int, mixed>

xmlGetTables()

private static xmlGetTables(DOMDocument $doc) : array<string|int, mixed>
Parameters
$doc : DOMDocument
Return values
array<string|int, mixed>

xmlLoad()

private static xmlLoad(mixed $module) : mixed
Parameters
$module : mixed
On this page

Search results