Completed
Pull Request — master (#21)
by Daniel
08:50
created
code/SQLite3Database.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -183,6 +183,7 @@  discard block
 block discarded – undo
183 183
      * Gets pragma value.
184 184
      * 
185 185
      * @param string pragma name
186
+     * @param string $pragma
186 187
      * @return string the pragma value
187 188
      */
188 189
     public function getPragma($pragma)
@@ -238,7 +239,7 @@  discard block
 block discarded – undo
238 239
      * for now we use the MySQL implementation with the MATCH()AGAINST() uglily replaced with LIKE
239 240
      * 
240 241
      * @param string $keywords Keywords as a space separated string
241
-     * @return object DataObjectSet of result pages
242
+     * @return PaginatedList DataObjectSet of result pages
242 243
      */
243 244
     public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC",
244 245
         $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 
97 97
         // Ensure database name is set
98 98
         if (empty($parameters['database'])) {
99
-            $parameters['database'] = 'database' . self::database_extension();
99
+            $parameters['database'] = 'database'.self::database_extension();
100 100
         }
101 101
         $dbName = $parameters['database'];
102 102
         if (!self::is_valid_database_name($dbName)) {
@@ -112,11 +112,11 @@  discard block
 block discarded – undo
112 112
         } else {
113 113
             // Ensure path is given
114 114
             if (empty($parameters['path'])) {
115
-                $parameters['path'] = ASSETS_PATH . '/.sqlitedb';
115
+                $parameters['path'] = ASSETS_PATH.'/.sqlitedb';
116 116
             }
117 117
 
118 118
             //assumes that the path to dbname will always be provided:
119
-            $file = $parameters['path'] . '/' . $dbName;
119
+            $file = $parameters['path'].'/'.$dbName;
120 120
             if (!file_exists($parameters['path'])) {
121 121
                 SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
122 122
                 SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']);
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
             $extraFilters['File'] .= " AND ShowInSearch <> 0";
268 268
         }
269 269
 
270
-        $limit = $start . ", " . (int) $pageLength;
270
+        $limit = $start.", ".(int) $pageLength;
271 271
 
272 272
         $notMatch = $invertedMatch ? "NOT " : "";
273 273
         if ($keywords) {
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
         $baseClasses = array('SiteTree' => '', 'File' => '');
292 292
         $queries = array();
293 293
         foreach ($classesToSearch as $class) {
294
-            $queries[$class] = DataList::create($class)->where($notMatch . $match[$class] . $extraFilters[$class], "")->dataQuery()->query();
294
+            $queries[$class] = DataList::create($class)->where($notMatch.$match[$class].$extraFilters[$class], "")->dataQuery()->query();
295 295
             $fromArr = $queries[$class]->getFrom();
296 296
             $baseClasses[$class] = reset($fromArr);
297 297
         }
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
             $totalCount += $query->unlimitedRowCount();
354 354
         }
355 355
 
356
-        $fullQuery = implode(" UNION ", $querySQLs) . " ORDER BY $sortBy LIMIT $limit";
356
+        $fullQuery = implode(" UNION ", $querySQLs)." ORDER BY $sortBy LIMIT $limit";
357 357
         // Get records
358 358
         $records = $this->preparedQuery($fullQuery, $queryParameters);
359 359
 
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
                 $comp = 'LIKE';
441 441
             }
442 442
             if ($negate) {
443
-                $comp = 'NOT ' . $comp;
443
+                $comp = 'NOT '.$comp;
444 444
             }
445 445
         }
446 446
 
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
         preg_match_all('/%(.)/', $format, $matches);
457 457
         foreach ($matches[1] as $match) {
458 458
             if (array_search($match, array('Y', 'm', 'd', 'H', 'i', 's', 'U')) === false) {
459
-                user_error('formattedDatetimeClause(): unsupported format character %' . $match, E_USER_WARNING);
459
+                user_error('formattedDatetimeClause(): unsupported format character %'.$match, E_USER_WARNING);
460 460
             }
461 461
         }
462 462
 
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
             $date = "'$date'";
482 482
         }
