Version20170808221437::changeSchema()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 3
cp 0
rs 9.7666
c 0
b 0
f 0
cc 4
nc 3
nop 2
crap 20
1
<?php
2
/**
3
 * Files_antivirus
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Viktar Dubiniuk <[email protected]>
9
 *
10
 * @copyright Viktar Dubiniuk 2018
11
 * @license AGPL-3.0
12
 */
13
14
namespace OCA\Files_Antivirus\Migrations;
15
16
use Doctrine\DBAL\Schema\Schema;
17
use Doctrine\DBAL\Types\Type;
18
use OCP\Migration\ISchemaMigration;
19
20
/**
21
 * Updates some fields to bigint if required
22
 */
23
class Version20170808221437 implements ISchemaMigration {
24
	/**
25
	 * @param Schema $schema
26
	 * @param array $options
27
	 *
28
	 * @return void
29
	 * @throws \Doctrine\DBAL\DBALException
30
	 * @throws \Doctrine\DBAL\Schema\SchemaException
31
	 */
32
	public function changeSchema(Schema $schema, array $options) {
33
		$prefix = $options['tablePrefix'];
34
35
		if ($schema->hasTable("${prefix}files_antivirus")) {
36
			$table = $schema->getTable("{$prefix}files_antivirus");
37
38
			$fileIdColumn = $table->getColumn('fileid');
39
			if ($fileIdColumn
40
				&& $fileIdColumn->getType()->getName() !== Type::BIGINT
41
			) {
42
				$fileIdColumn->setType(Type::getType(Type::BIGINT));
43
				$fileIdColumn->setOptions(['length' => 20]);
44
			}
45
		}
46
	}
47
}
48