Completed
Pull Request — master (#546)
by Thomas
03:34
created

Version20161122092159::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 2
1
<?php
2
3
namespace OCA\activity\Migrations;
4
5
use Doctrine\DBAL\Migrations\AbstractMigration;
6
use Doctrine\DBAL\Platforms\OraclePlatform;
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\DBAL\Types\Type;
9
10
class Version20161122092159 extends AbstractMigration {
11
    /**
12
     * @param Schema $schema
13
     */
14
    public function up(Schema $schema) {
15
		$prefix = $this->connection->getPrefix();
16
		$tableName = "{$prefix}activity";
17
		$table = $schema->getTable($tableName);
18
		// we only apply this step if the columns is not yet a CLOB
19
		if ($table->getColumn('subjectparams')->getType() === Type::getType(Type::TEXT)) {
20
			return;
21
		}
22
23
		if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
0 ignored issues
show
Bug introduced by
The class Doctrine\DBAL\Platforms\OraclePlatform does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
24
			$tableName = $this->connection->quoteIdentifier($tableName);
25
			$this->addSql("ALTER TABLE $tableName ADD (\"tmpsubjectparams\" CLOB, \"tmpmessageparams\" CLOB)");
26
			$this->addSql("UPDATE $tableName SET \"tmpsubjectparams\"=\"subjectparams\", \"tmpmessageparams\"=\"messageparams\"");
27
			$this->addSql("COMMIT");
28
			$this->addSql("ALTER TABLE $tableName DROP COLUMN \"subjectparams\"");
29
			$this->addSql("ALTER TABLE $tableName DROP COLUMN \"messageparams\"");
30
			$this->addSql("ALTER TABLE $tableName RENAME COLUMN \"tmpsubjectparams\" TO \"subjectparams\"");
31
			$this->addSql("ALTER TABLE $tableName RENAME COLUMN \"tmpmessageparams\" TO \"messageparams\"");
32
		} else {
33
			$table = $schema->getTable($tableName);
34
			$table->changeColumn('subjectparams', ['type' => Type::getType('text')]);
35
			$table->changeColumn('messageparams', ['type' => Type::getType('text')]);
36
		}
37
    }
38
39
    /**
40
     * @param Schema $schema
41
     */
42
    public function down(Schema $schema) {
43
		$prefix = $this->connection->getPrefix();
44
		$table = $schema->getTable("{$prefix}activity");
45
		$table->changeColumn('subjectparams', ['type' => Type::getType('string'), 'length' => '4000']);
46
		$table->changeColumn('messageparams', ['type' => Type::getType('string'), 'length' => '4000']);
47
    }
48
}
49