MediaWiki
1.23.2
|
Public Member Functions | |
__construct ( $tableName='', array $fields=array(), array $defaults=array(), $rowClass=null, $fieldPrefix='') | |
Constructor. More... | |
addToField (array $conditions, $field, $amount) | |
Add an amount (can be negative) to the specified field (needs to be numeric). More... | |
canHaveField ( $name) | |
Gets if the object can take a certain field. More... | |
count (array $conditions=array(), array $options=array()) | |
Returns the amount of matching records. More... | |
delete (array $conditions, $functionName=null) | |
Removes the object from the database. More... | |
exists () | |
Checks if the table exists. More... | |
getAPIParams ( $requireParams=false, $setDefaults=false) | |
Get API parameters for the fields supported by this object. More... | |
getDefaults () | |
Returns a list of default field values. More... | |
getFieldDescriptions () | |
Returns an array with the fields and their descriptions. More... | |
getFieldNames () | |
Return the names of the fields. More... | |
getFields () | |
getFieldsFromDBResult (stdClass $result) | |
Get an array with fields from a database result, that can be fed directly to the constructor or to setFields. More... | |
getName () | |
getPrefixedField ( $field) | |
Takes in a field and returns an it's prefixed version, ready for db usage. More... | |
getPrefixedFields (array $fields) | |
Takes in a field or array of fields and returns an array with their prefixed versions, ready for db usage. More... | |
getPrefixedValues (array $values) | |
Takes in an associative array with field names as keys and their values as value. More... | |
getReadDb () | |
Get the database ID used for read operations. More... | |
getReadDbConnection () | |
Get the database type used for read operations. More... | |
getRowClass () | |
getSummaryFields () | |
Returns a list of the summary fields. More... | |
getTargetWiki () | |
Get the ID of the any foreign wiki to use as a target for database operations. More... | |
getWriteDbConnection () | |
Get the database type used for read operations. More... | |
has (array $conditions=array()) | |
Returns if there is at least one record matching the provided conditions. More... | |
insertRow (IORMRow $row, $functionName=null, array $options=null) | |
Inserts the provided row into the database. More... | |
newFromArray (array $data, $loadDefaults=false) | |
newFromDBResult (stdClass $result) | |
newRow (array $fields, $loadDefaults=false) | |
Get a new instance of the class from an array. More... | |
newRowFromDBResult (stdClass $result) | |
Get a new instance of the class from a database result. More... | |
rawSelect ( $fields=null, array $conditions=array(), array $options=array(), $functionName=null) | |
Do the actual select. More... | |
rawSelectRow (array $fields, array $conditions=array(), array $options=array(), $functionName=null) | |
Selects the the specified fields of the records matching the provided conditions. More... | |
releaseConnection (DatabaseBase $db) | |
Releases the lease on the given database connection. More... | |
removeRow (IORMRow $row, $functionName=null) | |
Removes the provided row from the database. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
selectRow ( $fields=null, array $conditions=array(), array $options=array(), $functionName=null) | |
Selects the the specified fields of the first matching record. More... | |
setReadDb ( $db) | |
Set the database ID to use for read operations, use DB_XXX constants or an index to the load balancer setup. More... | |
setTargetWiki ( $wiki) | |
Set the ID of the any foreign wiki to use as a target for database operations. More... | |
unprefixFieldName ( $fieldName) | |
Takes a field name with prefix and returns the unprefixed equivalent. More... | |
unprefixFieldNames (array $fieldNames) | |
Takes an array of field names with prefix and returns the unprefixed equivalent. More... | |
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. More... | |
updateRow (IORMRow $row, $functionName=null) | |
Updates the provided row in the database. More... | |
updateSummaryFields ( $summaryFields=null, array $conditions=array()) | |
Computes the values of the summary fields of the objects matching the provided conditions. More... | |
Public Member Functions inherited from DBAccessBase | |
__construct ( $wiki=false) | |
getLoadBalancer () | |
Get the database type used for read operations. More... | |
Public Member Functions inherited from IORMTable | |
getLoadBalancer () | |
Get the database type used for read operations. More... | |
Static Public Member Functions | |
static | singleton () |
Get an instance of this class. More... | |
Protected Member Functions | |
getFieldPrefix () | |
Gets the db field prefix. More... | |
getWriteValues (IORMRow $row) | |
Gets the fields => values to write to the table. More... | |
Protected Member Functions inherited from DBAccessBase | |
getConnection ( $id, $groups=array()) | |
Returns a database connection. More... | |
Protected Attributes | |
array | $defaults = array() |
string | $fieldPrefix = '' |
string[] | $fields = array() |
integer | $readDb = DB_SLAVE |
ID of the database connection to use for read operations. More... | |
string | $rowClass = 'ORMRow' |
string | $tableName |
Protected Attributes inherited from DBAccessBase | |
string bool | $wiki = false |
$wiki The target wiki's name. More... | |
Static Protected Attributes | |
static | $instanceCache = array() |
Additional Inherited Members | |
Public Attributes inherited from IDBAccessObject | |
const | READ_LATEST = 1 |
const | READ_LOCKING = 3 |
const | READ_NONE = -1 |
const | READ_NORMAL = 0 |
Definition at line 31 of file ORMTable.php.
ORMTable::__construct | ( | $tableName = '' , |
|
array | $fields = array() , |
||
array | $defaults = array() , |
||
$rowClass = null , |
|||
$fieldPrefix = '' |
|||
) |
Constructor.
string | $tableName | |
string[] | $fields | |
array | $defaults | |
string | null | $rowClass | |
string | $fieldPrefix |
Definition at line 92 of file ORMTable.php.
References $defaults, $fieldPrefix, $fields, $rowClass, $tableName, and tableName().
ORMTable::addToField | ( | array | $conditions, |
$field, | |||
$amount | |||
) |
Add an amount (can be negative) to the specified field (needs to be numeric).
array | $conditions | |
string | $field | |
integer | $amount |
MWException |
Definition at line 1089 of file ORMTable.php.
References $success, array(), getName(), getPrefixedField(), getPrefixedValues(), getWriteDbConnection(), and releaseConnection().
ORMTable::canHaveField | ( | $name | ) |
Gets if the object can take a certain field.
string | $name |
Implements IORMTable.
Definition at line 960 of file ORMTable.php.
References $name, and getFields().
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.
array | $conditions | |
array | $options |
Implements IORMTable.
Definition at line 465 of file ORMTable.php.
References $options, $res, array(), getPrefixedValues(), and rawSelectRow().
Referenced by selectFields().
ORMTable::delete | ( | array | $conditions, |
$functionName = null |
|||
) |
Removes the object from the database.
array | $conditions | |
string | null | $functionName |
Implements IORMTable.
Definition at line 486 of file ORMTable.php.
References array(), getName(), getPrefixedValues(), getWriteDbConnection(), and releaseConnection().
ORMTable::exists | ( | ) |
Checks if the table exists.
Implements IORMTable.
Definition at line 443 of file ORMTable.php.
References $dbr, getName(), getReadDbConnection(), and releaseConnection().
Get API parameters for the fields supported by this object.
boolean | $requireParams | |
boolean | $setDefaults |
Implements IORMTable.
Definition at line 510 of file ORMTable.php.
References $defaults, $params, $type, array(), as, getDefaults(), getFields(), ApiBase\PARAM_DFLT, ApiBase\PARAM_ISMULTI, ApiBase\PARAM_REQUIRED, and ApiBase\PARAM_TYPE.
ORMTable::getDefaults | ( | ) |
Returns a list of default field values.
field name => field value
Implements IORMTable.
Definition at line 168 of file ORMTable.php.
References $defaults.
Referenced by getAPIParams().
ORMTable::getFieldDescriptions | ( | ) |
Returns an array with the fields and their descriptions.
field name => field description
Implements IORMTable.
Definition at line 560 of file ORMTable.php.
References array().
ORMTable::getFieldNames | ( | ) |
Return the names of the fields.
Implements IORMTable.
Definition at line 947 of file ORMTable.php.
References getFields().
|
protected |
Gets the db field prefix.
Reimplemented in TestORMTable, and PageORMTableForTesting.
Definition at line 129 of file ORMTable.php.
References $fieldPrefix.
Referenced by getPrefixedField(), and unprefixFieldName().
ORMTable::getFields | ( | ) |
MWException |
Implements IORMTable.
Reimplemented in TestORMTable, and PageORMTableForTesting.
Definition at line 152 of file ORMTable.php.
References $fields, and array().
Referenced by canHaveField(), getAPIParams(), getFieldNames(), getFieldsFromDBResult(), getWriteValues(), and rawSelect().
ORMTable::getFieldsFromDBResult | ( | stdClass | $result | ) |
Get an array with fields from a database result, that can be fed directly to the constructor or to setFields.
stdClass | $result |
MWException |
Implements IORMTable.
Definition at line 825 of file ORMTable.php.
References $fields, $name, $value, array(), as, getFields(), and unprefixFieldNames().
Referenced by newRowFromDBResult(), and selectFields().
ORMTable::getName | ( | ) |
MWException |
Implements IORMTable.
Reimplemented in TestORMTable, and PageORMTableForTesting.
Definition at line 114 of file ORMTable.php.
References $tableName, and tableName().
Referenced by addToField(), delete(), exists(), insertRow(), rawSelect(), rawSelectRow(), update(), and updateRow().
ORMTable::getPrefixedField | ( | $field | ) |
Takes in a field and returns an it's prefixed version, ready for db usage.
string | array | $field |
Implements IORMTable.
Definition at line 766 of file ORMTable.php.
References getFieldPrefix().
Referenced by addToField(), getPrefixedFields(), getPrefixedValues(), and getWriteValues().
ORMTable::getPrefixedFields | ( | array | $fields | ) |
Takes in a field or array of fields and returns an array with their prefixed versions, ready for db usage.
array | string | $fields |
Implements IORMTable.
Definition at line 749 of file ORMTable.php.
References $fields, as, and getPrefixedField().
Referenced by rawSelect().
ORMTable::getPrefixedValues | ( | array | $values | ) |
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.
array | $values |
Implements IORMTable.
Definition at line 717 of file ORMTable.php.
References $value, array(), as, and getPrefixedField().
Referenced by addToField(), count(), delete(), rawSelect(), update(), and updateRow().
ORMTable::getReadDb | ( | ) |
Get the database ID used for read operations.
Implements IORMTable.
Definition at line 571 of file ORMTable.php.
References $readDb.
Referenced by getReadDbConnection(), and updateSummaryFields().
ORMTable::getReadDbConnection | ( | ) |
Get the database type used for read operations.
This is to be used instead of wfGetDB.
Implements IORMTable.
Definition at line 621 of file ORMTable.php.
References array(), DBAccessBase\getConnection(), and getReadDb().
Referenced by exists(), rawSelect(), and rawSelectRow().
ORMTable::getRowClass | ( | ) |
Implements IORMTable.
Reimplemented in TestORMTable, and PageORMTableForTesting.
Definition at line 140 of file ORMTable.php.
References $rowClass.
Referenced by newRow().
ORMTable::getSummaryFields | ( | ) |
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.
Implements IORMTable.
Definition at line 181 of file ORMTable.php.
References array().
ORMTable::getTargetWiki | ( | ) |
Get the ID of the any foreign wiki to use as a target for database operations.
Implements IORMTable.
Definition at line 595 of file ORMTable.php.
References DBAccessBase\$wiki.
ORMTable::getWriteDbConnection | ( | ) |
Get the database type used for read operations.
This is to be used instead of wfGetDB.
Implements IORMTable.
Definition at line 635 of file ORMTable.php.
References array(), DB_MASTER, and DBAccessBase\getConnection().
Referenced by addToField(), delete(), insertRow(), update(), and updateRow().
|
protected |
Gets the fields => values to write to the table.
IORMRow | $row |
Definition at line 1032 of file ORMTable.php.
References $name, $type, $value, array(), as, getFields(), IORMRow\getFields(), and getPrefixedField().
Referenced by insertRow(), and updateRow().
Returns if there is at least one record matching the provided conditions.
Condition field names get prefixed.
array | $conditions |
Implements IORMTable.
Definition at line 432 of file ORMTable.php.
References array(), and selectRow().
Inserts the provided row into the database.
IORMRow | $row | |
string | null | $functionName | |
array | null | $options |
Definition at line 1001 of file ORMTable.php.
References $options, $success, getName(), getWriteDbConnection(), getWriteValues(), releaseConnection(), and IORMRow\setField().
array | $data | |
boolean | $loadDefaults |
Definition at line 920 of file ORMTable.php.
ORMTable::newFromDBResult | ( | stdClass | $result | ) |
stdClass | $result |
Definition at line 892 of file ORMTable.php.
References newRowFromDBResult().
Get a new instance of the class from an array.
array | $fields | |
boolean | $loadDefaults |
Implements IORMTable.
Reimplemented in PageORMTableForTesting.
Definition at line 934 of file ORMTable.php.
References $fields, and getRowClass().
Referenced by newRowFromDBResult(), and selectObjects().
ORMTable::newRowFromDBResult | ( | stdClass | $result | ) |
Get a new instance of the class from a database result.
stdClass | $result |
Implements IORMTable.
Definition at line 905 of file ORMTable.php.
References getFieldsFromDBResult(), and newRow().
Referenced by newFromDBResult().
ORMTable::rawSelect | ( | $fields = null , |
|
array | $conditions = array() , |
||
array | $options = array() , |
||
$functionName = null |
|||
) |
Do the actual select.
null | string | array | $fields | |
array | $conditions | |
array | $options | |
null | string | $functionName |
DBQueryError | if the query failed (even if the database was in ignoreErrors mode). |
Implements IORMTable.
Definition at line 247 of file ORMTable.php.
References $dbr, $error, $fields, $options, array(), getFields(), getName(), getPrefixedFields(), getPrefixedValues(), getReadDbConnection(), and releaseConnection().
Referenced by select(), and selectFields().
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.
array | $fields | |
array | $conditions | |
array | $options | |
string | null | $functionName |
Implements IORMTable.
Definition at line 377 of file ORMTable.php.
References $dbr, $options, getName(), getReadDbConnection(), and releaseConnection().
Referenced by count().
ORMTable::releaseConnection | ( | DatabaseBase | $db | ) |
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.
DatabaseBase | $db | the database |
Reimplemented from DBAccessBase.
Definition at line 650 of file ORMTable.php.
Referenced by addToField(), delete(), exists(), insertRow(), rawSelect(), rawSelectRow(), update(), and updateRow().
ORMTable::removeRow | ( | IORMRow | $row, |
$functionName = null |
|||
) |
Removes the provided row from the database.
IORMRow | $row | |
string | null | $functionName |
Definition at line 1067 of file ORMTable.php.
References $success, array(), and IORMRow\getId().
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.
array | string | null | $fields | |
array | $conditions | |
array | $options | |
string | null | $functionName |
Implements IORMTable.
Definition at line 198 of file ORMTable.php.
References $options, $res, and rawSelect().
Referenced by selectRow(), and updateSummaryFields().
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.
array | string | null | $fields | |
array | $conditions | |
array | $options | |
boolean | $collapse | Set to false to always return each result row as associative array. |
string | null | $functionName |
Implements IORMTable.
Definition at line 313 of file ORMTable.php.
References $fields, $options, array(), as, count(), getFieldsFromDBResult(), and rawSelect().
Referenced by selectFieldsRow(), and selectObjects().
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).
array | string | null | $fields | |
array | $conditions | |
array | $options | |
boolean | $collapse | Set to false to always return each result row as associative array. |
string | null | $functionName |
Implements IORMTable.
Definition at line 412 of file ORMTable.php.
References $options, false, and selectFields().
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.
array | string | null | $fields | |
array | $conditions | |
array | $options | |
string | null | $functionName |
DBQueryError | if the query failed (even if the database was in ignoreErrors mode). |
Implements IORMTable.
Definition at line 220 of file ORMTable.php.
References $options, array(), as, newRow(), and selectFields().
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.
array | string | null | $fields | |
array | $conditions | |
array | $options | |
string | null | $functionName |
Implements IORMTable.
Definition at line 354 of file ORMTable.php.
References $options, and select().
Referenced by has().
ORMTable::setReadDb | ( | $db | ) |
Set the database ID to use for read operations, use DB_XXX constants or an index to the load balancer setup.
integer | $db |
Implements IORMTable.
Definition at line 583 of file ORMTable.php.
Referenced by updateSummaryFields().
ORMTable::setTargetWiki | ( | $wiki | ) |
Set the ID of the any foreign wiki to use as a target for database operations.
string | bool | $wiki | The target wiki, in a form that LBFactory understands (or false if the local wiki shall be used) |
Implements IORMTable.
Definition at line 607 of file ORMTable.php.
References DBAccessBase\$wiki, and wiki.
|
static |
Get an instance of this class.
Definition at line 804 of file ORMTable.php.
Referenced by TestORMRowTest\getTableInstance().
ORMTable::unprefixFieldName | ( | $fieldName | ) |
Takes a field name with prefix and returns the unprefixed equivalent.
string | $fieldName |
Implements IORMTable.
Definition at line 792 of file ORMTable.php.
References getFieldPrefix().
ORMTable::unprefixFieldNames | ( | array | $fieldNames | ) |
Takes an array of field names with prefix and returns the unprefixed equivalent.
array | $fieldNames |
Implements IORMTable.
Definition at line 779 of file ORMTable.php.
References array().
Referenced by getFieldsFromDBResult().
Update the records matching the provided conditions by setting the fields that are keys in the $values param to their corresponding values.
array | $values | |
array | $conditions |
Implements IORMTable.
Definition at line 667 of file ORMTable.php.
References getName(), getPrefixedValues(), getWriteDbConnection(), and releaseConnection().
ORMTable::updateRow | ( | IORMRow | $row, |
$functionName = null |
|||
) |
Updates the provided row in the database.
IORMRow | $row | The row to save |
string | null | $functionName |
Definition at line 974 of file ORMTable.php.
References $success, array(), IORMRow\getId(), getName(), getPrefixedValues(), getWriteDbConnection(), getWriteValues(), and releaseConnection().
Computes the values of the summary fields of the objects matching the provided conditions.
array | string | null | $summaryFields | |
array | $conditions |
Implements IORMTable.
Definition at line 690 of file ORMTable.php.
References as, DB_MASTER, getReadDb(), select(), and setReadDb().
Definition at line 70 of file ORMTable.php.
Referenced by __construct(), getAPIParams(), and getDefaults().
|
protected |
Definition at line 58 of file ORMTable.php.
Referenced by __construct(), and getFieldPrefix().
|
protected |
Definition at line 52 of file ORMTable.php.
Referenced by __construct(), getFields(), getFieldsFromDBResult(), getPrefixedFields(), newRow(), rawSelect(), and selectFields().
|
staticprotected |
Definition at line 40 of file ORMTable.php.
|
protected |
ID of the database connection to use for read operations.
Can be changed via
DB_ enum
Definition at line 79 of file ORMTable.php.
Referenced by getReadDb().
|
protected |
Definition at line 64 of file ORMTable.php.
Referenced by __construct(), and getRowClass().
|
protected |