Completed
Pull Request — master (#93)
by Janis
07:58
created

DropOldTable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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