MediaWiki  REL1_22
ORMTable Class Reference
Inheritance diagram for ORMTable:
Collaboration diagram for ORMTable:

List of all members.

Public Member Functions

 __construct ($tableName= '', array $fields=array(), array $defaults=array(), $rowClass=null, $fieldPrefix= '')
 Constructor.
 addToField (array $conditions, $field, $amount)
 Add an amount (can be negative) to the specified field (needs to be numeric).
 canHaveField ($name)
 Gets if the object can take a certain field.
 count (array $conditions=array(), array $options=array())
 Returns the amount of matching records.
 delete (array $conditions, $functionName=null)
 Removes the object from the database.
 exists ()
 Checks if the table exists.
 getAPIParams ($requireParams=false, $setDefaults=false)
 Get API parameters for the fields supported by this object.
 getDefaults ()
 Returns a list of default field values.
 getFieldDescriptions ()
 Returns an array with the fields and their descriptions.
 getFieldNames ()
 Return the names of the fields.
 getFields ()
 getFieldsFromDBResult (stdClass $result)
 Get an array with fields from a database result, that can be fed directly to the constructor or to setFields.
 getName ()
 getPrefixedField ($field)
 Takes in a field and returns an it's prefixed version, ready for db usage.
 getPrefixedFields (array $fields)
 Takes in a field or array of fields and returns an array with their prefixed versions, ready for db usage.
 getPrefixedValues (array $values)
 Takes in an associative array with field names as keys and their values as value.
 getReadDb ()
 Get the database ID used for read operations.
 getReadDbConnection ()
 Get the database type used for read operations.
 getRowClass ()
 getSummaryFields ()
 Returns a list of the summary fields.
 getTargetWiki ()
 Get the ID of the any foreign wiki to use as a target for database operations.
 getWriteDbConnection ()
 Get the database type used for read operations.
 has (array $conditions=array())
 Returns if there is at least one record matching the provided conditions.
 insertRow (IORMRow $row, $functionName=null, array $options=null)
 Inserts the provided row into the database.
 newFromArray (array $data, $loadDefaults=false)
 newFromDBResult (stdClass $result)
 newRow (array $fields, $loadDefaults=false)
 Get a new instance of the class from an array.
 newRowFromDBResult (stdClass $result)
 Get a new instance of the class from a database result.
 rawSelect ($fields=null, array $conditions=array(), array $options=array(), $functionName=null)
 Do the actual select.
 rawSelectRow (array $fields, array $conditions=array(), array $options=array(), $functionName=null)
 Selects the the specified fields of the records matching the provided conditions.
 releaseConnection (DatabaseBase $db)
 Releases the lease on the given database connection.
 removeRow (IORMRow $row, $functionName=null)
 Removes the provided row from the database.
 select ($fields=null, array $conditions=array(), array $options=array(), $functionName=null)
 Selects the the specified fields of the records matching the provided conditions and returns them as DBDataObject.
 selectFields ($fields=null, array $conditions=array(), array $options=array(), $collapse=true, $functionName=null)
 Selects the the specified fields of the records matching the provided conditions and returns them as associative arrays.
 selectFieldsRow ($fields=null, array $conditions=array(), array $options=array(), $collapse=true, $functionName=null)
 Selects the the specified fields of the first record matching the provided conditions and returns it as an associative array, or false when nothing matches.
 selectObjects ($fields=null, array $conditions=array(), array $options=array(), $functionName=null)
 Selects the the specified fields of the records matching the provided conditions and returns them as DBDataObject.
 selectRow ($fields=null, array $conditions=array(), array $options=array(), $functionName=null)
 Selects the the specified fields of the first matching record.
 setReadDb ($db)
 Set the database ID to use for read operations, use DB_XXX constants or an index to the load balancer setup.
 setTargetWiki ($wiki)
 Set the ID of the any foreign wiki to use as a target for database operations.
 unprefixFieldName ($fieldName)
 Takes a field name with prefix and returns the unprefixed equivalent.
 unprefixFieldNames (array $fieldNames)
 Takes an array of field names with prefix and returns the unprefixed equivalent.
 update (array $values, array $conditions=array())
 Update the records matching the provided conditions by setting the fields that are keys in the $values param to their corresponding values.
 updateRow (IORMRow $row, $functionName=null)
 Updates the provided row in the database.
 updateSummaryFields ($summaryFields=null, array $conditions=array())
 Computes the values of the summary fields of the objects matching the provided conditions.