483 483
 
484
-        $modifier = empty($modifiers) ? '' : ", '" . implode("', '", $modifiers) . "'";
484
+        $modifier = empty($modifiers) ? '' : ", '".implode("', '", $modifiers)."'";
485 485
         return "strftime('$format', $date$modifier)";
486 486
     }
487 487
 
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
             $date = "'$date'";
499 499
         }
500 500
 
501
-        $modifier = empty($modifiers) ? '' : ", '" . implode("', '", $modifiers) . "'";
501
+        $modifier = empty($modifiers) ? '' : ", '".implode("', '", $modifiers)."'";
502 502
         return "datetime($date$modifier, '$interval')";
503 503
     }
504 504
 
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
             $date2 = "'$date2'";
527 527
         }
528 528
 
529
-        $modifier1 = empty($modifiers1) ? '' : ", '" . implode("', '", $modifiers1) . "'";
530
-        $modifier2 = empty($modifiers2) ? '' : ", '" . implode("', '", $modifiers2) . "'";
529
+        $modifier1 = empty($modifiers1) ? '' : ", '".implode("', '", $modifiers1)."'";
530
+        $modifier2 = empty($modifiers2) ? '' : ", '".implode("', '", $modifiers2)."'";
531 531
 
532 532
         return "strftime('%s', $date1$modifier1) - strftime('%s', $date2$modifier2)";
533 533
     }
Please login to merge, or discard this patch.
_register_database.php 2 patches
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -1,45 +1,45 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 $sqliteDatabaseAdapterRegistryFields = array(
4
-	'path' => array(
5
-		'title' => 'Directory path<br /><small>Absolute path to directory, writeable by the webserver user.<br />'
6
-			. 'Recommended to be outside of your webroot</small>',
7
-		'default' => dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . '.sqlitedb'
8
-	),
9
-	'database' => array(
10
-		'title' => 'Database filename (extension .sqlite)',
11
-		'default' => 'database.sqlite'
12
-	)
4
+    'path' => array(
5
+        'title' => 'Directory path<br /><small>Absolute path to directory, writeable by the webserver user.<br />'
6
+            . 'Recommended to be outside of your webroot</small>',
7
+        'default' => dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . '.sqlitedb'
8
+    ),
9
+    'database' => array(
10
+        'title' => 'Database filename (extension .sqlite)',
11
+        'default' => 'database.sqlite'
12
+    )
13 13
 );
14 14
 
15 15
 // Basic SQLLite3 Database
16 16
 DatabaseAdapterRegistry::register(
17
-	array(
18
-		'class' => 'SQLite3Database',
19
-		'title' => 'SQLite 3.3+ (using SQLite3)',
20
-		'helperPath' => dirname(__FILE__).'/code/SQLiteDatabaseConfigurationHelper.php',
21
-		'supported' => class_exists('SQLite3'),
22
-		'missingExtensionText' => 'The <a href="http://php.net/manual/en/book.sqlite3.php">SQLite3</a> 
17
+    array(
18
+        'class' => 'SQLite3Database',
19
+        'title' => 'SQLite 3.3+ (using SQLite3)',
20
+        'helperPath' => dirname(__FILE__).'/code/SQLiteDatabaseConfigurationHelper.php',
21
+        'supported' => class_exists('SQLite3'),
22
+        'missingExtensionText' => 'The <a href="http://php.net/manual/en/book.sqlite3.php">SQLite3</a> 
23 23
 			PHP Extension is not available. Please install or enable it of them and refresh this page.',
24
-		'fields' => array_merge($sqliteDatabaseAdapterRegistryFields, array('key' => array(
25
-			'title' => 'Encryption key<br><small>This function is experimental and requires configuration of an '
26
-			. 'encryption module</small>',
27
-			'default' => ''
28
-		)))
29
-	)
24
+        'fields' => array_merge($sqliteDatabaseAdapterRegistryFields, array('key' => array(
25
+            'title' => 'Encryption key<br><small>This function is experimental and requires configuration of an '
26
+            . 'encryption module</small>',
27
+            'default' => ''
28
+        )))
29
+    )
30 30
 );
