Developers/Setup tasks/Essentials

As every setup task must extend the MW_Setup_Task_Abstract class, it inherits some properties and methods that are required or useful to do the job. By using the abstract class, your task already implements the required interface MW_Setup_Task_Interface.

Methods

 * _execute(  ) : Executes a single SQL statement
 * _executeList(  ): Executes a list of SQL statements in the order provided by the array. They are executed one by one and not inside of a transaction
 * _getValue( , ) : Fetches a single record from the database and returns the value of the given column. If you need to fetch more than one record or column, use the property "_conn" instead
 * _msg : Prints the message indented by the given level. This method formats the messages so the output looks nice. Must be followed by a call to $this->_status( '...' )
 * _status : Prints the status for the test that was printed by $this->_msg( ... ) before. Usual status values are: "OK", "added", "dropped", "migrated" or the number of records inserted (" / ")
 * _getTableDefinitions : Extracts all table definitions from the given string (usually the content of a schema file). Each definition must be separated by two new lines ("\n")
 * _getIndexDefinitions : Extracts all index definitions from the given string (usually the content of a schema file). Each definition must be separated by two new lines ("\n")
 * _getTriggerDefinitions : Extracts all trigger definitions from the given string (usually the content of a schema file). Each definition must be separated by two new lines ("\n")

Properties

 * _conn : Connection to the database that should be set up. This property is an object implementing MW_DB_Connection_Interface and is only used if you have to fetch records from the database, transform them and write them back to the database. Otherwise, it's easier to use the methods provided by the abstract class.
 * _schema : Allows the access to the database schema. It's an object implementing MW_Setup_DBSchema_Interface that provides some methods to test if the database contains tables, columns or indexes.
 * _additional : A generic object and for Arcavias setup tasks it contains the context object (implementing MShop_Context_Item_Interface</tt>). It enables the setup tasks to create e.g. managers for manipulating data in a more convenient way or use existing code for performing required tasks.

Database access
The database connection object provides:


 * create( <SQL statement> ) : Returns a database statement object using the given SQL statement and implementing MW_DB_Statement_Interface</tt>
 * escape : Escapes the given value before it can be safely inserted into the SQL statement
 * begin : Starts a transaction for this connection
 * commit : Commits the changes done within the transaction
 * rollback : Discards the changes done inside the transaction

Available methods of the database statement are:


 * bind(, , [ ] ) : Binds a value to a parameter in the statement. "Type" is optional and by default MW_DB_Statement_Abstract::PARAM_STR
 * execute : Executes the SQL statement and returns an object implementing MW_DB_Result_Interface</tt>

The statement result object contains:


 * affectedRows : Returns the number of rows affected by a INSERT, UPDATE or DELETE statement
 * fetch( [ ] ) : Retrieves the next row from database result set, returns false if no more rows are available. "Style" is optional and by default MW_DB_Result_Abstract::ASSOC
 * finish : Cleans up pending database result sets. Must be always called after retrieving all rows or executing another statement
 * nextResult : Retrieves next database result set if the SQL statement contained multiple statements

Example code for fetching records:

Database schema tests
The schema object provides:


 * tableExists(

<< Previous: Implementation - Rules for setup tasks