Static Public Member Functions

static singleton ()
 Get an instance of this class.

Protected Member Functions

 getFieldPrefix ()
 Gets the db field prefix.
 getWriteValues (IORMRow $row)
 Gets the fields => values to write to the table.

Protected Attributes

array $defaults = array()
string $fieldPrefix = ''
string[] $fields = array()
integer $readDb = DB_SLAVE
 ID of the database connection to use for read operations.
string $rowClass = 'ORMRow'
string $tableName

Static Protected Attributes

static $instanceCache = array()

Detailed Description

Definition at line 31 of file ORMTable.php.


Constructor & Destructor Documentation

ORMTable::__construct ( tableName = '',
array fields = array(),
array defaults = array(),
rowClass = null,
fieldPrefix = '' 
)

Constructor.

Since:
1.21
Parameters:
string$tableName
string[]$fields
array$defaults
string | null$rowClass
string$fieldPrefix

Definition at line 93 of file ORMTable.php.


Member Function Documentation

ORMTable::addToField ( array conditions,
field,
amount 
)

Add an amount (can be negative) to the specified field (needs to be numeric).

Since:
1.22
Parameters:
array$conditions
string$field
integer$amount
Returns:
boolean Success indicator
Exceptions:
MWException

Definition at line 1073 of file ORMTable.php.

Gets if the object can take a certain field.

Since:
1.20
Parameters:
string$name
Returns:
boolean

Implements IORMTable.

Definition at line 944 of file ORMTable.php.

ORMTable::count ( array conditions = array(),
array options = array() 
)

Returns the amount of matching records.

Condition field names get prefixed.

Note that this can be expensive on large tables. In such cases you might want to use DatabaseBase::estimateRowCount instead.

Since:
1.20
Parameters:
array$conditions
array$options
Returns:
integer

Implements IORMTable.

Definition at line 457 of file ORMTable.php.

ORMTable::delete ( array conditions,
functionName = null 
)

Removes the object from the database.

Since:
1.20
Parameters:
array$conditions
string | null$functionName
Returns:
boolean Success indicator

Implements IORMTable.

Definition at line 478 of file ORMTable.php.

Checks if the table exists.

Since:
1.21
Returns:
boolean

Implements IORMTable.

Definition at line 435 of file ORMTable.php.

ORMTable::getAPIParams ( requireParams = false,
setDefaults = false 
)

Get API parameters for the fields supported by this object.

Since:
1.20
Parameters:
boolean$requireParams
boolean$setDefaults
Returns:
array

Implements IORMTable.

Definition at line 501 of file ORMTable.php.

Returns a list of default field values.

field name => field value

Since:
1.20
Returns:
array

Implements IORMTable.

Definition at line 167 of file ORMTable.php.

Returns an array with the fields and their descriptions.

field name => field description

Since:
1.20
Returns:
array

Implements IORMTable.

Definition at line 549 of file ORMTable.php.

Return the names of the fields.

Since:
1.20
Returns:
array

Implements IORMTable.

Definition at line 931 of file ORMTable.php.

ORMTable::getFieldPrefix ( ) [protected]

Gets the db field prefix.

Since:
1.20
Returns:
string

Reimplemented in TestORMTable, and PageORMTableForTesting.

Definition at line 128 of file ORMTable.php.

See also:
ORMTable::getFields
Since:
1.21
Returns:
array
Exceptions:
MWException

Implements IORMTable.

Reimplemented in TestORMTable, and PageORMTableForTesting.

