From: Aryeh Gregor Date: Fri, 27 Aug 2010 16:42:18 +0000 (+0000) Subject: Style fixes for r71609 and follow-ups X-Git-Tag: 1.31.0-rc.0~35299 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=7e8bef4ecb5d6065707f378387f5e58e11b8e6e1;p=lhc%2Fweb%2Fwiklou.git Style fixes for r71609 and follow-ups 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. --- diff --git a/includes/db/Database.php b/includes/db/Database.php index 0fd4ea374e..46971d0757 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -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 {