DropOldTable::run()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.8666
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
/**
4
 * Nextcloud - OCR
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 * 
8
 * @author Janis Koehr <[email protected]>
9
 * @copyright Janis Koehr 2017
10
 */
11
namespace OCA\Ocr\Migration;
12
13
use OCP\IDBConnection;
14
use OCP\Migration\IOutput;
15
use OCP\Migration\IRepairStep;
16
17
18
class DropOldTable implements IRepairStep {
19
20
    /** @var IDBConnection */
21
    protected $connection;
22
23
    /**
24
     *
25
     * @param IDBConnection $connection            
26
     */
27 2
    public function __construct(IDBConnection $connection) {
28 2
        $this->connection = $connection;
29 2
    }
30
31
    /**
32
     * Returns the step's name
33
     * 
34
     * @return string
35
     */
36
    public function getName() {
37
        return 'Drop old database table';
38
    }
39
40
    /**
41
     * Run repair step.
42
     * Must throw exception on error.
43
     * 
44
     * @throws \Exception in case of failure
45
     */
46 2
    public function run(IOutput $output) {
47 2
        $output->startProgress(1);
48 2
        if ($this->connection->tableExists('ocr_jobs')) {
49 1
            $this->connection->dropTable('ocr_jobs');
50
        }
51
        // still needed for downwards compatibility
52 2
        if ($this->connection->tableExists('ocr_status')) {
53 1
            $this->connection->dropTable('ocr_status');
54
        }
55 2
        $output->advance(1, "Drop old database table: ocr_jobs");
56 2
        $output->finishProgress();
57
    }
58
}