Definition at line 151 of file ORMTable.php.

ORMTable::getFieldsFromDBResult ( stdClass $  result)

Get an array with fields from a database result, that can be fed directly to the constructor or to setFields.

Since:
1.20
Parameters:
stdClass$result
Returns:
array

Implements IORMTable.

Definition at line 809 of file ORMTable.php.

See also:
IORMTable::getName
Since:
1.21
Returns:
string
Exceptions:
MWException

Implements IORMTable.

Reimplemented in TestORMTable, and PageORMTableForTesting.

Definition at line 113 of file ORMTable.php.

Takes in a field and returns an it's prefixed version, ready for db usage.

Since:
1.20
Parameters:
string | array$field
Returns:
string

Implements IORMTable.

Definition at line 750 of file ORMTable.php.

Takes in a field or array of fields and returns an array with their prefixed versions, ready for db usage.

Since:
1.20
Parameters:
array | string$fields
Returns:
array

Implements IORMTable.

Definition at line 733 of file ORMTable.php.

Takes in an associative array with field names as keys and their values as value.

The field names are prefixed with the db field prefix.

Since:
1.20
Parameters:
array$values
Returns:
array

Implements IORMTable.

Definition at line 700 of file ORMTable.php.

Get the database ID used for read operations.

Since:
1.20
Returns:
integer DB_ enum

Implements IORMTable.

Definition at line 560 of file ORMTable.php.

Get the database type used for read operations.

This is to be used instead of wfGetDB.

See also:
LoadBalancer::getConnection
Since:
1.20
Returns:
DatabaseBase The database object

Implements IORMTable.

Definition at line 607 of file ORMTable.php.

See also:
IORMTable::getRowClass
Since:
1.21
Returns:
string

Implements IORMTable.

Reimplemented in TestORMTable, and PageORMTableForTesting.

Definition at line 139 of file ORMTable.php.

Returns a list of the summary fields.

These are fields that cache computed values, such as the amount of linked objects of $type. This is relevant as one might not want to do actions such as log changes when these get updated.

Since:
1.20
Returns:
array

Implements IORMTable.

Definition at line 180 of file ORMTable.php.

Get the ID of the any foreign wiki to use as a target for database operations.

Since:
1.20
Returns:
String|bool The target wiki, in a form that LBFactory understands (or false if the local wiki is used)

Implements IORMTable.

Definition at line 582 of file ORMTable.php.

Get the database type used for read operations.

This is to be used instead of wfGetDB.

See also:
LoadBalancer::getConnection
Since:
1.20
Returns:
DatabaseBase The database object

Implements IORMTable.

Definition at line 621 of file ORMTable.php.

ORMTable::getWriteValues ( IORMRow row) [protected]

Gets the fields => values to write to the table.

Since:
1.22
Parameters:
IORMRow$row
Returns:
array

Definition at line 1016 of file ORMTable.php.

ORMTable::has ( array conditions = array())

Returns if there is at least one record matching the provided conditions.

Condition field names get prefixed.

Since:
1.20
Parameters:
array$conditions
Returns:
boolean

Implements IORMTable.

Definition at line 424 of file ORMTable.php.

ORMTable::insertRow ( IORMRow row,
functionName = null,
array options = null 
)

Inserts the provided row into the database.

Since:
1.22
Parameters:
IORMRow$row
string | null$functionName
array | null$options
Returns:
boolean Success indicator

Definition at line 985 of file ORMTable.php.

ORMTable::newFromArray ( array data,
loadDefaults = false 
)
See also:
ORMTable::newRow
Deprecated:
use newRow instead
Since:
1.20
Parameters:
array$data
boolean$loadDefaults
Returns:
IORMRow

Definition at line 904 of file ORMTable.php.

ORMTable::newFromDBResult ( stdClass $  result)
See also:
ORMTable::newRowFromFromDBResult
Deprecated:
use newRowFromDBResult instead
Since:
1.20
Parameters:
stdClass$result
Returns:
IORMRow

