BUG: tinymce field can't use media library image CMSB 3.82
5 posts by 2 authors in: Forums > CMS Builder
Last Post: 4 hours ago (RSS)
By kitsguru - January 27
I was trying to use an image from the media library in the wysiwyg editor. This was previously allowed.
In the cmsb/lib/media_functions.php I discovered these lines of code:
// Validate upload field exists and user has access
$fieldName = request('fieldName');
$uploadFields = Schema::fields($GLOBALS['tableName'], 'upload');
$uploadFieldSchema = $uploadFields[$fieldName] ?? null;
match (true) {
empty($uploadFieldSchema) => die("Invalid upload field: $fieldName"),
!userHasFieldAccess($uploadFieldSchema) => die("No access to field: $fieldName"),
default => null,
};
This issue is that the tinymce field is not type upload but mediumtext.
yaadev.com
By Dave - January 30
Hi Jeff,
Great find, thanks for reporting that.
We'll have that patched in the next beta and here's some updated code if you want to try it now:
// Validate field exists (upload or wysiwyg with allowUploads) and user has access
$fieldName = request('fieldName');
$fieldSchema = Schema::fields($GLOBALS['tableName'])[$fieldName] ?? null;
$canUpload = $fieldSchema && ($fieldSchema['type'] === 'upload' || ($fieldSchema['type'] === 'wysiwyg' && !empty($fieldSchema['allowUploads'])));
match (true) {
empty($fieldSchema) => die("Invalid field: $fieldName"),
!$canUpload => die("Field doesn't allow uploads: $fieldName"),
!userHasFieldAccess($fieldSchema) => die("No access to field: $fieldName"),
default => null,
};
Let me know if you run into any other issues. Thanks!
interactivetools.com
By kitsguru - January 31
That didn't work and actually threw another error
Error: Error inserting row.
mysqli_sql_exception(1364): Field 'filePath' doesn't have a default value
Last SQL query (visible to admins only):
INSERT INTO `cmsb_uploads` SET `createdTime` = NOW(), `tableName` = "blog", `fieldName` = "content", `recordNum` = "6", `mediaNum` = 36, `preSaveTempId` = "", `order` = 1769895591, `width` = 0, `height` = 0, `thumbWidth` = 0, `thumbHeight` = 0, `thumbWidth2` = 0, `thumbHeight2` = 0, `thumbWidth3` = 0, `thumbHeight3` = 0, `thumbWidth4` = 0, `thumbHeight4` = 0 in /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/DB.php:363 [Admin View]
Backtrace:
#0 Script started at /Volumes/J/@projects/yaaws5/html/www/cmsb/admin.php:0
#1 require() at /Volumes/J/@projects/yaaws5/html/www/cmsb/admin.php:81
#2 media_addMediaAjax() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/menus/default/actionHandler.php:98
#3 Itools\ZenDB\DB::insert() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/media_functions.php:381
#4 Itools\ZenDB\DB->fetchResultSet() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/DB.php:360
#5 Itools\ZenDB\MysqliWrapper->query() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/DB.php:1011
#6 mysqli->query() at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/MysqliWrapper.php:90
#7 mysqli_sql_exception(1364) thrown at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/MysqliWrapper.php:90
#8 Itools\ZenDB\DBException(1364) thrown at /Volumes/J/@projects/yaaws5/html/www/cmsb/lib/ZenDB/DB.php:363
yaadev.com
By Dave - February 3
Hi Jeff,
You might have an old schema file or mysql column definitions from an old backup.
The upload section is hidden in the database editor but you can direct link to it like this:
/cmsb/admin.php?menu=database&action=editTable&tableName=uploads&tab=mysql
Check what filePath is, it should be:
`filePath` varchar(255) DEFAULT NULL,
For any fields that don't have "DEFAULT NULL", just click modify and save on the field and it will ensure it has the right type.
Hope that helps!
interactivetools.com
By kitsguru - 4 hours ago
I am still getting an error, even though the image from the media library is being added. I did a bit of triage and traced it to the cmsb/lib/menus/default/wysiwygMedia.php at line 119
try {
const response = await fetch('?', {
method: 'POST',
body: formData
});
const msg = await response.text();
if (msg) {
return alert("Error: " + msg);
}
// refresh upload iframe and close modal in parent window
const parentWindow = self.parent;
const uploadIframe = parentWindow.document.getElementById(fieldName + '_iframe');
uploadIframe.contentDocument.location.reload();
parentWindow.hideModal();
} catch {
alert("1. There was an error adding media!");
}
There were two locations with the same error message, 'There was an error adding media!', so I added the '1' to determine which one was being thrown. There is noting in the logs to indicate why the error is thrown.
yaadev.com