From ea5d3788b0fa2d098c345d139d489d4db678bb5d Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Fri, 19 May 2017 14:58:32 +0200 Subject: [PATCH] Fix ticket db update see #1954 --- app/Migrations/Schema/V111/Version111.php | 44 ++++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/app/Migrations/Schema/V111/Version111.php b/app/Migrations/Schema/V111/Version111.php index d8d21c983b..67211dc283 100644 --- a/app/Migrations/Schema/V111/Version111.php +++ b/app/Migrations/Schema/V111/Version111.php @@ -176,7 +176,16 @@ class Version111 extends AbstractMigrationChamilo $this->addSql('ALTER TABLE plugin_ticket_ticket DROP ticket_id, DROP ticket_code, DROP request_user'); $this->addSql('ALTER TABLE plugin_ticket_ticket MODIFY COLUMN id INT NOT NULL PRIMARY KEY AUTO_INCREMENT'); + $table = $schema->getTable('plugin_ticket_ticket'); + if ($table->hasIndex('fk_ticket_priority')) { + $table->renameIndex('fk_ticket_priority', 'IDX_EDE2C768497B19F9'); + } + if ($schema->hasTable('plugin_ticket_assigned_log')) { + $table = $schema->getTable('plugin_ticket_assigned_log'); + if ($table->hasIndex('fk_ticket_assigned_log')) { + $table->renameIndex('fk_ticket_assigned_log', 'IDX_54B65868700047D2'); + } $this->addSql('RENAME TABLE plugin_ticket_assigned_log TO ticket_assigned_log'); $this->addSql('ALTER TABLE ticket_assigned_log ENGINE=InnoDB'); } @@ -187,11 +196,21 @@ class Version111 extends AbstractMigrationChamilo } if ($schema->hasTable('plugin_ticket_message')) { + $table = $schema->getTable('plugin_ticket_message'); + if ($table->hasIndex('fk_tick_message')) { + $table->renameIndex('fk_tick_message', 'IDX_BA71692D700047D2'); + } + $this->addSql('RENAME TABLE plugin_ticket_message TO ticket_message'); - $this->addSql('ALTER TABLE plugin_ticket_message ENGINE=InnoDB'); + $this->addSql('ALTER TABLE ticket_message ENGINE=InnoDB'); } if ($schema->hasTable('plugin_ticket_message_attachments')) { + $table = $schema->getTable('plugin_ticket_message_attachments'); + if ($table->hasIndex('ticket_message_id_fk')) { + $table->renameIndex('ticket_message_id_fk', 'IDX_70BF9E26537A1329'); + } + $this->addSql('RENAME TABLE plugin_ticket_message_attachments TO ticket_message_attachments'); $this->addSql('ALTER TABLE ticket_message_attachments ENGINE=InnoDB'); } @@ -212,17 +231,16 @@ class Version111 extends AbstractMigrationChamilo if ($schema->hasTable('plugin_ticket_project')) { $this->addSql('RENAME TABLE plugin_ticket_project TO ticket_project'); $this->addSql('ALTER TABLE ticket_project ENGINE=InnoDB'); - } if ($schema->hasTable('plugin_ticket_status')) { $this->addSql('RENAME TABLE plugin_ticket_status TO ticket_status'); - $this->addSql('ALTER TABLE plugin_ticket_status ENGINE=InnoDB'); + $this->addSql('ALTER TABLE ticket_status ENGINE=InnoDB'); } if ($schema->hasTable('plugin_ticket_ticket')) { $this->addSql('RENAME TABLE plugin_ticket_ticket TO ticket_ticket'); - $this->addSql('ALTER TABLE plugin_ticket_ticket ENGINE=InnoDB'); + $this->addSql('ALTER TABLE ticket_ticket ENGINE=InnoDB'); } $this->addSql('ALTER TABLE ticket_project DROP project_id, CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE description description LONGTEXT DEFAULT NULL, CHANGE email email VARCHAR(255) DEFAULT NULL, CHANGE other_area other_area INT DEFAULT NULL, CHANGE sys_insert_user_id sys_insert_user_id INT NOT NULL, CHANGE sys_insert_datetime sys_insert_datetime DATETIME NOT NULL, CHANGE sys_lastedit_user_id sys_lastedit_user_id INT DEFAULT NULL;'); @@ -266,10 +284,6 @@ class Version111 extends AbstractMigrationChamilo $this->addSql('ALTER TABLE ticket_message_attachments DROP message_attch_id, CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE message_id message_id INT DEFAULT NULL, CHANGE ticket_id ticket_id INT DEFAULT NULL, CHANGE filename filename LONGTEXT NOT NULL, CHANGE size size INT NOT NULL, CHANGE sys_insert_user_id sys_insert_user_id INT NOT NULL, CHANGE sys_insert_datetime sys_insert_datetime DATETIME NOT NULL, CHANGE sys_lastedit_user_id sys_lastedit_user_id INT DEFAULT NULL;'); $this->addSql('ALTER TABLE ticket_message_attachments ADD CONSTRAINT FK_70BF9E26700047D2 FOREIGN KEY (ticket_id) REFERENCES ticket_ticket (id);'); $this->addSql('CREATE INDEX IDX_70BF9E26700047D2 ON ticket_message_attachments (ticket_id);'); - $table = $schema->getTable('ticket_message_attachments'); - if ($table->hasIndex('ticket_message_id_fk')) { - $table->renameIndex('ticket_message_id_fk', 'IDX_70BF9E26537A1329'); - } } $this->addSql('UPDATE ticket_priority SET sys_insert_user_id = 1 WHERE sys_insert_user_id IS NULL'); @@ -302,11 +316,6 @@ class Version111 extends AbstractMigrationChamilo $this->addSql('CREATE INDEX IDX_EDE2C768613FECDF ON ticket_ticket (session_id);'); $this->addSql('CREATE INDEX IDX_EDE2C7686BF700BD ON ticket_ticket (status_id);'); - $table = $schema->getTable('ticket_ticket'); - if ($table->hasIndex('fk_ticket_priority')) { - $table->renameIndex('fk_ticket_priority', 'IDX_EDE2C768497B19F9'); - } - $this->addSql('ALTER TABLE ticket_assigned_log CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE ticket_id ticket_id INT DEFAULT NULL, CHANGE user_id user_id INT DEFAULT NULL, CHANGE assigned_date assigned_date DATETIME NOT NULL, CHANGE sys_insert_user_id sys_insert_user_id INT NOT NULL;'); $this->addSql('ALTER TABLE ticket_assigned_log ADD CONSTRAINT FK_54B65868700047D2 FOREIGN KEY (ticket_id) REFERENCES ticket_ticket (id);'); @@ -315,18 +324,11 @@ class Version111 extends AbstractMigrationChamilo $this->addSql('ALTER TABLE ticket_assigned_log ADD CONSTRAINT FK_54B65868A76ED395 FOREIGN KEY (user_id) REFERENCES user (id);'); $this->addSql('CREATE INDEX IDX_54B65868A76ED395 ON ticket_assigned_log (user_id);'); - $table = $schema->getTable('ticket_assigned_log'); - if ($table->hasIndex('fk_ticket_assigned_log')) { - $table->renameIndex('fk_ticket_assigned_log', 'IDX_54B65868700047D2'); - } + $this->addSql('ALTER TABLE ticket_message DROP message_id, CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE ticket_id ticket_id INT DEFAULT NULL, CHANGE subject subject VARCHAR(255) DEFAULT NULL, CHANGE message message LONGTEXT DEFAULT NULL, CHANGE status status VARCHAR(255) NOT NULL, CHANGE ip_address ip_address VARCHAR(255) NOT NULL, CHANGE sys_insert_user_id sys_insert_user_id INT NOT NULL, CHANGE sys_insert_datetime sys_insert_datetime DATETIME NOT NULL, CHANGE sys_lastedit_user_id sys_lastedit_user_id INT DEFAULT NULL;'); $this->addSql('ALTER TABLE ticket_message ADD CONSTRAINT FK_BA71692D700047D2 FOREIGN KEY (ticket_id) REFERENCES ticket_ticket (id);'); - $table = $schema->getTable('ticket_message'); - if ($table->hasIndex('fk_tick_message')) { - $table->renameIndex('fk_tick_message', 'IDX_BA71692D700047D2'); - } $this->addSql('ALTER TABLE ticket_ticket CHANGE category_id category_id INT DEFAULT NULL;'); $this->addSql('ALTER TABLE ticket_ticket ADD CONSTRAINT FK_EDE2C76812469DE2 FOREIGN KEY (category_id) REFERENCES ticket_category (id);');