Fix migration issue with fields that might already exist in the database - refs CT#7892

1.10.x
Yannick Warnier 10 years ago
parent bda9ac54e7
commit 35bbbde1f5
  1. 36
      app/Migrations/Schema/V110/Version20150522222222.php

@ -17,9 +17,41 @@ class Version20150522222222 extends AbstractMigrationChamilo
*/
public function up(Schema $schema)
{
$this->addSql('ALTER TABLE user ADD COLUMN last_login datetime DEFAULT NULL');
// The first ALTER queries here requires a check because the field might already exist
$connection = $this->connection;
$fieldExists = false;
$sql = "SELECT *
FROM user
LIMIT 1";
$result = $connection->executeQuery($sql);
$dataList = $result->fetchAll();
if (!empty($dataList)) {
foreach ($dataList as $data) {
if (isset($data['last_login'])) {
$fieldExists = true;
}
}
}
if (!$fieldExists) {
$this->addSql('ALTER TABLE user ADD COLUMN last_login datetime DEFAULT NULL');
}
// calendar events comments
$this->addSql("ALTER TABLE c_calendar_event ADD COLUMN comment TEXT");
$fieldExists = false;
$sql = "SELECT *
FROM c_calendar_event
LIMIT 1";
$result = $connection->executeQuery($sql);
$dataList = $result->fetchAll();
if (!empty($dataList)) {
foreach ($dataList as $data) {
if (isset($data['comment'])) {
$fieldExists = true;
}
}
}
if (!$fieldExists) {
$this->addSql("ALTER TABLE c_calendar_event ADD COLUMN comment TEXT");
}
// Move some settings from configuration.php to the database
// Current settings categories are:

Loading…
Cancel
Save