Completed
Push — master ( 69c507...0da94d )
by Martijn van
02:23
created

ClearTestDatabasesCommand::deleteAllTempDbs()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.2
cc 4
eloc 6
nc 6
nop 0
1
<?php
2
3
4
class ClearTestDatabasesCommand extends SilverstripeCommand
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
5
{
6
    /**
7
     * The console command name.
8
     *
9
     * @var string
10
     */
11
    protected $name = 'clear:tmpdbs';
12
13
    /**
14
     * The console command description.
15
     *
16
     * @var string
17
     */
18
    protected $description = 'Clear the test databases';
19
20
    public function fire()
21
    {
22
        SapphireTest::delete_all_temp_dbs();
23
24
        $this->deleteAllTempDbs();
25
26
        $this->line(" ");
27
        $this->info("Test databases cleared");
28
    }
29
30
    protected function deleteAllTempDbs() {
31
        $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
32
        foreach(DB::get_schema()->databaseList() as $dbName) {
33
            if(preg_match(sprintf('/^%stmpdb[0-9]+$/', $prefix), $dbName)) {
34
                DB::get_schema()->dropDatabase($dbName);
35
                $this->info("Dropped database $dbName");
36
            }
37
        }
38
    }
39
}
40