This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Glower
Glower

In the system log sometimes I can see messages like this:

PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'url' at row 1 in /var/www/asm.ru/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:105

Probably the field 'url' has no mutator to cut very long url before saving. Current core version 447

mjauvin
mjauvin

Can you submit a PR for this?

Glower
Glower

http://prntscr.com/nc1o2b

I suppose that it's kernel error

Glower
Glower

\modules\system\models\RequestLog.php

There's no mutator value for the url column. The maximum size is 191. Who can I write to fix the bug? :)

I can add event for now, but it would be better if developers fix the bug in kernel

Glower
Glower

Solution:

RequestLog::extend(function($model) {
    $model->bindEvent('model.beforeSave', function() use ($model) {
        $model->attributes['url'] = mb_substr(trim($model->attributes['url']), 0, 191);
    });
});

But it's temporary. Before updates :)

Last updated

mjauvin
mjauvin

@glower, can you test if the following patch solves the issue? I'll submit a PR to october core if it does.

diff --git a/modules/system/models/RequestLog.php b/modules/system/models/RequestLog.php
index ab93b119..615edca6 100644
--- a/modules/system/models/RequestLog.php
+++ b/modules/system/models/RequestLog.php
@@ -62,4 +62,9 @@ class RequestLog extends Model

         return $record;
     }
+
+    public function beforeModelSave()
+    {
+        $this->attributes['url'] = mb_substr(trim($model->attributes['url']), 0, 191);
+    }
 }
babenko34666
babenko34666

october/modules/system/models/RequestLog.php

line 45

'url' => substr(Request::fullUrl(), 0, 255),

change to

'url' => substr(Request::fullUrl(), 0, 191),

Last updated

mjauvin
mjauvin

even better.

mjauvin
mjauvin

https://github.com/octobercms/october/pull/4287

This has been merged into the develop branch.

1-9 of 9

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.