Completed
Push — release-2.1 ( 6f6d35...dd7040 )
by Michael
11:13
created
Sources/DbPackages-postgresql.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -382,7 +382,7 @@
 block discarded – undo
382 382
  * @param array $parameters Not used?
383 383
  * @param string $if_exists What to do if the index exists. If 'update', the definition will be updated.
384 384
  * @param string $error
385
- * @return boolean Whether or not the operation was successful
385
+ * @return false|null Whether or not the operation was successful
386 386
  */
387 387
 function smf_db_add_index($table_name, $index_info, $parameters = array(), $if_exists = 'update', $error = 'fatal')
388 388
 {
Please login to merge, or discard this patch.
Braces   +110 added lines, -86 removed lines patch added patch discarded remove patch
@@ -13,8 +13,9 @@  discard block
 block discarded – undo
13 13
  * @version 2.1 Beta 4
14 14
  */
15 15
 
16
-if (!defined('SMF'))
16
+if (!defined('SMF')) {
17 17
 	die('No direct access...');
18
+}
18 19
 
19 20
 /**
20 21
  * Add the file functions to the $smcFunc array.
@@ -52,8 +53,9 @@  discard block
 block discarded – undo
52 53
 		'messages', 'moderators', 'package_servers', 'permission_profiles', 'permissions', 'personal_messages',
53 54
 		'pm_recipients', 'poll_choices', 'polls', 'scheduled_tasks', 'sessions', 'settings', 'smileys',
54 55
 		'themes', 'topics');
55
-	foreach ($reservedTables as $k => $table_name)
56
-		$reservedTables[$k] = strtolower($db_prefix . $table_name);
56
+	foreach ($reservedTables as $k => $table_name) {
57
+			$reservedTables[$k] = strtolower($db_prefix . $table_name);
58
+	}
57 59
 
58 60
 	// We in turn may need the extra stuff.
59 61
 	db_extend('extra');
@@ -102,8 +104,9 @@  discard block
 block discarded – undo
102 104
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
103 105
 
104 106
 	// First - no way do we touch SMF tables.
105
-	if (in_array(strtolower($table_name), $reservedTables))
106
-		return false;
107
+	if (in_array(strtolower($table_name), $reservedTables)) {
108
+			return false;
109
+	}
107 110
 
108 111
 	// Log that we'll want to remove this on uninstall.
109 112
 	$db_package_log[] = array('remove_table', $table_name);
@@ -113,10 +116,11 @@  discard block
 block discarded – undo
113 116
 	if (in_array($full_table_name, $tables))
114 117
 	{
115 118
 		// This is a sad day... drop the table? If not, return false (error) by default.
116
-		if ($if_exists == 'overwrite')
117
-			$smcFunc['db_drop_table']($table_name);
118
-		else
119
-			return $if_exists == 'ignore';
119
+		if ($if_exists == 'overwrite') {
120
+					$smcFunc['db_drop_table']($table_name);
121
+		} else {
122
+					return $if_exists == 'ignore';
123
+		}
120 124
 	}
121 125
 
122 126
 	// If we've got this far - good news - no table exists. We can build our own!
@@ -134,17 +138,18 @@  discard block
 block discarded – undo
134 138
 				)
135 139
 			);
136 140
 			$default = 'default nextval(\'' . $table_name . '_seq\')';
141
+		} elseif (isset($column['default']) && $column['default'] !== null) {
142
+					$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
143
+		} else {
144
+					$default = '';
137 145
 		}
138
-		elseif (isset($column['default']) && $column['default'] !== null)
139
-			$default = 'default \'' . $smcFunc['db_escape_string']($column['default']) . '\'';
140
-		else
141
-			$default = '';
142 146
 
143 147
 		// Sort out the size...
144 148
 		$column['size'] = isset($column['size']) && is_numeric($column['size']) ? $column['size'] : null;
145 149
 		list ($type, $size) = $smcFunc['db_calculate_type']($column['type'], $column['size']);
146
-		if ($size !== null)
147
-			$type = $type . '(' . $size . ')';
150
+		if ($size !== null) {
151
+					$type = $type . '(' . $size . ')';
152
+		}
148 153
 
149 154
 		// Now just put it together!
150 155
 		$table_query .= "\n\t\"" . $column['name'] . '" ' . $type . ' ' . (!empty($column['null']) ? '' : 'NOT NULL') . ' ' . $default . ',';
@@ -157,19 +162,21 @@  discard block
 block discarded – undo
157 162
 		$columns = implode(',', $index['columns']);
158 163
 
159 164
 		// Primary goes in the table...
160
-		if (isset($index['type']) && $index['type'] == 'primary')
161
-			$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
162
-		else
165
+		if (isset($index['type']) && $index['type'] == 'primary') {
166
+					$table_query .= "\n\t" . 'PRIMARY KEY (' . implode(',', $index['columns']) . '),';
167
+		} else
163 168
 		{
164
-			if (empty($index['name']))
165
-				$index['name'] = implode('_', $index['columns']);
169
+			if (empty($index['name'])) {
170
+							$index['name'] = implode('_', $index['columns']);
171
+			}
166 172
 			$index_queries[] = 'CREATE ' . (isset($index['type']) && $index['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $table_name . '_' . $index['name'] . ' ON ' . $table_name . ' (' . $columns . ')';
167 173
 		}
168 174
 	}
169 175
 
170 176
 	// No trailing commas!
171
-	if (substr($table_query, -1) == ',')
172
-		$table_query = substr($table_query, 0, -1);
177
+	if (substr($table_query, -1) == ',') {
178
+			$table_query = substr($table_query, 0, -1);
179
+	}
173 180
 
174 181
 	$table_query .= ')';
175 182
 
@@ -180,12 +187,13 @@  discard block
 block discarded – undo
180 187
 		)
181 188
 	);
182 189
 	// And the indexes...
183
-	foreach ($index_queries as $query)
184
-		$smcFunc['db_query']('', $query,
190
+	foreach ($index_queries as $query) {
191
+			$smcFunc['db_query']('', $query,
185 192
 		array(
186 193
 			'security_override' => true,
187 194
 		)
188 195
 	);
196
+	}
189 197
 
190 198
 	// Go, go power rangers!
191 199
 	$smcFunc['db_transaction']('commit');
@@ -213,8 +221,9 @@  discard block
 block discarded – undo
213 221
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
214 222
 
215 223
 	// God no - dropping one of these = bad.
216
-	if (in_array(strtolower($table_name), $reservedTables))
217
-		return false;
224
+	if (in_array(strtolower($table_name), $reservedTables)) {
225
+			return false;
226
+	}
218 227
 
219 228
 	// Does it exist?
220 229
 	if (in_array($full_table_name, $smcFunc['db_list_tables']()))
@@ -272,21 +281,24 @@  discard block
 block discarded – undo
272 281
 
273 282
 	// Does it exist - if so don't add it again!
274 283
 	$columns = $smcFunc['db_list_columns']($table_name, false);
275
-	foreach ($columns as $column)
276
-		if ($column == $column_info['name'])
284
+	foreach ($columns as $column) {
285
+			if ($column == $column_info['name'])
277 286
 		{
278 287
 			// If we're going to overwrite then use change column.
279 288
 			if ($if_exists == 'update')
280 289
 				return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
281
-			else
282
-				return false;
290
+	}
291
+			else {
292
+							return false;
293
+			}
283 294
 		}
284 295
 
285 296
 	// Get the specifics...
286 297
 	$column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null;
287 298
 	list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
288
-	if ($size !== null)
289
-		$type = $type . '(' . $size . ')';
299
+	if ($size !== null) {
300
+			$type = $type . '(' . $size . ')';
301
+	}
290 302
 
291 303
 	// Now add the thing!
292 304
 	$query = '
@@ -301,11 +313,12 @@  discard block
 block discarded – undo
301 313
 	// If there's more attributes they need to be done via a change on PostgreSQL.
302 314
 	unset($column_info['type'], $column_info['size']);
303 315
 
304
-	if (count($column_info) != 1)
305
-		return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
306
-	else
307
-		return true;
308
-}
316
+	if (count($column_info) != 1) {
317
+			return $smcFunc['db_change_column']($table_name, $column_info['name'], $column_info);
318
+	} else {
319
+			return true;
320
+	}
321
+	}
309 322
 
310 323
 /**
311 324
  * Removes a column.
@@ -324,8 +337,8 @@  discard block
 block discarded – undo
324 337
 
325 338
 	// Does it exist?
326 339
 	$columns = $smcFunc['db_list_columns']($table_name, true);
327
-	foreach ($columns as $column)
328
-		if ($column['name'] == $column_name)
340
+	foreach ($columns as $column) {
341
+			if ($column['name'] == $column_name)
329 342
 		{
330 343
 			// If there is an auto we need remove it!
331 344
 			if ($column['auto'])
@@ -335,6 +348,7 @@  discard block
 block discarded – undo
335 348
 						'security_override' => true,
336 349
 					)
337 350
 				);
351
+	}
338 352
 
339 353
 			$smcFunc['db_query']('', '
340 354
 				ALTER TABLE ' . $table_name . '
@@ -368,13 +382,15 @@  discard block
 block discarded – undo
368 382
 	// Check it does exist!
369 383
 	$columns = $smcFunc['db_list_columns']($table_name, true);
370 384
 	$old_info = null;
371
-	foreach ($columns as $column)
372
-		if ($column['name'] == $old_column)
385
+	foreach ($columns as $column) {
386
+			if ($column['name'] == $old_column)
373 387
 			$old_info = $column;
388
+	}
374 389
 
375 390
 	// Nothing?
376
-	if ($old_info == null)
377
-		return false;
391
+	if ($old_info == null) {
392
+			return false;
393
+	}
378 394
 
379 395
 	// Now we check each bit individually and ALTER as required.
380 396
 	if (isset($column_info['name']) && $column_info['name'] != $old_column)
@@ -431,8 +447,9 @@  discard block
 block discarded – undo
431 447
 	{
432 448
 		$column_info['size'] = isset($column_info['size']) && is_numeric($column_info['size']) ? $column_info['size'] : null;
433 449
 		list ($type, $size) = $smcFunc['db_calculate_type']($column_info['type'], $column_info['size']);
434
-		if ($size !== null)
435
-			$type = $type . '(' . $size . ')';
450
+		if ($size !== null) {
451
+					$type = $type . '(' . $size . ')';
452
+		}
436 453
 
437 454
 		// The alter is a pain.
438 455
 		$smcFunc['db_transaction']('begin');
@@ -526,21 +543,23 @@  discard block
 block discarded – undo
526 543
 	$table_name = str_replace('{db_prefix}', $db_prefix, $table_name);
527 544
 
528 545
 	// No columns = no index.
529
-	if (empty($index_info['columns']))
530
-		return false;
546
+	if (empty($index_info['columns'])) {
547
+			return false;
548
+	}
531 549
 	$columns = implode(',', $index_info['columns']);
532 550
 
533 551
 	// No name - make it up!
534 552
 	if (empty($index_info['name']))
535 553
 	{
536 554
 		// No need for primary.
537
-		if (isset($index_info['type']) && $index_info['type'] == 'primary')
538
-			$index_info['name'] = '';
539
-		else
540
-			$index_info['name'] = $table_name . implode('_', $index_info['columns']);
555
+		if (isset($index_info['type']) && $index_info['type'] == 'primary') {
556
+					$index_info['name'] = '';
557
+		} else {
558
+					$index_info['name'] = $table_name . implode('_', $index_info['columns']);
559
+		}
560
+	} else {
561
+			$index_info['name'] = $table_name . $index_info['name'];
541 562
 	}
542
-	else
543
-		$index_info['name'] = $table_name . $index_info['name'];
544 563
 
545 564
 	// Log that we are going to want to remove this!
546 565
 	$db_package_log[] = array('remove_index', $table_name, $index_info['name']);
@@ -553,10 +572,11 @@  discard block
 block discarded – undo
553 572
 		if ($index['name'] == $index_info['name'] || ($index['type'] == 'primary' && isset($index_info['type']) && $index_info['type'] == 'primary'))
554 573
 		{
555 574
 			// If we want to overwrite simply remove the current one then continue.
556
-			if ($if_exists != 'update' || $index['type'] == 'primary')
557
-				return false;
558
-			else
559
-				$smcFunc['db_remove_index']($table_name, $index_info['name']);
575
+			if ($if_exists != 'update' || $index['type'] == 'primary') {
576
+							return false;
577
+			} else {
578
+							$smcFunc['db_remove_index']($table_name, $index_info['name']);
579
+			}
560 580
 		}
561 581
 	}
562 582
 
@@ -570,8 +590,7 @@  discard block
 block discarded – undo
570 590
 				'security_override' => true,
571 591
 			)
572 592
 		);
573
-	}
574
-	else
593
+	} else
575 594
 	{
576 595
 		$smcFunc['db_query']('', '
577 596
 			CREATE ' . (isset($index_info['type']) && $index_info['type'] == 'unique' ? 'UNIQUE' : '') . ' INDEX ' . $index_info['name'] . ' ON ' . $table_name . ' (' . $columns . ')',
@@ -599,8 +618,9 @@  discard block
 block discarded – undo
599 618
 
600 619
 	// Better exist!
601 620
 	$indexes = $smcFunc['db_list_indexes']($table_name, true);
602
-	if ($index_name != 'primary')
603
-		$index_name = $table_name . '_' . $index_name;
621
+	if ($index_name != 'primary') {
622
+			$index_name = $table_name . '_' . $index_name;
623
+	}
604 624
 
605 625
 	foreach ($indexes as $index)
606 626
 	{
@@ -664,8 +684,7 @@  discard block
 block discarded – undo
664 684
 			'datetime' => 'timestamp without time zone',
665 685
 			'timestamp' => 'timestamp without time zone',
666 686
 		);
667
-	}
668
-	else
687
+	} else
669 688
 	{
670 689
 		$types = array(
671 690
 			'character varying' => 'varchar',
@@ -681,14 +700,16 @@  discard block
 block discarded – undo
681 700
 	// Got it? Change it!
682 701
 	if (isset($types[$type_name]))
683 702
 	{
684
-		if ($type_name == 'tinytext')
685
-			$type_size = 255;
703
+		if ($type_name == 'tinytext') {
704
+					$type_size = 255;
705
+		}
686 706
 		$type_name = $types[$type_name];
687 707
 	}
688 708
 
689 709
 	// Only char fields got size
690
-	if (strpos($type_name, 'char') === false)
691
-			$type_size = null;
710
+	if (strpos($type_name, 'char') === false) {
711
+				$type_size = null;
712
+	}
692 713
 
693 714
 
694 715
 	return array($type_name, $type_size);
@@ -742,8 +763,7 @@  discard block
 block discarded – undo
742 763
 		if (!$detail)
743 764
 		{
744 765
 			$columns[] = $row['column_name'];
745
-		}
746
-		else
766
+		} else
747 767
 		{
748 768
 			$auto = false;
749 769
 			// What is the default?
@@ -751,11 +771,11 @@  discard block
 block discarded – undo
751 771
 			{
752 772
 				$default = null;
753 773
 				$auto = true;
774
+			} elseif (trim($row['column_default']) != '') {
775
+							$default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::'));
776
+			} else {
777
+							$default = null;
754 778
 			}
755
-			elseif (trim($row['column_default']) != '')
756
-				$default = strpos($row['column_default'], '::') === false ? $row['column_default'] : substr($row['column_default'], 0, strpos($row['column_default'], '::'));
757
-			else
758
-				$default = null;
759 779
 
760 780
 			// Make the type generic.
761 781
 			list ($type, $size) = $smcFunc['db_calculate_type']($row['data_type'], $row['character_maximum_length'], true);
@@ -806,26 +826,30 @@  discard block
 block discarded – undo
806 826
 	while ($row = $smcFunc['db_fetch_assoc']($result))
807 827
 	{
808 828
 		// Try get the columns that make it up.
809
-		if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0)
810
-			continue;
829
+		if (preg_match('~\(([^\)]+?)\)~i', $row['inddef'], $matches) == 0) {
830
+					continue;
831
+		}
811 832
 
812 833
 		$columns = explode(',', $matches[1]);
813 834
 
814
-		if (empty($columns))
815
-			continue;
835
+		if (empty($columns)) {
836
+					continue;
837
+		}
816 838
 
817
-		foreach ($columns as $k => $v)
818
-			$columns[$k] = trim($v);
839
+		foreach ($columns as $k => $v) {
840
+					$columns[$k] = trim($v);
841
+		}
819 842
 
820 843
 		// Fix up the name to be consistent cross databases
821
-		if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1)
822
-			$row['name'] = 'PRIMARY';
823
-		else
824
-			$row['name'] = str_replace($table_name . '_', '', $row['name']);
844
+		if (substr($row['name'], -5) == '_pkey' && $row['is_primary'] == 1) {
845
+					$row['name'] = 'PRIMARY';
846
+		} else {
847
+					$row['name'] = str_replace($table_name . '_', '', $row['name']);
848
+		}
825 849
 
826
-		if (!$detail)
827
-			$indexes[] = $row['name'];
828
-		else
850
+		if (!$detail) {
851
+					$indexes[] = $row['name'];
852
+		} else
829 853
 		{
830 854
 			$indexes[$row['name']] = array(
831 855
 				'name' => $row['name'],
Please login to merge, or discard this patch.
custom_avatar/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
attachments/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/fugue/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/aaron/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/akyhne/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.
Smileys/default/index.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,9 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Try to handle it with the upper level index.php. (it should know what to do.)
4
-if (file_exists(dirname(dirname(__FILE__)) . '/index.php'))
4
+if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) {
5 5
 	include (dirname(dirname(__FILE__)) . '/index.php');
6
-else
6
+} else {
7 7
 	exit;
8
+}
8 9
 
9 10
 ?>
10 11
\ No newline at end of file
Please login to merge, or discard this patch.
Themes/index.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,8 @@
 block discarded – undo
12 12
 	header('Location: ' . $boardurl);
13 13
 }
14 14
 // Can't find it... just forget it.
15
-else
15
+else {
16 16
 	exit;
17
+}
17 18
 
18 19
 ?>
19 20
\ No newline at end of file
Please login to merge, or discard this patch.