sebastian-lenz / craft-linkfield

Link field for Craft 3
MIT License
122 stars 65 forks source link

$type of 'tel' leads to out of range error #262

Open oknate opened 1 year ago

oknate commented 1 year ago

When running the migration with 2.0.0-rc.2 Exception: SQLSTATE[22003]: Numeric value out of range: 7 ERROR: value "+33149544600" is out of range for type integer The SQL being executed was: SELECT EXISTS(SELECT "id" FROM "elements" WHERE "id"='+33149544600') (/var/www/html/vendor/yiisoft/yii2/db/Schema.php:676)

The problem is it tries to put the value as a key in the linkedSiteId column, but this only accepts integers

oknate commented 1 year ago

This code got us around the error:

@@ -145,7 +164,8 @@ class m190417_202153_migrateDataToTable extends Migration
       unset($payload['type']);
       unset($payload['value']);

-      if ($value && is_numeric($value)) {
+
+      if ($type !== 'tel' && $value && is_numeric($value)) {
         $doesExist = (new Query())
           ->select('id')
           ->where(['id' => $value])
@@ -157,6 +177,10 @@ class m190417_202153_migrateDataToTable extends Migration
         }
       }

+      if ($type === 'tel') {
+        $value = '';
+      }
+
       $insertRows[] = [
         $row['elementId'],                          // elementId
         $row['siteId'],                             // siteId