From e386cbae57d7bb6c1b5da9dc966a3e88cc571420 Mon Sep 17 00:00:00 2001 From: Jeremy Shipman Date: Fri, 24 Aug 2007 03:31:14 +0000 Subject: [PATCH] created alteration_message method to replace all the code used to echo changes when dbbuild runs, with appropriate colouring. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@40809 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DataObject.php | 4 +-- core/model/Database.php | 53 ++++++++++++++++++++++++------------ core/model/ErrorPage.php | 5 +--- core/model/MySQLDatabase.php | 5 +--- core/model/SiteTree.php | 10 ++----- security/Member.php | 5 +--- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/core/model/DataObject.php b/core/model/DataObject.php index a6d534c1c..36081b015 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -1595,9 +1595,7 @@ class DataObject extends Controller { $obj = new $baseClass($record); $obj->write(); } - if(!Database::$supressOutput) { - echo "
  • Added default records to $baseClass table
  • "; - } + Database::alteration_message("Added default records to $baseClass table","created"); } } } diff --git a/core/model/Database.php b/core/model/Database.php index 72bbf8d32..189a59997 100755 --- a/core/model/Database.php +++ b/core/model/Database.php @@ -204,9 +204,7 @@ abstract class Database extends Object { function requireTable($table, $fieldSchema = null, $indexSchema = null) { if(!isset($this->tableList[strtolower($table)])) { $this->transCreateTable($table); - if(!Database::$supressOutput) { - echo "
  • Table $table: created
  • "; - } + Database::alteration_message("Table $table: created","created"); } else { $this->checkAndRepairTable($table); } @@ -239,9 +237,7 @@ abstract class Database extends Object { $suffix = $suffix ? ($suffix+1) : 2; } $this->renameTable($table, "_obsolete_{$table}$suffix"); - if(!Database::$supressOutput) { - echo "
  • Table $table: renamed to _obsolete_{$table}$suffix
  • "; - } + Database::alteration_message("Table $table: renamed to _obsolete_{$table}$suffix","obsolete"); } } @@ -266,14 +262,10 @@ abstract class Database extends Object { } if($newTable || !isset($this->indexList[$table][$index])) { $this->transCreateIndex($table, $index, $spec); - if(!Database::$supressOutput) { - echo "
  • Index $table.$index: created as $spec
  • "; - } + Database::alteration_message("Index $table.$index: created as $spec","created"); } else if($this->indexList[$table][$index] != $spec) { $this->transAlterIndex($table, $index, $spec); - if(!Database::$supressOutput) { - echo "
  • Index $table.$index: changed to $spec (from {$this->indexList[$table][$index]})
  • "; - } + Database::alteration_message("Index $table.$index: changed to $spec (from {$this->indexList[$table][$index]})","changed"); } } @@ -302,16 +294,12 @@ abstract class Database extends Object { Profiler::mark('createField'); $this->transCreateField($table, $field, $spec); Profiler::unmark('createField'); - if(!Database::$supressOutput) { - echo "
  • Field $table.$field: created as $spec
  • "; - } + Database::alteration_message("Field $table.$field: created as $spec","created"); } else if($this->fieldList[$table][$field] != $spec) { Profiler::mark('alterField'); $this->transAlterField($table, $field, $spec); Profiler::unmark('alterField'); - if(!Database::$supressOutput) { - echo "
  • Field $table.$field: changed to $spec (from {$this->fieldList[$table][$field]})
  • "; - } + Database::alteration_message("Field $table.$field: changed to $spec (from {$this->fieldList[$table][$field]})","changed"); } Profiler::unmark('requireField'); } @@ -387,6 +375,35 @@ abstract class Database extends Object { Database::$supressOutput = true; } + static function alteration_message($message,$type=""){ + if(!Database::$supressOutput) { + $color = ""; + switch ($type){ + case "created": + $color = "green"; + break; + case "obsolete": + $color = "red"; + break; + case "error": + $color = "red"; + break; + case "deleted": + $color = "red"; + break; + case "changed": + $color = "blue"; + break; + case "repaired": + $color = "blue"; + break; + default: + $color=""; + } + echo "
  • $message
  • "; + } + } + } /** diff --git a/core/model/ErrorPage.php b/core/model/ErrorPage.php index 228adbce7..b11135516 100755 --- a/core/model/ErrorPage.php +++ b/core/model/ErrorPage.php @@ -33,11 +33,8 @@ class ErrorPage extends Page { $errorpage->write(); // Don't publish, as the manifest may not be built yet // $errorpage->publish("Stage", "Live"); - - if(!Database::$supressOutput) { - echo "
  • 404 page created
  • "; - } + Database::alteration_message("404 page created","created"); } } diff --git a/core/model/MySQLDatabase.php b/core/model/MySQLDatabase.php index 56c26f4d1..1e301e553 100644 --- a/core/model/MySQLDatabase.php +++ b/core/model/MySQLDatabase.php @@ -206,10 +206,7 @@ class MySQLDatabase extends Database { */ public function checkAndRepairTable($tableName) { if(!$this->runTableCheckCommand("CHECK TABLE `$tableName`")) { - if(!Database::$supressOutput) { - echo "
  • Table $tableName: repaired
  • "; - } - + Database::alteration_message("Table $tableName: repaired","repaired"); return $this->runTableCheckCommand("REPAIR TABLE `$tableName` USE_FRM"); } else { return true; diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index 29010fe70..177154de9 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -406,10 +406,7 @@ class SiteTree extends DataObject { $homepage->write(); $homepage->publish("Stage", "Live"); $homepage->flushCache(); - - if(!Database::$supressOutput) { - echo "
  • Home page created
  • "; - } + Database::alteration_message("Home page created","created"); } if(DB::query("SELECT COUNT(*) FROM SiteTree")->value() == 1) { @@ -420,10 +417,7 @@ class SiteTree extends DataObject { $aboutus->Status = "Published"; $aboutus->write(); $aboutus->publish("Stage", "Live"); - - if(!Database::$supressOutput) { - echo "
  • About Us created
  • "; - } + Database::alteration_message("About Us created","created"); $contactus = new Page(); $contactus->Title = "Contact Us"; diff --git a/security/Member.php b/security/Member.php index d64f86083..27069a142 100644 --- a/security/Member.php +++ b/security/Member.php @@ -426,10 +426,7 @@ class Member extends DataObject { if(!DB::query("SELECT * FROM Member")->value() && isset($_REQUEST['username']) && isset($_REQUEST['password'])) { Security::findAnAdministrator($_REQUEST['username'], $_REQUEST['password']); - - if(!Database::$supressOutput) { - echo "
  • Added admin account
  • "; - } + Database::alteration_message("Added admin account","created"); } } }