Completed
Push — 1.10.x ( 2635b5...f0080b )
by Yannick
165:55 queued 120:08
created

Version20150505132304   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Application\Migrations\Schema\V110;
5
6
use Application\Migrations\AbstractMigrationChamilo;
7
use Doctrine\DBAL\Schema\Schema;
8
9
/**
10
 * Extra fields changes
11
 */
12
class Version20150505132304 extends AbstractMigrationChamilo
13
{
14
    /**
15
     * @param Schema $schema
16
     */
17
    public function up(Schema $schema)
18
    {
19
        // Force table creation in order to do updates/insert later.
20
        $this->connection->executeQuery('CREATE TABLE IF NOT EXISTS extra_field (id INT AUTO_INCREMENT NOT NULL, extra_field_type INT NOT NULL, field_type INT NOT NULL, variable VARCHAR(64) NOT NULL, display_text VARCHAR(255) DEFAULT NULL, default_value LONGTEXT, field_order INT DEFAULT NULL, visible TINYINT(1) DEFAULT NULL, changeable TINYINT(1) DEFAULT NULL, filter TINYINT(1) DEFAULT NULL, created_at DATETIME NOT NULL, PRIMARY KEY(id))');
21
        $this->connection->executeQuery('CREATE TABLE IF NOT EXISTS extra_field_values (id INT AUTO_INCREMENT NOT NULL, value VARCHAR(255) DEFAULT NULL, field_id INT NOT NULL, item_id INT NOT NULL, comment LONGTEXT, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id))');
22
        $this->connection->executeQuery('CREATE TABLE IF NOT EXISTS extra_field_options (id INT AUTO_INCREMENT NOT NULL, field_id INT DEFAULT NULL, option_value LONGTEXT, display_text VARCHAR(64) DEFAULT NULL, option_order INT DEFAULT NULL, priority VARCHAR(255) DEFAULT NULL, priority_message VARCHAR(255) DEFAULT NULL, INDEX IDX_A572E3AE443707B0 (field_id), PRIMARY KEY(id))');
23
24
        if (!$schema->hasTable('extra_field_options')) {
25
            $this->connection->executeQuery(
26
                'ALTER TABLE extra_field_options ADD CONSTRAINT FK_A572E3AE443707B0 FOREIGN KEY (field_id) REFERENCES extra_field (id)'
27
            );
28
        }
29
30
        $this->addSql('CREATE TABLE IF NOT EXISTS extra_field_option_rel_field_option (id INT AUTO_INCREMENT NOT NULL, field_id INT DEFAULT NULL, field_option_id INT DEFAULT NULL, related_field_option_id INT DEFAULT NULL, role_id INT DEFAULT NULL, UNIQUE INDEX idx (field_id, role_id, field_option_id, related_field_option_id), PRIMARY KEY(id))');
31
32
        /*
33
        $this->addSql('DROP TABLE course_field');
34
        $this->addSql('DROP TABLE course_field_options');
35
        $this->addSql('DROP TABLE course_field_values');
36
        $this->addSql('DROP TABLE session_field');
37
        $this->addSql('DROP TABLE session_field_options');
38
        $this->addSql('DROP TABLE session_field_values');
39
        $this->addSql('DROP TABLE user_field');
40
        $this->addSql('DROP TABLE user_field_options');
41
        $this->addSql('DROP TABLE user_field_values');
42
        */
43
    }
44
45
    /**
46
     * @param Schema $schema
47
     */
48
    public function postUp(Schema $schema)
49
    {
50
51
    }
52
53
    /**
54
     * @param Schema $schema
55
     */
56
    public function down(Schema $schema)
57
    {
58
        $this->addSql('ALTER TABLE extra_field_options DROP FOREIGN KEY FK_A572E3AE443707B0');
59
        $this->addSql('DROP TABLE extra_field_option_rel_field_option');
60
        $this->addSql('DROP TABLE extra_field_options');
61
        $this->addSql('DROP TABLE extra_field');
62
        $this->addSql('DROP TABLE extra_field_values');
63
    }
64
}
65