Definition at line 876 of file ORMTable.php.

ORMTable::newRow ( array fields,
loadDefaults = false 
)

Get a new instance of the class from an array.

Since:
1.20
Parameters:
array$fields
boolean$loadDefaults
Returns:
IORMRow

Implements IORMTable.

Reimplemented in PageORMTableForTesting.

Definition at line 918 of file ORMTable.php.

ORMTable::newRowFromDBResult ( stdClass $  result)

Get a new instance of the class from a database result.

Since:
1.20
Parameters:
stdClass$result
Returns:
IORMRow

Implements IORMTable.

Definition at line 889 of file ORMTable.php.

ORMTable::rawSelect ( fields = null,
array conditions = array(),
array options = array(),
functionName = null 
)

Do the actual select.

Since:
1.20
Parameters:
null | string | array$fields
array$conditions
array$options
null | string$functionName
Returns:
ResultWrapper
Exceptions:
DBQueryErrorif the quey failed (even if the database was in ignoreErrors mode).

Implements IORMTable.

Definition at line 243 of file ORMTable.php.

ORMTable::rawSelectRow ( array fields,
array conditions = array(),
array options = array(),
functionName = null 
)

Selects the the specified fields of the records matching the provided conditions.

Field names do NOT get prefixed.

Since:
1.20
Parameters:
array$fields
array$conditions
array$options
string | null$functionName
Returns:
ResultWrapper

Implements IORMTable.

Definition at line 372 of file ORMTable.php.

Releases the lease on the given database connection.

This is useful mainly for connections to a foreign wiki. It does nothing for connections to the local wiki.

See also:
LoadBalancer::reuseConnection
Parameters:
DatabaseBase$dbthe database
Since:
1.20

Reimplemented from DBAccessBase.

Definition at line 635 of file ORMTable.php.

ORMTable::removeRow ( IORMRow row,
functionName = null 
)

Removes the provided row from the database.

Since:
1.22
Parameters:
IORMRow$row
string | null$functionName
Returns:
boolean Success indicator

Definition at line 1051 of file ORMTable.php.

ORMTable::select ( fields = null,
array conditions = array(),
array options = array(),
functionName = null 
)

Selects the the specified fields of the records matching the provided conditions and returns them as DBDataObject.

Field names get prefixed.

Since:
1.20
Parameters:
array | string | null$fields
array$conditions
array$options
string | null$functionName
Returns:
ORMResult

Implements IORMTable.

Definition at line 197 of file ORMTable.php.

ORMTable::selectFields ( fields = null,
array conditions = array(),
array options = array(),
collapse = true,
functionName = null 
)

Selects the the specified fields of the records matching the provided conditions and returns them as associative arrays.

Provided field names get prefixed. Returned field names will not have a prefix.

When $collapse is true: If one field is selected, each item in the result array will be this field. If two fields are selected, each item in the result array will have as key the first field and as value the second field. If more then two fields are selected, each item will be an associative array.

Since:
1.20
Parameters:
array | string | null$fields
array$conditions
array$options
boolean$collapseSet to false to always return each result row as associative array.
string | null$functionName
Returns:
array of array

Implements IORMTable.

Definition at line 309 of file ORMTable.php.

ORMTable::selectFieldsRow ( fields = null,
array conditions = array(),
array options = array(),
collapse = true,
functionName = null 
)

Selects the the specified fields of the first record matching the provided conditions and returns it as an associative array, or false when nothing matches.

This method makes use of selectFields and expects the same parameters and returns the same results (if there are any, if there are none, this method returns false).

See also:
ORMTable::selectFields
Since:
1.20
Parameters:
array | string | null$fields
array$conditions
array$options
boolean$collapseSet to false to always return each result row as associative array.
string | null$functionName
Returns:
mixed|array|bool False on failure

Implements IORMTable.

Definition at line 405 of file ORMTable.php.

ORMTable::selectObjects ( fields = null,
array conditions = array(),
array options = array(),
functionName = null 
)

