Completed
Push — master ( 721837...277496 )
by Victor
13:18
created

Version20170804201253::changeSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace OC\Migrations;
4
5
use Doctrine\DBAL\Schema\Schema;
6
use Doctrine\DBAL\Types\Type;
7
use OCP\Migration\ISchemaMigration;
8
9
/**
10
 * Updates some fields to bigint if required
11
 */
12
class Version20170804201253 implements ISchemaMigration {
13
	public function changeSchema(Schema $schema, array $options) {
14
		$prefix = $options['tablePrefix'];
15
		$this->updateToBigint($schema, "${prefix}mounts", "root_id");
16
		$this->updateToBigint($schema, "${prefix}filecache", "fileid");
17
		$this->updateToBigint($schema, "${prefix}filecache", "parent");
18
		$this->updateToBigint($schema, "${prefix}vcategory_to_object", "objid");
19
	}
20
21
	/**
22
	 * @param Schema $schema
23
	 * @param string $tableName
24
	 * @param string $columnName
25
	 */
26
	protected function updateToBigint(Schema $schema, $tableName, $columnName) {
27
		if ($schema->hasTable($tableName)) {
28
			$table = $schema->getTable($tableName);
29
30
			$column = $table->getColumn($columnName);
31
			if ($column && $column->getType()->getName() !== Type::BIGINT) {
32
				$column->setType(Type::getType(Type::BIGINT));
33
				$column->setOptions(['length' => 20]);
34
			}
35
		}
36
	}
37
}
38