From 9c7d45bd91afbb59dbde76272c45300a2873bc3f Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 7 Sep 2012 07:47:04 -0400
Subject: [PATCH] Style fixes; corrected comments.

---
 .../VuFind/Controller/Plugin/DbUpgrade.php    | 52 +++++++++++++------
 .../VuFind/Controller/UpgradeController.php   | 21 ++++----
 2 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/module/VuFind/src/VuFind/Controller/Plugin/DbUpgrade.php b/module/VuFind/src/VuFind/Controller/Plugin/DbUpgrade.php
index d89f70c27fa..cc3b11a6dee 100644
--- a/module/VuFind/src/VuFind/Controller/Plugin/DbUpgrade.php
+++ b/module/VuFind/src/VuFind/Controller/Plugin/DbUpgrade.php
@@ -102,13 +102,15 @@ class DbUpgrade extends AbstractPlugin
     /**
      * Execute a query.
      *
-     * @param string $sql SQL to run
+     * @param string $sql    SQL to run
+     * @param bool   $logsql Should we return the SQL as a string rather than
+     * execute it?
      *
-     * @return void
+     * @return string        SQL if $logsql is true, empty string otherwise
      */
     public function query($sql, $logsql)
-    {        
-        if($logsql) {
+    {
+        if ($logsql) {
             return $sql . ";\n";
         } else {
             $this->getAdapter()->query($sql, DbAdapter::QUERY_MODE_EXECUTE);
@@ -189,9 +191,11 @@ class DbUpgrade extends AbstractPlugin
      * Create missing tables based on the output of getMissingTables().
      *
      * @param array $tables Output of getMissingTables()
+     * @param bool  $logsql Should we return the SQL as a string rather than
+     * execute it?
      *
      * @throws \Exception
-     * @return void
+     * @return string       SQL if $logsql is true, empty string otherwise
      */
     public function createMissingTables($tables, $logsql = false)
     {
@@ -206,18 +210,20 @@ class DbUpgrade extends AbstractPlugin
      * Get a list of missing columns in the database tables (associative array,
      * key = table name, value = array of missing column definitions).
      *
+     * @param array $missingTables List of missing tables
+     *
      * @throws \Exception
      * @return array
      */
-    public function getMissingColumns($missing_tables = array())
+    public function getMissingColumns($missingTables = array())
     {
         $missing = array();
         foreach ($this->dbCommands as $table => $sql) {
             // Skip missing tables if we're logging
-            if(in_array($table, $missing_tables)) {
+            if (in_array($table, $missingTables)) {
                 continue;
             }
-            
+
             // Parse column names out of the CREATE TABLE SQL, which will always be
             // the first entry in the array; we assume the standard mysqldump
             // formatting is used here.
@@ -289,18 +295,22 @@ class DbUpgrade extends AbstractPlugin
      * Get a list of changed columns in the database tables (associative array,
      * key = table name, value = array of column name => new data type).
      *
+     * @param array $missingTables  List of missing tables
+     * @param array $missingColumns List of missing columns
+     *
      * @throws \Exception
      * @return array
      */
-    public function getModifiedColumns($missingTables = array(), $missingColumns = array())
-    {
+    public function getModifiedColumns($missingTables = array(),
+        $missingColumns = array()
+    ) {
         $missing = array();
         foreach ($this->dbCommands as $table => $sql) {
             // Skip missing tables if we're logging
-            if(in_array($table, $missingTables)) {
+            if (in_array($table, $missingTables)) {
                 continue;
             }
-            
+
             // Parse column names out of the CREATE TABLE SQL, which will always be
             // the first entry in the array; we assume the standard mysqldump
             // formatting is used here.
@@ -325,7 +335,7 @@ class DbUpgrade extends AbstractPlugin
             $actualColumns = $this->getTableColumns($table);
             foreach ($expectedColumns as $i => $column) {
                 // Skip column if we're logging and it's missing
-                if(in_array($column, $missingColumns)) {
+                if (in_array($column, $missingColumns)) {
                     continue;
                 }
                 $currentColumn = $actualColumns[$column];
@@ -344,16 +354,20 @@ class DbUpgrade extends AbstractPlugin
      * Create missing columns based on the output of getMissingColumns().
      *
      * @param array $columns Output of getMissingColumns()
+     * @param bool  $logsql  Should we return the SQL as a string rather than
+     * execute it?
      *
      * @throws \Exception
-     * @return void
+     * @return string        SQL if $logsql is true, empty string otherwise
      */
     public function createMissingColumns($columns, $logsql = false)
     {
         $sqlcommands = '';
         foreach ($columns as $table => $sql) {
             foreach ($sql as $column) {
-                $sqlcommands .= $this->query("ALTER TABLE `{$table}` ADD COLUMN {$column}", $logsql);
+                $sqlcommands .= $this->query(
+                    "ALTER TABLE `{$table}` ADD COLUMN {$column}", $logsql
+                );
             }
         }
         return $sqlcommands;
@@ -363,16 +377,20 @@ class DbUpgrade extends AbstractPlugin
      * Modify columns based on the output of getModifiedColumns().
      *
      * @param array $columns Output of getModifiedColumns()
+     * @param bool  $logsql  Should we return the SQL as a string rather than
+     * execute it?
      *
      * @throws \Exception
-     * @return void
+     * @return string        SQL if $logsql is true, empty string otherwise
      */
     public function updateModifiedColumns($columns, $logsql = false)
     {
         $sqlcommands = '';
         foreach ($columns as $table => $sql) {
             foreach ($sql as $column) {
-                $sqlcommands .= $this->query("ALTER TABLE `{$table}` MODIFY COLUMN {$column}", $logsql);
+                $sqlcommands .= $this->query(
+                    "ALTER TABLE `{$table}` MODIFY COLUMN {$column}", $logsql
+                );
             }
         }
         return $sqlcommands;
diff --git a/module/VuFind/src/VuFind/Controller/UpgradeController.php b/module/VuFind/src/VuFind/Controller/UpgradeController.php
index b96ca158fd6..426479ad737 100644
--- a/module/VuFind/src/VuFind/Controller/UpgradeController.php
+++ b/module/VuFind/src/VuFind/Controller/UpgradeController.php
@@ -197,7 +197,7 @@ class UpgradeController extends AbstractBase
             // the missing tables will cause fatal errors during the column test.
             $missingTables = $this->dbUpgrade()->getMissingTables();
             if (!empty($missingTables)) {
-                if(!$this->logsql) {
+                if (!$this->logsql) {
                     if (!isset($this->session->dbRootUser)
                         || !isset($this->session->dbRootPass)
                     ) {
@@ -210,7 +210,8 @@ class UpgradeController extends AbstractBase
                     $this->dbUpgrade()->setAdapter($db)
                         ->createMissingTables($missingTables);
                 } else {
-                    $sql .= $this->dbUpgrade()->createMissingTables($missingTables, true);
+                    $sql .= $this->dbUpgrade()
+                        ->createMissingTables($missingTables, true);
                 }
             }
 
@@ -218,7 +219,7 @@ class UpgradeController extends AbstractBase
             $mT = $this->logsql ? $missingTables : array();
             $missingCols = $this->dbUpgrade()->getMissingColumns($mT);
             if (!empty($missingCols)) {
-                if(!$this->logsql) {
+                if (!$this->logsql) {
                     if (!isset($this->session->dbRootUser)
                         || !isset($this->session->dbRootPass)
                     ) {
@@ -234,7 +235,8 @@ class UpgradeController extends AbstractBase
                     $this->dbUpgrade()->setAdapter($db)
                         ->createMissingColumns($missingCols);
                 } else {
-                    $sql .= $this->dbUpgrade()->createMissingColumns($missingCols, true);
+                    $sql .= $this->dbUpgrade()
+                        ->createMissingColumns($missingCols, true);
                 }
             }
             
@@ -242,7 +244,7 @@ class UpgradeController extends AbstractBase
             $mC = $this->logsql ? $missingCols : array();
             $modifiedCols = $this->dbUpgrade()->getModifiedColumns($mT, $mC);
             if (!empty($modifiedCols)) {
-                if(!$this->logsql) {
+                if (!$this->logsql) {
                     if (!isset($this->session->dbRootUser)
                         || !isset($this->session->dbRootPass)
                     ) {
@@ -258,7 +260,8 @@ class UpgradeController extends AbstractBase
                     $this->dbUpgrade()->setAdapter($db)
                         ->updateModifiedColumns($modifiedCols);
                 } else {
-                    $sql .= $this->dbUpgrade()->updateModifiedColumns($modifiedCols, true);
+                    $sql .= $this->dbUpgrade()
+                        ->updateModifiedColumns($modifiedCols, true);
                 }
             }
 
@@ -280,7 +283,7 @@ class UpgradeController extends AbstractBase
         }
 
         $this->cookie->databaseOkay = true;
-        if($this->logsql) {
+        if ($this->logsql) {
             $this->session->sql = $sql;
             return $this->forwardTo('Upgrade', 'ShowSql');
         }
@@ -295,7 +298,7 @@ class UpgradeController extends AbstractBase
     public function showsqlAction()
     {
         $continue = $this->params()->fromPost('continue', 'nope');
-        if($continue == 'Next') {
+        if ($continue == 'Next') {
             unset($this->session->sql);
             return $this->forwardTo('Upgrade', 'Home');
         }
@@ -311,7 +314,7 @@ class UpgradeController extends AbstractBase
     public function getdbcredentialsAction()
     {
         $print = $this->params()->fromPost('printsql', 'nope');
-        if($print == 'Skip') {
+        if ($print == 'Skip') {
             $this->logsql = true;
             $this->session->dbRootUser = '$$$$$$$';
             $this->session->dbRootPass = '$$$$$$$';
-- 
GitLab