31 31
 
32 32
 // PDO database
33 33
 DatabaseAdapterRegistry::register(
34
-	array(
35
-		'class' => 'SQLite3PDODatabase',
36
-		'title' => 'SQLite 3.3+ (using PDO)',
37
-		'helperPath' => dirname(__FILE__).'/code/SQLiteDatabaseConfigurationHelper.php',
38
-		'supported' => (class_exists('PDO') && in_array('sqlite', PDO::getAvailableDrivers())),
39
-		'missingExtensionText' => 
40
-			'Either the <a href="http://php.net/manual/en/book.pdo.php">PDO Extension</a> or the
34
+    array(
35
+        'class' => 'SQLite3PDODatabase',
36
+        'title' => 'SQLite 3.3+ (using PDO)',
37
+        'helperPath' => dirname(__FILE__).'/code/SQLiteDatabaseConfigurationHelper.php',
38
+        'supported' => (class_exists('PDO') && in_array('sqlite', PDO::getAvailableDrivers())),
39
+        'missingExtensionText' => 
40
+            'Either the <a href="http://php.net/manual/en/book.pdo.php">PDO Extension</a> or the
41 41
 			<a href="http://php.net/manual/en/book.sqlite3.php">SQLite3 PDO Driver</a>
42 42
 			are unavailable. Please install or enable these and refresh this page.',
43
-		'fields' => $sqliteDatabaseAdapterRegistryFields
44
-	)
43
+        'fields' => $sqliteDatabaseAdapterRegistryFields
44
+    )
45 45
 );
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 	'path' => array(
5 5
 		'title' => 'Directory path<br /><small>Absolute path to directory, writeable by the webserver user.<br />'
6 6
 			. 'Recommended to be outside of your webroot</small>',
7
-		'default' => dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . '.sqlitedb'
7
+		'default' => dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'.sqlitedb'
8 8
 	),
9 9
 	'database' => array(
10 10
 		'title' => 'Database filename (extension .sqlite)',
Please login to merge, or discard this patch.
code/SQLite3Query.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     public function seek($row)
44 44
     {
45 45
         $this->handle->reset();
46
-        $i=0;
46
+        $i = 0;
47 47
         while ($i < $row && $row = @$this->handle->fetchArray()) {
48 48
             $i++;
49 49
         }
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function numRecords()
57 57
     {
58
-        $c=0;
58
+        $c = 0;
59 59
         while ($this->handle->fetchArray()) {
60 60
             $c++;
61 61
         }
Please login to merge, or discard this patch.
code/SQLiteDatabaseConfigurationHelper.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
                 self::create_db_dir($databaseConfig['path']);
27 27
                 self::secure_db_dir($databaseConfig['path']);
28 28
             }
29
-            $file = $databaseConfig['path'] . '/' . $databaseConfig['database'];
29
+            $file = $databaseConfig['path'].'/'.$databaseConfig['database'];
30 30
             $conn = null;
31 31
         
32 32
             switch ($databaseConfig['type']) {
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      */
213 213
     public static function secure_db_dir($path)
214 214
     {
215
-        return (is_writeable($path)) ? file_put_contents($path . '/.htaccess', 'deny from all') : false;
215
+        return (is_writeable($path)) ? file_put_contents($path.'/.htaccess', 'deny from all') : false;
216 216
     }
217 217
     
218 218
     public function requireDatabaseAlterPermissions($databaseConfig)
Please login to merge, or discard this patch.
code/SQLite3SchemaManager.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
          
45 45
         // If using file based database ensure any existing file is removed
46 46
         $parameters = $this->database->getParameters();
47
-        $fullpath = $parameters['path'] . '/' . $name;
47
+        $fullpath = $parameters['path'].'/'.$name;
48 48
         if (is_writable($fullpath)) {
49 49
             unlink($fullpath);
50 50
         }
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
     public function alterField($tableName, $fieldName, $fieldSpec)
243 243
     {
244 244
         $oldFieldList = $this->fieldList($tableName);
245
-        $fieldNameList = '"' . implode('","', array_keys($oldFieldList)) . '"';
245
+        $fieldNameList = '"'.implode('","', array_keys($oldFieldList)).'"';
246 246
 
247 247
         if (!empty($_REQUEST['avoidConflict']) && Director::isDev()) {
248 248
             $fieldSpec = preg_replace('/\snot null\s/i', ' NOT NULL ON CONFLICT REPLACE ', $fieldSpec);
@@ -256,12 +256,12 @@  discard block
 block discarded – undo
256 256
         // Update field spec
257 257
         $newColsSpec = array();
258 258
         foreach ($oldFieldList as $name => $oldSpec) {
259
-            $newColsSpec[] = "\"$name\" " . ($name == $fieldName ? $fieldSpec : $oldSpec);
259
+            $newColsSpec[] = "\"$name\" ".($name == $fieldName ? $fieldSpec : $oldSpec);
260 260
         }
261 261
 
262 262
         $queries = array(
263 263
             "BEGIN TRANSACTION",
264
-            "CREATE TABLE \"{$tableName}_alterfield_{$fieldName}\"(" . implode(',', $newColsSpec) . ")",
264
+            "CREATE TABLE \"{$tableName}_alterfield_{$fieldName}\"(".implode(',', $newColsSpec).")",
265 265
             "INSERT INTO \"{$tableName}_alterfield_{$fieldName}\" SELECT {$fieldNameList} FROM \"$tableName\"",
266 266
             "DROP TABLE \"$tableName\"",
267 267
             "ALTER TABLE \"{$tableName}_alterfield_{$fieldName}\" RENAME TO \"$tableName\"",
@@ -295,15 +295,15 @@  discard block
 block discarded – undo
295 295
         $oldCols = array();
296 296
         $newColsSpec = array();
297 297
         foreach ($oldFieldList as $name => $spec) {
298
-            $oldCols[] = "\"$name\"" . (($name == $oldName) ? " AS $newName" : '');
299
-            $newColsSpec[] = "\"" . (($name == $oldName) ? $newName : $name) . "\" $spec";
298
+            $oldCols[] = "\"$name\"".(($name == $oldName) ? " AS $newName" : '');
299
+            $newColsSpec[] = "\"".(($name == $oldName) ? $newName : $name)."\" $spec";
300 300
         }
301 301
 
302 302
         // SQLite doesn't support direct renames through ALTER TABLE
303 303
         $queries = array(
304 304
             "BEGIN TRANSACTION",
305
-            "CREATE TABLE \"{$tableName}_renamefield_{$oldName}\" (" . implode(',', $newColsSpec) . ")",
306
-            "INSERT INTO \"{$tableName}_renamefield_{$oldName}\" SELECT " . implode(',', $oldCols) . " FROM \"$tableName\"",
305
+            "CREATE TABLE \"{$tableName}_renamefield_{$oldName}\" (".implode(',', $newColsSpec).")",
306
+            "INSERT INTO \"{$tableName}_renamefield_{$oldName}\" SELECT ".implode(',', $oldCols)." FROM \"$tableName\"",
307 307
             "DROP TABLE \"$tableName\"",
308 308
             "ALTER TABLE \"{$tableName}_renamefield_{$oldName}\" RENAME TO \"$tableName\"",
309 309
             "COMMIT"
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
      */
456 456
     public function boolean($values)
457 457
     {
458
-        $default = empty($values['default']) ? 0 : (int)$values['default'];
458
+        $default = empty($values['default']) ? 0 : (int) $values['default'];
459 459
         return "BOOL NOT NULL DEFAULT $default";
460 460
     }
461 461
 
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
      */
500 500
     public function enum($values)
501 501
     {
502
-        $tablefield = $values['table'] . '.' . $values['name'];
502
+        $tablefield = $values['table'].'.'.$values['name'];
503 503
         $enumValues = implode(',', $values['enums']);
504 504
         
505 505
         // Ensure the cache table exists
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
      */
570 570
     public function int($values, $asDbValue = false)
571 571
     {
572
-        return "INTEGER({$values['precision']}) " . strtoupper($values['null']) . " DEFAULT " . (int)$values['default'];
572
+        return "INTEGER({$values['precision']}) ".strtoupper($values['null'])." DEFAULT ".(int) $values['default'];
573 573
     }
574 574
 
575 575
     /**
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 
645 645
     public function hasTable($tableName)
646 646
     {
647
-        return (bool)$this->preparedQuery(
647
+        return (bool) $this->preparedQuery(
648 648
             'SELECT name FROM sqlite_master WHERE type = ? AND name = ?',
649 649
             array('table', $tableName)
650 650
         )->first();
Please login to merge, or discard this patch.
code/SQLite3QueryBuilder.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
             $rowParts[] = implode(', ', $parts);
50 50
         }
51 51
         $columnSQL = implode(', ', $columns);
52
-        $sql = "INSERT INTO {$into}{$nl}($columnSQL){$nl}SELECT " . implode("{$nl}UNION ALL SELECT ", $rowParts);
52
+        $sql = "INSERT INTO {$into}{$nl}($columnSQL){$nl}SELECT ".implode("{$nl}UNION ALL SELECT ", $rowParts);
53 53
         
54 54
         return $sql;
55 55
     }
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
         }
73 73
 
74 74
         // For literal values return this as the limit SQL
75
-        if (! is_array($limit)) {
75
+        if (!is_array($limit)) {
76 76
             return "{$nl}LIMIT $limit";
77 77
         }
78 78
 
79 79
         // Assert that the array version provides the 'limit' key
80
-        if (! array_key_exists('limit', $limit) || ($limit['limit'] !== null && ! is_numeric($limit['limit']))) {
80
+        if (!array_key_exists('limit', $limit) || ($limit['limit'] !== null && !is_numeric($limit['limit']))) {
81 81
             throw new InvalidArgumentException(
82
-                'SQLite3QueryBuilder::buildLimitSQL(): Wrong format for $limit: '. var_export($limit, true)
82
+                'SQLite3QueryBuilder::buildLimitSQL(): Wrong format for $limit: '.var_export($limit, true)
83 83
             );
84 84
         }
85 85
 
Please login to merge, or discard this patch.
_configure_database.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -4,11 +4,11 @@
 block discarded – undo
4 4
 global $databaseConfig;
5 5
 if(strpos($databaseConfig['type'], 'SQLite') === 0) {
6 6
 
7
-	if(defined('SS_SQLITE_DATABASE_PATH')) {
8
-		$databaseConfig['path'] = SS_SQLITE_DATABASE_PATH;
9
-	}
7
+    if(defined('SS_SQLITE_DATABASE_PATH')) {
8
+        $databaseConfig['path'] = SS_SQLITE_DATABASE_PATH;
9
+    }
10 10
 
11
-	if(defined('SS_SQLITE_DATABASE_KEY')) {
12
-		$databaseConfig['key'] = SS_SQLITE_DATABASE_KEY;
13
-	}
11
+    if(defined('SS_SQLITE_DATABASE_KEY')) {
12
+        $databaseConfig['key'] = SS_SQLITE_DATABASE_KEY;
13
+    }
14 14
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,13 +2,13 @@
 block discarded – undo
2 2
 
3 3
 // Script called from ConfigureFromEnv.php
4 4
 global $databaseConfig;
5
-if(strpos($databaseConfig['type'], 'SQLite') === 0) {
5
+if (strpos($databaseConfig['type'], 'SQLite') === 0) {
6 6
 
7
-	if(defined('SS_SQLITE_DATABASE_PATH')) {
7
+	if (defined('SS_SQLITE_DATABASE_PATH')) {
8 8
 		$databaseConfig['path'] = SS_SQLITE_DATABASE_PATH;
9 9
 	}
10 10
 
11
-	if(defined('SS_SQLITE_DATABASE_KEY')) {
11
+	if (defined('SS_SQLITE_DATABASE_KEY')) {
12 12
 		$databaseConfig['key'] = SS_SQLITE_DATABASE_KEY;
13 13
 	}
14 14
 }
Please login to merge, or discard this patch.