Browse Source

Check if variables exists already in the database see #2012

jmontoyaa 7 years ago
parent
commit
7c9d7aedeb

+ 6 - 3
app/Migrations/Schema/V110/Version20150609113500.php

@@ -16,9 +16,12 @@ class Version20150609113500 extends AbstractMigrationChamilo
      */
     public function up(Schema $schema)
     {
-        $this->addSql("INSERT INTO extra_field
-            (extra_field_type, field_type, variable, display_text, visible, changeable, created_at)
-            VALUES (2, 10, 'tags', 'Tags', 1, 1, NOW())");
+        $connection = $this->connection;
+        $sql = "SELECT id FROM extra_field WHERE variable = 'tags'";
+        $result = $connection->executeQuery($sql)->fetchAll();
+        if (empty($result)) {
+            $this->addSql("INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at) VALUES (2, 10, 'tags', 'Tags', 1, 1, NOW())");
+        }
     }
 
     /**

+ 6 - 3
app/Migrations/Schema/V110/Version20150616093200.php

@@ -16,9 +16,12 @@ class Version20150616093200 extends AbstractMigrationChamilo
      */
     public function up(Schema $schema)
     {
-        $this->addSql("INSERT INTO extra_field (
-            extra_field_type, field_type, variable, display_text, visible, changeable, created_at)
-            VALUES (2, 19, 'video_url', 'VideoUrl', 1, 1, NOW())");
+        $connection = $this->connection;
+        $sql = "SELECT id FROM extra_field WHERE variable = 'video_url'";
+        $result = $connection->executeQuery($sql)->fetchAll();
+        if (empty($result)) {
+            $this->addSql("INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at) VALUES (2, 19, 'video_url', 'VideoUrl', 1, 1, NOW())");
+        }
     }
 
     /**

+ 6 - 3
app/Migrations/Schema/V110/Version20150624164100.php

@@ -16,9 +16,12 @@ class Version20150624164100 extends AbstractMigrationChamilo
      */
     public function up(Schema $schema)
     {
-        $this->addSql("INSERT INTO extra_field
-            (extra_field_type, field_type, variable, display_text, visible, changeable, created_at)
-            VALUES (3, 16, 'image', 'Image', 1, 1, NOW())");
+        $connection = $this->connection;
+        $sql = "SELECT id FROM extra_field WHERE variable = 'image'";
+        $result = $connection->executeQuery($sql)->fetchAll();
+        if (empty($result)) {
+            $this->addSql("INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at) VALUES (3, 16, 'image', 'Image', 1, 1, NOW())");
+        }
     }
 
     /**

+ 6 - 3
app/Migrations/Schema/V110/Version20150625155000.php

@@ -16,9 +16,12 @@ class Version20150625155000 extends AbstractMigrationChamilo
      */
     public function up(Schema $schema)
     {
-        $this->addSql("INSERT INTO extra_field
-            (extra_field_type, field_type, variable, display_text, visible, changeable, created_at)
-            VALUES (1, 1, 'captcha_blocked_until_date', 'Account locked until', 0, 0, NOW())");
+        $connection = $this->connection;
+        $sql = "SELECT id FROM extra_field WHERE variable = 'captcha_blocked_until_date'";
+        $result = $connection->executeQuery($sql)->fetchAll();
+        if (empty($result)) {
+            $this->addSql("INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at) VALUES (1, 1, 'captcha_blocked_until_date', 'Account locked until', 0, 0, NOW())" );
+        }
     }
 
     /**

+ 12 - 12
app/Migrations/Schema/V111/Version20160610142700.php

@@ -21,25 +21,25 @@ class Version20160610142700 extends AbstractMigrationChamilo
      */
     public function up(Schema $schema)
     {
-        $dataList = $this
-            ->connection
-            ->executeQuery("
-                SELECT id FROM extra_field
-                WHERE variable = 'skype' AND extra_field_type = 1 
-            ")
-            ->fetchAll();
+        $connection = $this->connection;
+        $sql = "SELECT id FROM extra_field WHERE variable = 'skype' AND extra_field_type = 1";
+        $result = $connection->executeQuery($sql)->fetchAll();
 
-        if (empty($dataList)) {
+        if (empty($result)) {
             $this->addSql("
                 INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at)
-                VALUES (1, 1, 'skype', 'Skype', 1, 1, now())
+                VALUES (1, 1, 'skype', 'Skype', 1, 1, NOW())
             ");
         }
 
-        $this->addSql("
+        $sql = "SELECT id FROM extra_field WHERE variable = 'skype' AND extra_field_type = 1";
+        $result = $connection->executeQuery($sql)->fetchAll();
+        if (empty($result)) {
+            $this->addSql("
             INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at)
-            VALUES (1, 1, 'linkedin_url', 'LinkedInUrl', 1, 1, now())
-        ");
+            VALUES (1, 1, 'linkedin_url', 'LinkedInUrl', 1, 1, NOW())"
+            );
+        }
 
         $this->addSettingCurrent(
             'allow_show_skype_account',

+ 6 - 1
app/Migrations/Schema/V111/Version20160706145000.php

@@ -21,7 +21,12 @@ class Version20160706145000 extends AbstractMigrationChamilo
      */
     public function up(Schema $schema)
     {
-        $this->addSql("INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at) VALUES (8, 10, 'tags', 'Tags', 1, 1, NOW())");
+        $connection = $this->connection;
+        $sql = "SELECT id FROM extra_field WHERE variable = 'tags'";
+        $result = $connection->executeQuery($sql)->fetchAll();
+        if (empty($result)) {
+            $this->addSql("INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at) VALUES (8, 10, 'tags', 'Tags', 1, 1, NOW())");
+        }
     }
 
     /**