We need to have long posts in our new forum occasionally. I hit the limit for our rules but it would be great to have longer posts in other contexts too.
Following it up I find that it is an artificial limit in Flarum that goes back to 2020 when the database had a maximum of 65,535 characters per row in TEXT format which lets you store the data a little more efficiently, but it is only a saving of a few bytes per row.
However checking the database for our forum, Flarum has changed the database content type to permit millions of bytes per row. So, there is no longer any reason to have this limit. It is just a historical thing. Low priority presumably.
I've found out that MySql databases can usually store over a million multi-byte characters per row, enough for an entire book even when set to MEDIUMTEXT.
The Flarum posts column is indeed set to MEDIUMTEXT.
[upl-image-preview uuid=356e62b2-da0b-4297-b6b4-7a790ef11d9c url=
alt={TEXT?}]
- TINYTEXT: 255 characters - 255 B
- TEXT: 65,535 characters - 64 KB
- MEDIUMTEXT: 16,777,215 - 16 MB
- LONGTEXT: 4,294,967,295 characters - 4 GB
https://www.atlassian.com/data/databases/understanding-strorage-sizes-for-mysql-text-data-types
When someone else asked the question they got the answer:
I also found that the origin of the limit of 65536 goes back to 2020 when the column was TEXT.
QUOTE STARTS
This is a limitation of the MySQL text field that we use to store content. While this could in theory be adjusted to a MEDIUMTEXT or LONGTEXT field it requires more store space (2KB overhead for TEXT, 3KB for Medium Text, 4KB for LONGTEXT) which adds up a lot with large numbers of post. Further it's incredibly rare for people to post that much data. For that reason it's not the default.
https://discuss.flarum.org/d/25007-the-content-may-not-be-greater-than-65535-characters/2
From the screenshot I just shared it's clear that the My SQL field is now set to MEDIUMTEXT.
So it should be possible to extend it without adjusting the database if I understand right.
Perplexity AI suggests I edit a file called extend.php in the Flarum folder and gave me this code:
<?php
use Flarum\Extend;
return [
(new Extend\Validator(\Flarum\Post\PostValidator::class))
->configure(function ($flarumValidator, $validator) {
$rules = $validator->getRules();
if (!array_key_exists('content', $rules)) {
return;
}
$rules['content'] = array_map(function (string $rule) {
if (\Illuminate\Support\Str::startsWith($rule, 'max:')) {
return 'max:1000000'; // Set to 1 million characters
}
return $rule;
}, $rules['content']);
$validator->setRules($rules);
}),
];
[edited to remove the back ticks see replies]
Chatbot discussion here:
https://www.perplexity.ai/search/is-there-an-extension-or-setti-1wVHM_KwTieeAxFHztGz2Q Is there an extension or setting to increase maximum length of Flarum post beyond 65535 characters
It looks simple enough. But there is no way that I will just use code written by a chatbot without knowing how it works, not for something like this.
So that's my question. Is it as simple as that and is this code okay to use or does it need to be done slightly differently, or is there another way to do it?
I'm a coder myself, a developer of microtonal and polyrhythmic software for Windows, and I can probably add some extensions myself at a later date but I'm new to all this right now.