Provides a system for applying database updates. Updates extend the dbUpdateDefinition class and add a series of SQL or method calls to be applied as updates. These individual updates are aggregated by this manager class that will then apply the updates.
When specifying database names, be sure to use the system::getConfig()->getDatabase() method. This ensures that the database can be portable.
Log entries are created for every action performed. Test runs are not saved (commit is false) but the log information will be returned in a report for each database. This can be queried either for potential issues when run in a test mode or to review the update process.
The manager can generate an array of data representating the current update status which can be displayed either on the CLI or via a web page.
Note: that to successfully run, the user must have permissions to modify the database in question. Database creation CANNOT be handled by this system (you should not be using root user!).
To set a new database user / password, implement this class in a calling system and then set the database details manually and re-request the database connection. This will override the default connection.
public __construct()
Creates a new dbUpdate manager instance
public static getInstance()
Returns a static instance of dbUpdateManager
public static fetchDatabaseUpdateComponents()
Locates all database update classes in /data/dbUpdates and returns them as an associative array of classname => file location
public reset()
Resets object to defaults
protected buildDbUpdateManager()
Returns an instance of the database update manager with all update classes assigned
public isUpToDate()
Returns true if databases are up-to-date, false if any require an update
public getUpdateStatus()
Returns an array detailing information about each database update and the current state
public update([$inCommit = false])
Applies any outstanding updates to the database(s), generates a report accessible via dbUpdateManager::getUpdateReport()
public getHaltOnError()
Returns $_HaltOnError
public setHaltOnError($inHaltOnError)
Set $_HaltOnError to $inHaltOnError
public getUpdateReport()
Returns $_UpdateReport
public setUpdateReport($inUpdateReport)
Set $_UpdateReport to $inUpdateReport
public addUpdate($inDefinition)
Adds a new database definition to apply updates to
public removeUpdate($inDefinition)
Removes the definition from the set
public getUpdate($inKey)
Returns the update by $inKey
public getUpdateByDatabaseName($inDatabase)
Returns the update definition object for $inDatabase, false on failure
public getCount()
Returns the item count
Posted by: Scorpio Documentor (Writer), in Db on 19 Nov 2009 @ 20:30
Tags: baseset, countable, db, dbupdatemanager, iteratoraggregate, traversable,
This
work is licenced under a
Creative Commons Licence.