From 994e93f790f8c4e36b5157bd1ee1636301bbdd72 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 26 Oct 2009 22:03:29 +0000 Subject: [PATCH] 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 --- core/model/DB.php | 17 +++++++++++++++++ core/model/DataObject.php | 2 +- core/model/Database.php | 35 +++++++++++++++-------------------- core/model/ErrorPage.php | 2 +- core/model/MySQLDatabase.php | 4 ++-- core/model/SiteConfig.php | 2 +- core/model/SiteTree.php | 4 ++-- core/model/Translatable.php | 2 +- security/Member.php | 2 +- 9 files changed, 41 insertions(+), 29 deletions(-) diff --git a/core/model/DB.php b/core/model/DB.php index 1ce1574ee..c5327774c 100755 --- a/core/model/DB.php +++ b/core/model/DB.php @@ -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); + } + } ?> \ No newline at end of file diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 8781447e4..d46a2ec3f 100755 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -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"); } } diff --git a/core/model/Database.php b/core/model/Database.php index 02e775986..896d44970 100755 --- a/core/model/Database.php +++ b/core/model/Database.php @@ -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 (from {$array_spec})","changed"); + $this->alterationMessage("Index $table.$index: changed to $spec_msg (from {$array_spec})","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 (from {$fieldValue})","changed"); + $this->alterationMessage("Field $table.$field: changed to $specValue (from {$fieldValue})","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": diff --git a/core/model/ErrorPage.php b/core/model/ErrorPage.php index 154aebb48..52cd970b3 100755 --- a/core/model/ErrorPage.php +++ b/core/model/ErrorPage.php @@ -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'); } } diff --git a/core/model/MySQLDatabase.php b/core/model/MySQLDatabase.php index 268af64cc..6a8b1c8ba 100755 --- a/core/model/MySQLDatabase.php +++ b/core/model/MySQLDatabase.php @@ -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; diff --git a/core/model/SiteConfig.php b/core/model/SiteConfig.php index de9635f74..8dce13a2b 100644 --- a/core/model/SiteConfig.php +++ b/core/model/SiteConfig.php @@ -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"); } } diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index d3e792b9d..710896d38 100755 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -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'); diff --git a/core/model/Translatable.php b/core/model/Translatable.php index 039019426..f07a8f650 100755 --- a/core/model/Translatable.php +++ b/core/model/Translatable.php @@ -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 diff --git a/security/Member.php b/security/Member.php index 8affc26ec..97b612c70 100644 --- a/security/Member.php +++ b/security/Member.php @@ -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"); } }