Selects the the specified fields of the records matching the provided conditions and returns them as DBDataObject.

Field names get prefixed.

Since:
1.20
Parameters:
array | string | null$fields
array$conditions
array$options
string | null$functionName
Returns:
array of row objects
Exceptions:
DBQueryErrorif the query failed (even if the database was in ignoreErrors mode).

Implements IORMTable.

Definition at line 217 of file ORMTable.php.

ORMTable::selectRow ( fields = null,
array conditions = array(),
array options = array(),
functionName = null 
)

Selects the the specified fields of the first matching record.

Field names get prefixed.

Since:
1.20
Parameters:
array | string | null$fields
array$conditions
array$options
string | null$functionName
Returns:
IORMRow|bool False on failure

Implements IORMTable.

Definition at line 350 of file ORMTable.php.

Set the database ID to use for read operations, use DB_XXX constants or an index to the load balancer setup.

Parameters:
integer$db
Since:
1.20

Implements IORMTable.

Definition at line 571 of file ORMTable.php.

Set the ID of the any foreign wiki to use as a target for database operations.

Parameters:
string | bool$wikiThe target wiki, in a form that LBFactory understands (or false if the local wiki shall be used)
Since:
1.20

Implements IORMTable.

Definition at line 593 of file ORMTable.php.

static ORMTable::singleton ( ) [static]

Get an instance of this class.

Since:
1.20
Deprecated:
since 1.21
Returns:
IORMTable

Definition at line 788 of file ORMTable.php.

Referenced by TestORMRowTest\getTableInstance().

ORMTable::unprefixFieldName ( fieldName)

Takes a field name with prefix and returns the unprefixed equivalent.

Since:
1.20
Parameters:
string$fieldName
Returns:
string

Implements IORMTable.

Definition at line 776 of file ORMTable.php.

Takes an array of field names with prefix and returns the unprefixed equivalent.

Since:
1.20
Parameters:
array$fieldNames
Returns:
array

Implements IORMTable.

Definition at line 763 of file ORMTable.php.

ORMTable::update ( array values,
array conditions = array() 
)

Update the records matching the provided conditions by setting the fields that are keys in the $values param to their corresponding values.

Since:
1.20
Parameters:
array$values
array$conditions
Returns:
boolean Success indicator

Implements IORMTable.

Definition at line 651 of file ORMTable.php.

ORMTable::updateRow ( IORMRow row,
functionName = null 
)

Updates the provided row in the database.

Since:
1.22
Parameters:
IORMRow$rowThe row to save
string | null$functionName
Returns:
boolean Success indicator

Definition at line 958 of file ORMTable.php.

ORMTable::updateSummaryFields ( summaryFields = null,
array conditions = array() 
)

Computes the values of the summary fields of the objects matching the provided conditions.

Since:
1.20
Parameters:
array | string | null$summaryFields
array$conditions

Implements IORMTable.

Definition at line 673 of file ORMTable.php.


Member Data Documentation

array ORMTable::$defaults = array() [protected]
Since:
1.21

Definition at line 71 of file ORMTable.php.

string ORMTable::$fieldPrefix = '' [protected]
Since:
1.21

Definition at line 59 of file ORMTable.php.

string [] ORMTable::$fields = array() [protected]
Since:
1.21

Definition at line 53 of file ORMTable.php.

ORMTable::$instanceCache = array() [static, protected]

Definition at line 41 of file ORMTable.php.

integer ORMTable::$readDb = DB_SLAVE [protected]

ID of the database connection to use for read operations.

Can be changed via

See also:
setReadDb.
Since:
1.20

DB_ enum

Definition at line 80 of file ORMTable.php.

string ORMTable::$rowClass = 'ORMRow' [protected]
Since:
1.21

Definition at line 65 of file ORMTable.php.

string ORMTable::$tableName [protected]
Since:
1.21

Definition at line 47 of file ORMTable.php.


The documentation for this class was generated from the following file: