API CHANGE: replaced Database::USE_ANSI_SQL with DB::USE_ANSI_SQL

API CHANGE: replaced Database::alteration_message() with DB::alteration_message()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90097 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-10-26 22:03:29 +00:00
parent 5ca90fd00b
commit 994e93f790
9 changed files with 41 additions and 29 deletions

View File

@ -6,6 +6,15 @@
* @subpackage model
*/
class DB {
/**
* This constant was added in SilverStripe 2.4 to indicate that SQL-queries
* should now use ANSI-compatible syntax. The most notable affect of this
* change is that table and field names should be escaped with double quotes
* and not backticks
*/
const USE_ANSI_SQL = true;
/**
* The global database connection.
* @var SS_Database
@ -291,5 +300,13 @@ class DB {
static function quiet() {
return self::getConn()->quiet();
}
/**
* Show a message about database alteration.
*/
static function alteration_message($message,$type="") {
return self::getConn()->alterationMessage($message, $type);
}
}
?>

View File

@ -2907,7 +2907,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
$obj = new $className($record);
$obj->write();
}
SS_Database::alteration_message("Added default records to $className table","created");
DB::alteration_message("Added default records to $className table","created");
}
}

View File

@ -6,14 +6,6 @@
* @subpackage model
*/
abstract class SS_Database {
/**
* This constant was added in SilverStripe 2.4 to indicate that SQL-queries
* should now use ANSI-compatible syntax. The most notable affect of this
* change is that table and field names should be escaped with double quotes
* and not backticks
*/
const USE_ANSI_SQL = true;
/**
* Connection object to the database.
* @param resource
@ -25,7 +17,7 @@ abstract class SS_Database {
* will be displayed, eg creation of tables.
* @param boolean
*/
public static $supressOutput = false;
protected $supressOutput = false;
/**
* Execute the given SQL query.
@ -264,7 +256,7 @@ abstract class SS_Database {
if(!isset($this->tableList[strtolower($table)])) {
$this->transCreateTable($table, $options, $extensions);
SS_Database::alteration_message("Table $table: created","created");
$this->alterationMessage("Table $table: created","created");
} else {
$this->checkAndRepairTable($table, $options);
@ -331,7 +323,7 @@ abstract class SS_Database {
$suffix = $suffix ? ($suffix+1) : 2;
}
$this->renameTable($table, "_obsolete_{$table}$suffix");
SS_Database::alteration_message("Table $table: renamed to _obsolete_{$table}$suffix","obsolete");
$this->alterationMessage("Table $table: renamed to _obsolete_{$table}$suffix","obsolete");
}
}
@ -384,11 +376,11 @@ abstract class SS_Database {
if($newTable || !isset($this->indexList[$table][$index_alt])) {
$this->transCreateIndex($table, $index, $spec);
SS_Database::alteration_message("Index $table.$index: created as $spec","created");
$this->alterationMessage("Index $table.$index: created as $spec","created");
} else if($array_spec != DB::getConn()->convertIndexSpec($spec)) {
$this->transAlterIndex($table, $index, $spec);
$spec_msg=DB::getConn()->convertIndexSpec($spec);
SS_Database::alteration_message("Index $table.$index: changed to $spec_msg <i style=\"color: #AAA\">(from {$array_spec})</i>","changed");
$this->alterationMessage("Index $table.$index: changed to $spec_msg <i style=\"color: #AAA\">(from {$array_spec})</i>","changed");
}
}
@ -464,7 +456,7 @@ abstract class SS_Database {
$this->transCreateField($table, $field, $spec_orig);
Profiler::unmark('createField');
SS_Database::alteration_message("Field $table.$field: created as $spec_orig","created");
$this->alterationMessage("Field $table.$field: created as $spec_orig","created");
} else if($fieldValue != $specValue) {
// If enums are being modified, then we need to fix existing data in the table.
// Update any records where the enum is set to a legacy value to be set to the default.
@ -494,13 +486,13 @@ abstract class SS_Database {
$query .= "'{$holder[$i]}')";
DB::query($query);
$amount = DB::affectedRows();
SS_Database::alteration_message("Changed $amount rows to default value of field $field (Value: $default)");
$this->alterationMessage("Changed $amount rows to default value of field $field (Value: $default)");
}
}
Profiler::mark('alterField');
$this->transAlterField($table, $field, $spec_orig);
Profiler::unmark('alterField');
SS_Database::alteration_message("Field $table.$field: changed to $specValue <i style=\"color: #AAA\">(from {$fieldValue})</i>","changed");
$this->alterationMessage("Field $table.$field: changed to $specValue <i style=\"color: #AAA\">(from {$fieldValue})</i>","changed");
}
Profiler::unmark('requireField');
}
@ -519,7 +511,7 @@ abstract class SS_Database {
$suffix = $suffix ? ($suffix+1) : 2;
}
$this->renameField($table, $fieldName, "_obsolete_{$fieldName}$suffix");
SS_Database::alteration_message("Field $table.$fieldName: renamed to $table._obsolete_{$fieldName}$suffix","obsolete");
$this->alterationMessage("Field $table.$fieldName: renamed to $table._obsolete_{$fieldName}$suffix","obsolete");
}
}
@ -614,11 +606,14 @@ abstract class SS_Database {
* Enable supression of database messages.
*/
function quiet() {
SS_Database::$supressOutput = true;
$this->supressOutput = true;
}
static function alteration_message($message,$type=""){
if(!SS_Database::$supressOutput) {
/**
* Show a message about database alteration
*/
function alterationMessage($message,$type=""){
if(!$this->supressOutput) {
$color = "";
switch ($type){
case "created":

View File

@ -68,7 +68,7 @@ class ErrorPage extends Page {
$errorpage->Status = 'New page';
$errorpage->write();
SS_Database::alteration_message('404 page created', 'created');
DB::alteration_message('404 page created', 'created');
}
}

View File

@ -261,7 +261,7 @@ class MySQLDatabase extends SS_Database {
if($alteredOptions && isset($alteredOptions[get_class($this)])) {
$this->query(sprintf("ALTER TABLE \"%s\" %s", $tableName, $alteredOptions[get_class($this)]));
SS_Database::alteration_message(
DB::alteration_message(
sprintf("Table %s options changed: %s", $tableName, $alteredOptions[get_class($this)]),
"changed"
);
@ -281,7 +281,7 @@ class MySQLDatabase extends SS_Database {
*/
public function checkAndRepairTable($tableName) {
if(!$this->runTableCheckCommand("CHECK TABLE \"$tableName\"")) {
SS_Database::alteration_message("Table $tableName: repaired","repaired");
DB::alteration_message("Table $tableName: repaired","repaired");
return $this->runTableCheckCommand("REPAIR TABLE \"$tableName\" USE_FRM");
} else {
return true;

View File

@ -107,7 +107,7 @@ class SiteConfig extends DataObject implements PermissionProvider {
$siteConfig = DataObject::get_one('SiteConfig');
if(!$siteConfig) {
self::make_site_config();
Database::alteration_message("Added default site config","created");
DB::alteration_message("Added default site config","created");
}
}

View File

@ -1236,7 +1236,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$homepage->write();
$homepage->publish("Stage", "Live");
$homepage->flushCache();
SS_Database::alteration_message("Home page created","created");
DB::alteration_message("Home page created","created");
}
if(DB::query("SELECT COUNT(*) FROM \"SiteTree\"")->value() == 1) {
@ -1247,7 +1247,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$aboutus->Status = "Published";
$aboutus->write();
$aboutus->publish("Stage", "Live");
SS_Database::alteration_message("About Us created","created");
DV::alteration_message("About Us created","created");
$contactus = new Page();
$contactus->Title = _t('SiteTree.DEFAULTCONTACTTITLE', 'Contact Us');

View File

@ -618,7 +618,7 @@ class Translatable extends DataObjectDecorator implements PermissionProvider {
unset($obj);
}
}
SS_Database::alteration_message(sprintf(
DB::alteration_message(sprintf(
"Added default locale '%s' to table %s","changed",
Translatable::default_locale(),
$this->owner->class

View File

@ -954,7 +954,7 @@ class Member extends DataObject {
if(!DB::query("SELECT * FROM \"Member\"")->value() && isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
Security::findAnAdministrator($_REQUEST['username'], $_REQUEST['password']);
SS_Database::alteration_message("Added admin account","created");
DB::alteration_message("Added admin account","created");
}
}