class Tracker

This class tracks changes on databases, tables and views.

Properties

static protected $enabled Whether tracking is ready.
static protected $_tracking_cache Cache to avoid quering tracking status multiple times.

Methods

static void
enable()

Actually enables tracking. This needs to be done after all underlaying code is initialized.

static boolean
isActive()

Gets the on/off value of the Tracker module, starts initialization.

static string
getTableName(string $string)

Parses the name of a table from a SQL statement substring.

static boolean
isTracked(string $dbname, string $tablename)

Gets the tracking status of a table, is it active or deactive ?

static string
getLogComment()

Returns the comment line for the log.

static int
createVersion(string $dbname, string $tablename, string $version, string $tracking_set = '', bool $is_view = false)

Creates tracking version of a table / view (in other words: create a job to track future changes on the table).

static int
deleteTracking(string $dbname, string $tablename, string $version = '')

Removes all tracking data for a table or a version of a table

static int
createDatabaseVersion(string $dbname, string $version, string $query, string $tracking_set = 'CREATE DATABASE,ALTER DATABASE,DROP DATABASE')

Creates tracking version of a database (in other words: create a job to track future changes on the database).

static bool
changeTrackingData(string $dbname, string $tablename, string $version, string $type, string|array $new_data)

Changes tracking data of a table.

static int
activateTracking(string $dbname, string $tablename, string $version)

Activates tracking of a table.

static int
deactivateTracking(string $dbname, string $tablename, string $version)

Deactivates tracking of a table.

static int
getVersion(string $dbname, string $tablename, string $statement = null)

Gets the newest version of a tracking job (in other words: gets the HEAD version).

static mixed
getTrackedData(string $dbname, string $tablename, string $version)

Gets the record of a tracking job.

static mixed
parseQuery(string $query)

Parses a query. Gets - statement identifier (UPDATE, ALTER TABLE, .

static void
handleQuery(string $query)

Analyzes a given SQL statement and saves tracking data.

Details

at line 53
static void enable()

Actually enables tracking. This needs to be done after all underlaying code is initialized.

Return Value

void

at line 65
static boolean isActive()

Gets the on/off value of the Tracker module, starts initialization.

Return Value

boolean (true=on|false=off)

at line 96
static protected string getTableName(string $string)

Parses the name of a table from a SQL statement substring.

Parameters

string $string part of SQL statement

Return Value

string the name of table

at line 125
static boolean isTracked(string $dbname, string $tablename)

Gets the tracking status of a table, is it active or deactive ?

Parameters

string $dbname name of database
string $tablename name of table

Return Value

boolean true or false

at line 163
static string getLogComment()

Returns the comment line for the log.

Return Value

string Comment, contains date and username

at line 185
static int createVersion(string $dbname, string $tablename, string $version, string $tracking_set = '', bool $is_view = false)

Creates tracking version of a table / view (in other words: create a job to track future changes on the table).

Parameters

string $dbname name of database
string $tablename name of table
string $version version
string $tracking_set set of tracking statements
bool $is_view if table is a view

Return Value

int result of version insertion

at line 307
static int deleteTracking(string $dbname, string $tablename, string $version = '')

Removes all tracking data for a table or a version of a table

Parameters

string $dbname name of database
string $tablename name of table
string $version version

Return Value

int result of version insertion

at line 337
static int createDatabaseVersion(string $dbname, string $version, string $query, string $tracking_set = 'CREATE DATABASE,ALTER DATABASE,DROP DATABASE')

Creates tracking version of a database (in other words: create a job to track future changes on the database).

Parameters

string $dbname name of database
string $version version
string $query query
string $tracking_set set of tracking statements

Return Value

int result of version insertion

at line 433
static bool changeTrackingData(string $dbname, string $tablename, string $version, string $type, string|array $new_data)

Changes tracking data of a table.

Parameters

string $dbname name of database
string $tablename name of table
string $version version
string $type type of data(DDL || DML)
string|array $new_data the new tracking data

Return Value

bool result of change

at line 483
static int activateTracking(string $dbname, string $tablename, string $version)

Activates tracking of a table.

Parameters

string $dbname name of database
string $tablename name of table
string $version version

Return Value

int result of SQL query

at line 500
static int deactivateTracking(string $dbname, string $tablename, string $version)

Deactivates tracking of a table.

Parameters

string $dbname name of database
string $tablename name of table
string $version version

Return Value

int result of SQL query

at line 518
static int getVersion(string $dbname, string $tablename, string $statement = null)

Gets the newest version of a tracking job (in other words: gets the HEAD version).

Parameters

string $dbname name of database
string $tablename name of table
string $statement tracked statement

Return Value

int (-1 if no version exists | > 0 if a version exists)

at line 549
static mixed getTrackedData(string $dbname, string $tablename, string $version)

Gets the record of a tracking job.

Parameters

string $dbname name of database
string $tablename name of table
string $version version number

Return Value

mixed record DDM log, DDL log, structure snapshot, tracked statements.

at line 677
static mixed parseQuery(string $query)

Parses a query. Gets - statement identifier (UPDATE, ALTER TABLE, .

..) - type of statement, is it part of DDL or DML ? - tablename

Parameters

string $query query

Return Value

mixed Array containing identifier, type and tablename.

at line 815
static void handleQuery(string $query)

Analyzes a given SQL statement and saves tracking data.

Parameters

string $query a SQL query

Return Value

void