Style fixes for r71609 and follow-ups
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 27 Aug 2010 16:42:18 +0000 (16:42 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 27 Aug 2010 16:42:18 +0000 (16:42 +0000)
Avoid one-letter variable names, be descriptive.  Name an unused value
variable in foreach "$unused".  Add spaces where needed.  Wrap comments
at 79 columns, not some arbitrarily-selected number.  Remove blank line.

includes/db/Database.php

index 0fd4ea3..46971d0 100644 (file)
@@ -1039,32 +1039,30 @@ abstract class DatabaseBase implements DatabaseType {
        }
 
        /**
-        * INSERT ... ON DUPE UPDATE wrapper, inserts an array into a table, optionally updating if
-        * duplicate primary key found
+        * INSERT ... ON DUPLICATE KEY UPDATE wrapper, inserts an array into a
+        * table, optionally updating if duplicate primary key found
         *
-        * $a may be a single associative array, or an array of these with numeric keys, for
-        * multi-row insert.
+        * $rows may be a single associative array, or an array of these with
+        * numeric keys, for multi-row insert.
         *
-        * Usually aborts on failure
-        * If errors are explicitly ignored, returns success
+        * Usually aborts on failure.  If errors are explicitly ignored, returns success.
         *
         * @param $table   String: table name (prefix auto-added)
-        * @param $a       Array: Array of rows to insert
+        * @param $rows    Array: Array of rows to insert
         * @param $fname   String: Calling function name (use __METHOD__) for logs/profiling
         * @param $onDupeUpdate   Array: Associative array of fields to update on duplicate
         *
         * @return bool
         */
-       function insertOrUpdate( $table, $a, $fname = 'DatabaseBase::insertOrUpdate', $onDupeUpdate = array() ) {
-               
-               if ( isset( $a[0] ) && is_array( $a[0] ) ) {
-                       $keys = array_keys( $a[0] );
+       function insertOrUpdate( $table, $rows, $fname = 'DatabaseBase::insertOrUpdate', $onDupeUpdate = array() ) {
+               if ( isset( $rows[0] ) && is_array( $rows[0] ) ) {
+                       $keys = array_keys( $rows[0] );
                } else {
-                       $keys = array_keys( $a );
+                       $keys = array_keys( $rows );
                }
 
-               //Get what is only to be set if inserted
-               $where = array_diff( $a, $onDupeUpdate );
+               // Get what is only to be set if inserted
+               $where = array_diff( $rows, $onDupeUpdate );
 
                $res = $this->select(
                        $table,
@@ -1074,12 +1072,13 @@ abstract class DatabaseBase implements DatabaseType {
                );
 
                if ( $res ) {
-                       // Where there is a different value to set if this is being "updated", use the $onDupeUpdate value for that to
-                       // replace the original option (if it was an insert), and replace the column name with the value read from
-                       // the existing row
-                       foreach( $where as $k => $v ) {
-                               if ( isset( $onDupeUpdate[$k] ) ) {
-                                       $options[$k] = str_replace( $k, $res[0]->{$k}, $onDupeUpdate[$k] );
+                       // Where there is a different value to set if this is being
+                       // "updated", use the $onDupeUpdate value for that to replace the
+                       // original option (if it was an insert), and replace the column
+                       // name with the value read from the existing row
+                       foreach ( $where as $key => $unused ) {
+                               if ( isset( $onDupeUpdate[$key] ) ) {
+                                       $options[$key] = str_replace( $key, $res[0]->{$key}, $onDupeUpdate[$key] );
                                }
                        }
                } else {