如何在 Prestashop 1.7 中增加附件的最大文件名大小

问题描述

在 Prestashop 1.7 上,如何增加附件的最大文件名大小?
后台命名附件文件时,我遇到以下错误消息。

enter image description here

如何在 Prestashop 1.7 中解决这个问题?我在网上查了一下,找到了一些适用于 Prestashop 1.5 或 1.6 的解决方案,但不适用于 1.7。

以下是我关注的一些链接

按照上面的链接,我已经尝试过:

  • 数据库中,将“ps_attachment_lang”表中“name”列的类型更改为“varchar(128)”。
  • 在 Attachment.PHP (/classes/Attachment.PHP) 中,确保大小为 128。
'name' => ['type' => self::TYPE_STRING,'lang' => true,'validate' => 'isGenericName','required' => true,'size' => 128],
  • 在AdminProductsController.PHP(/controllers/admin/AdminProductsController.PHP)中,修改了ajaxProcessAddAttachment()函数的一部分,来自
if (!Validate::isGenericName($name)) {
  $_FILES['attachment_file']['error'][] = $this->trans('Invalid name for %s language',[$language['name']],'Admin.Notifications.Error');
} elseif (Tools::strlen($name) > 32) {
  $_FILES['attachment_file']['error'][] = $this->trans('The name for %1s language is too long (%2d chars max).',[$language['name'],32],'Admin.Notifications.Error');
}

if (!Validate::isGenericName($name)) {
  $_FILES['attachment_file']['error'][] = $this->trans('Invalid name for %s language','Admin.Notifications.Error');
} elseif (Tools::strlen($name) > 64) {
  $_FILES['attachment_file']['error'][] = $this->trans('The name for %1s language is too long (%2d chars max).',64],'Admin.Notifications.Error');
}

但不幸的是,它们都没有奏效。

提前致谢。

解决方法

这是我自己的问题,但我找到了一个解决方案。

在 AttachmentConstraint.php(在 /src/Core/Domain/Attachment/Configuration/AttachmentConstraint.php)中,找到该行

const MAX_NAME_LENGTH = 32;

并将其更改为低于数据库表可以容纳的任何数字:

//const MAX_NAME_LENGTH = 32; 
const MAX_NAME_LENGTH = 128; // this number needs to be lower than `name` column in `ps_attachment_lang` table

这应该可以解决问题,但此解决方案需要更改核心文件。如果有人知道我们可以在不修改核心文件的情况下实现这一目标的方法,请分享。