]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 27 May 2019 14:51:44 +0000 (16:51 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 27 May 2019 14:51:44 +0000 (16:51 +0200)
src/app/Console/Commands/MigrateCommand.php
src/app/Magic/Fields/Field.php
src/app/Magic/Models/CubistMagicModelAbstract.php

index 771430d8f3913c6653ccf2db02ffe1b4a07d9962..6c7e6bc4a9a655ef109e120dff0a05541026142d 100644 (file)
@@ -60,7 +60,6 @@ class MigrateCommand extends CubistCommand
         $queries = $diff->toSaveSql($connection->getDatabasePlatform());
         foreach ($queries as $q) {
             $this->line($q);
-            // $connection->exec($q);
         }
     }
 
@@ -69,7 +68,7 @@ class MigrateCommand extends CubistCommand
      */
     public function _migrate($model)
     {
-        $this->line('Handle ' . get_class($model));
+        $this->line('Handling ' . get_class($model));
         $this->line($model->setSchema($this->_schema));
     }
 }
index df9fc86589799b3a50fbb00b32ad5355aef7ec92..6466d3bc5d68584d0768e2f75522765139d80de3 100644 (file)
@@ -7,6 +7,7 @@ use Cubist\Backpack\app\Magic\CubistMagicAttribute;
 use Doctrine\DBAL\Schema\Table;
 use Exception;
 use Illuminate\Support\Str;
+use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
 
 class Field
 {
@@ -99,18 +100,13 @@ class Field
         return $this->getAttribute('form');
     }
 
-    public function getDatabaseSchema()
-    {
-
-    }
-
     /**
      * @param $table Table
      */
     public function defineDbColumn($table)
     {
         $name = $this->getAttribute('name');
-        $table->addColumn($name, $this->_databaseType, $this->_databaseAttributes);
+        $table->addColumn($name, CubistMagicModelAbstract::toDoctrineType($this->_databaseType), $this->_databaseAttributes);
         if ($this->_databaseUnique) {
             $table->addUniqueIndex([$name]);
         }
index 5205a82870a7d8940761d645cddca1e5a305d109..a0c484005c0fc8c4c444849cfaf6ecf7dfcbe577 100644 (file)
@@ -9,6 +9,7 @@ use Cubist\Backpack\app\Magic\Util;
 use Cviebrock\EloquentSluggable\Sluggable;
 use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
 use Doctrine\DBAL\Schema\Schema;
+use Doctrine\DBAL\Schema\Table;
 use Illuminate\Database\Eloquent\Model;
 use Cubist\Backpack\app\Magic\CubistMagicAttribute;
 use Illuminate\Support\Str;
@@ -19,6 +20,8 @@ class CubistMagicModelAbstract extends Model
     use CrudTrait;
     use Sluggable, SluggableScopeHelpers;
 
+    protected static $_doctrineTypesMapping = ['int' => 'integer'];
+
     protected $primaryKey = 'id';
     public $timestamps = true;
 
@@ -158,9 +161,15 @@ class CubistMagicModelAbstract extends Model
     public function setSchema($schema)
     {
         $table = $schema->createTable($this->table);
-        $table->addColumn($this->primaryKey, $this->keyType, ['autoincrement' => $this->incrementing, 'unsigned' => true]);
+        try {
+            $table->addColumn($this->primaryKey, self::toDoctrineType($this->keyType), ['autoincrement' => $this->incrementing, 'unsigned' => true]);
+        } catch (\Exception $e) {
+            return $e->getMessage();
+        }
+
         $table->setPrimaryKey([$this->primaryKey], 'pk_' . $this->table);
 
+
         foreach ($this->_fields as $field) {
             $field->defineDbColumn($table);
         }
@@ -170,6 +179,13 @@ class CubistMagicModelAbstract extends Model
             $table->addColumn(static::UPDATED_AT, 'date');
             $table->addColumn('deleted_at', 'date');
         }
+    }
 
+    public static function toDoctrineType($type)
+    {
+        if (isset(self::$_doctrineTypesMapping[$type])) {
+            return self::$_doctrineTypesMapping[$type];
+        }
+        return $type;
     }
 }