Permalink
Browse files

BackwardsCompatibilityBreak - Renamed fORMDatabase::getInstance() to …

…fORMDatabase::retrieve() and renamed fORMSchema::getInstance() to fORMSchema::retrieve()
  • Loading branch information...
wbond committed Oct 16, 2008
1 parent 001a8f0 commit 57b8a0345897ab73f89e4ba83556e85c90b3a2dc
View
@@ -325,7 +325,7 @@ public function __construct($primary_key=NULL)
}
// Check the primary keys
$pk_columns = fORMSchema::getInstance()->getKeys(fORM::tablize($this), 'primary');
$pk_columns = fORMSchema::retrieve()->getKeys(fORM::tablize($this), 'primary');
if ((sizeof($pk_columns) > 1 && array_keys($primary_key) != $pk_columns) || (sizeof($pk_columns) == 1 && !is_scalar($primary_key))) {
fCore::toss(
'fProgrammerException',
@@ -349,7 +349,7 @@ public function __construct($primary_key=NULL)
// Create an empty array for new objects
} else {
$column_info = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($this));
$column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this));
foreach ($column_info as $column => $info) {
$this->values[$column] = NULL;
}
@@ -476,12 +476,12 @@ public function delete()
$table = fORM::tablize($this);
$inside_db_transaction = fORMDatabase::getInstance()->isInsideTransaction();
$inside_db_transaction = fORMDatabase::retrieve()->isInsideTransaction();
try {
if (!$inside_db_transaction) {
fORMDatabase::getInstance()->translatedQuery('BEGIN');
fORMDatabase::retrieve()->translatedQuery('BEGIN');
}
fORM::callHookCallback(
@@ -493,8 +493,8 @@ public function delete()
);
// Check to ensure no foreign dependencies prevent deletion
$one_to_many_relationships = fORMSchema::getInstance()->getRelationships($table, 'one-to-many');
$many_to_many_relationships = fORMSchema::getInstance()->getRelationships($table, 'many-to-many');
$one_to_many_relationships = fORMSchema::retrieve()->getRelationships($table, 'one-to-many');
$many_to_many_relationships = fORMSchema::retrieve()->getRelationships($table, 'many-to-many');
$relationships = array_merge($one_to_many_relationships, $many_to_many_relationships);
$records_sets_to_delete = array();
@@ -548,7 +548,7 @@ public function delete()
// Delete this record
$sql = 'DELETE FROM ' . $table . ' WHERE ' . fORMDatabase::createPrimaryKeyWhereClause($table, $table, $this->values, $this->old_values);
$result = fORMDatabase::getInstance()->translatedQuery($sql);
$result = fORMDatabase::retrieve()->translatedQuery($sql);
// Delete related records
@@ -569,7 +569,7 @@ public function delete()
);
if (!$inside_db_transaction) {
fORMDatabase::getInstance()->translatedQuery('COMMIT');
fORMDatabase::retrieve()->translatedQuery('COMMIT');
}
fORM::callHookCallback(
@@ -582,16 +582,16 @@ public function delete()
// If we just deleted an object that has an auto-incrementing primary key,
// lets delete that value from the object since it is no longer valid
$column_info = fORMSchema::getInstance()->getColumnInfo($table);
$pk_columns = fORMSchema::getInstance()->getKeys($table, 'primary');
$column_info = fORMSchema::retrieve()->getColumnInfo($table);
$pk_columns = fORMSchema::retrieve()->getKeys($table, 'primary');
if (sizeof($pk_columns) == 1 && $column_info[$pk_columns[0]]['auto_increment']) {
$this->values[$pk_columns[0]] = NULL;
unset($this->old_values[$pk_columns[0]]);
}
} catch (fPrintableException $e) {
if (!$inside_db_transaction) {
fORMDatabase::getInstance()->translatedQuery('ROLLBACK');
fORMDatabase::retrieve()->translatedQuery('ROLLBACK');
}
fORM::callHookCallback(
@@ -664,7 +664,7 @@ protected function encode($column, $formatting=NULL)
);
}
$column_type = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($this), $column, 'type');
$column_type = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this), $column, 'type');
// Ensure the programmer is calling the function properly
if (in_array($column_type, array('blob'))) {
@@ -714,7 +714,7 @@ protected function encode($column, $formatting=NULL)
// Make sure we don't mangle a non-float value
if ($column_type == 'float' && is_numeric($value)) {
$column_decimal_places = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($this), $column, 'decimal_places');
$column_decimal_places = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this), $column, 'decimal_places');
// If the user passed in a formatting value, use it
if ($formatting !== NULL && is_numeric($formatting)) {
@@ -755,7 +755,7 @@ public function exists()
);
}
$pk_columns = fORMSchema::getInstance()->getKeys(fORM::tablize($this), 'primary');
$pk_columns = fORMSchema::retrieve()->getKeys(fORM::tablize($this), 'primary');
foreach ($pk_columns as $pk_column) {
if ((self::has($this->old_values, $pk_column) && self::retrieve($this->old_values, $pk_column) === NULL) || $this->values[$pk_column] === NULL) {
return FALSE;
@@ -805,7 +805,7 @@ protected function inspect($column, $element=NULL)
);
}
$info = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($this), $column);
$info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this), $column);
if (!in_array($info['type'], array('varchar', 'char', 'text'))) {
unset($info['valid_values']);
@@ -863,7 +863,7 @@ public function load()
$table = fORM::tablize($this);
$sql = 'SELECT * FROM ' . $table . ' WHERE ' . fORMDatabase::createPrimaryKeyWhereClause($table, $table, $this->values, $this->old_values);
$result = fORMDatabase::getInstance()->translatedQuery($sql);
$result = fORMDatabase::retrieve()->translatedQuery($sql);
$result->tossIfNoResults();
} catch (fExpectedException $e) {
@@ -889,20 +889,20 @@ public function load()
protected function loadFromResult(fResult $result)
{
$row = $result->current();
$column_info = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($this));
$column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this));
foreach ($row as $column => $value) {
if ($value === NULL) {
$this->values[$column] = $value;
} else {
$this->values[$column] = fORMDatabase::getInstance()->unescape($column_info[$column]['type'], $value);
$this->values[$column] = fORMDatabase::retrieve()->unescape($column_info[$column]['type'], $value);
}
$this->values[$column] = fORM::objectify($this, $column, $this->values[$column]);
}
// Save this object to the identity map
$pk_columns = fORMSchema::getInstance()->getKeys(fORM::tablize($this), 'primary');
$pk_columns = fORMSchema::retrieve()->getKeys(fORM::tablize($this), 'primary');
$pk_data = array();
foreach ($pk_columns as $pk_column) {
@@ -935,7 +935,7 @@ protected function loadFromIdentityMap($source)
$row = $source;
}
$pk_columns = fORMSchema::getInstance()->getKeys(fORM::tablize($this), 'primary');
$pk_columns = fORMSchema::retrieve()->getKeys(fORM::tablize($this), 'primary');
// If we don't have a value for each primary key, we can't load
if (is_array($row) && array_diff($pk_columns, array_keys($row))) {
@@ -991,7 +991,7 @@ public function populate()
$table = fORM::tablize($this);
$column_info = fORMSchema::getInstance()->getColumnInfo($table);
$column_info = fORMSchema::retrieve()->getColumnInfo($table);
foreach ($column_info as $column => $info) {
if (fRequest::check($column)) {
$method = 'set' . fGrammar::camelize($column, TRUE);
@@ -1036,7 +1036,7 @@ protected function prepare($column, $formatting=NULL)
);
}
$column_info = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($this), $column);
$column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this), $column);
$column_type = $column_info['type'];
// Ensure the programmer is calling the function properly
@@ -1134,7 +1134,7 @@ public function reflect($include_doc_comments=FALSE)
{
$signatures = array();
$columns_info = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($this));
$columns_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this));
foreach ($columns_info as $column => $column_info) {
$camelized_column = fGrammar::camelize($column, TRUE);
@@ -1427,23 +1427,23 @@ public function store()
try {
$table = fORM::tablize($this);
$column_info = fORMSchema::getInstance()->getColumnInfo($table);
$column_info = fORMSchema::retrieve()->getColumnInfo($table);
// New auto-incrementing records require lots of special stuff, so we'll detect them here
$new_autoincrementing_record = FALSE;
if (!$this->exists()) {
$pk_columns = fORMSchema::getInstance()->getKeys($table, 'primary');
$pk_columns = fORMSchema::retrieve()->getKeys($table, 'primary');
if (sizeof($pk_columns) == 1 && $column_info[$pk_columns[0]]['auto_increment']) {
$new_autoincrementing_record = TRUE;
$pk_column = $pk_columns[0];
}
}
$inside_db_transaction = fORMDatabase::getInstance()->isInsideTransaction();
$inside_db_transaction = fORMDatabase::retrieve()->isInsideTransaction();
if (!$inside_db_transaction) {
fORMDatabase::getInstance()->translatedQuery('BEGIN');
fORMDatabase::retrieve()->translatedQuery('BEGIN');
}
fORM::callHookCallback(
@@ -1482,7 +1482,7 @@ public function store()
} else {
$sql = $this->constructUpdateSQL($sql_values);
}
$result = fORMDatabase::getInstance()->translatedQuery($sql);
$result = fORMDatabase::retrieve()->translatedQuery($sql);
// If there is an auto-incrementing primary key, grab the value from the database
@@ -1493,8 +1493,8 @@ public function store()
// Storing *-to-many relationships
$one_to_many_relationships = fORMSchema::getInstance()->getRelationships($table, 'one-to-many');
$many_to_many_relationships = fORMSchema::getInstance()->getRelationships($table, 'many-to-many');
$one_to_many_relationships = fORMSchema::retrieve()->getRelationships($table, 'one-to-many');
$many_to_many_relationships = fORMSchema::retrieve()->getRelationships($table, 'many-to-many');
foreach ($this->related_records as $related_table => $relationship) {
foreach ($relationship as $route => $info) {
@@ -1521,7 +1521,7 @@ public function store()
);
if (!$inside_db_transaction) {
fORMDatabase::getInstance()->translatedQuery('COMMIT');
fORMDatabase::retrieve()->translatedQuery('COMMIT');
}
fORM::callHookCallback(
@@ -1535,7 +1535,7 @@ public function store()
} catch (fPrintableException $e) {
if (!$inside_db_transaction) {
fORMDatabase::getInstance()->translatedQuery('ROLLBACK');
fORMDatabase::retrieve()->translatedQuery('ROLLBACK');
}
fORM::callHookCallback(
View
@@ -341,7 +341,7 @@ static public function defineActiveRecordClass($class)
if (class_exists($class, FALSE)) {
return;
}
$tables = fORMSchema::getInstance()->getTables();
$tables = fORMSchema::retrieve()->getTables();
$table = self::tablize($class);
if (in_array($table, $tables)) {
eval('class ' . $class . ' extends fActiveRecord { };');
@@ -469,7 +469,7 @@ static public function objectify($class, $column, $value)
$table = self::tablize($class);
// Turn date/time values into objects
$column_type = fORMSchema::getInstance()->getColumnInfo($table, $column, 'type');
$column_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
if ($value !== NULL && in_array($column_type, array('date', 'time', 'timestamp'))) {
try {
View
@@ -71,7 +71,7 @@ static public function configureEmailColumn($class, $column)
{
$class = fORM::getClass($class);
$table = fORM::tablize($class);
$data_type = fORMSchema::getInstance()->getColumnInfo($table, $column, 'type');
$data_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
$valid_data_types = array('varchar', 'char', 'text');
if (!in_array($data_type, $valid_data_types)) {
@@ -117,7 +117,7 @@ static public function configureLinkColumn($class, $column)
{
$class = fORM::getClass($class);
$table = fORM::tablize($class);
$data_type = fORMSchema::getInstance()->getColumnInfo($table, $column, 'type');
$data_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
$valid_data_types = array('varchar', 'char', 'text');
if (!in_array($data_type, $valid_data_types)) {
@@ -174,7 +174,7 @@ static public function configureNumberColumn($class, $column)
{
$class = fORM::getClass($class);
$table = fORM::tablize($class);
$data_type = fORMSchema::getInstance()->getColumnInfo($table, $column, 'type');
$data_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
$valid_data_types = array('integer', 'float');
if (!in_array($data_type, $valid_data_types)) {
@@ -241,7 +241,7 @@ static public function configureRandomColumn($class, $column, $type, $length)
{
$class = fORM::getClass($class);
$table = fORM::tablize($class);
$data_type = fORMSchema::getInstance()->getColumnInfo($table, $column, 'type');
$data_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
$valid_data_types = array('varchar', 'char', 'text');
if (!in_array($data_type, $valid_data_types)) {
@@ -315,7 +315,7 @@ static public function encodeNumberColumn($object, &$values, &$old_values, &$rel
{
list ($action, $column) = fORM::parseMethod($method_name);
$column_info = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($object), $column);
$column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($object), $column);
$value = $values[$column];
if ($value instanceof fNumber) {
@@ -349,7 +349,7 @@ static public function inspect($object, &$values, &$old_values, &$related_record
list ($action, $column) = fORM::parseMethod($method_name);
$class = get_class($object);
$info = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($class), $column);
$info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class), $column);
$element = (isset($parameters[0])) ? $parameters[0] : NULL;
if (!in_array($info['type'], array('varchar', 'char', 'text'))) {
@@ -470,7 +470,7 @@ static public function prepareNumberColumn($object, &$values, &$old_values, &$re
{
list ($action, $column) = fORM::parseMethod($method_name);
$column_info = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($object), $column);
$column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($object), $column);
$value = $values[$column];
if ($value instanceof fNumber) {
@@ -525,7 +525,7 @@ static public function reflect($class, &$signatures, $include_doc_comments)
if (isset(self::$number_columns[$class])) {
foreach(self::$number_columns[$class] as $column => $enabled) {
$camelized_column = fGrammar::camelize($column, TRUE);
$type = fORMSchema::getInstance()->getColumnInfo(fORM::tablize($class), $column, 'type');
$type = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class), $column, 'type');
// Get and set methods
$signature = '';
@@ -637,7 +637,7 @@ static public function setRandomStrings($object, &$values, &$old_values, &$relat
foreach (self::$random_columns[$class] as $column => $settings) {
// Check to see if this is a unique column
$unique_keys = fORMSchema::getInstance()->getKeys($table, 'unique');
$unique_keys = fORMSchema::retrieve()->getKeys($table, 'unique');
$is_unique_column = FALSE;
foreach ($unique_keys as $unique_key) {
if ($unique_key == array($column)) {
@@ -646,9 +646,9 @@ static public function setRandomStrings($object, &$values, &$old_values, &$relat
$value = fCryptography::randomString($settings['length'], $settings['type']);
// See if this is unique
$sql = "SELECT " . $column . " FROM " . $table . " WHERE " . $column . " = " . fORMDatabase::getInstance()->escape('string', $value);
$sql = "SELECT " . $column . " FROM " . $table . " WHERE " . $column . " = " . fORMDatabase::retrieve()->escape('string', $value);
} while (fORMDatabase::getInstance()->query($sql)->getReturnedRows());
} while (fORMDatabase::retrieve()->query($sql)->getReturnedRows());
}
}
Oops, something went wrong.

0 comments on commit 57b8a03

Please sign in to comment.