Skip to content

Commit

Permalink
Fixed issue #17725: Unclear error message (#2171)
Browse files Browse the repository at this point in the history
* Fixed issue #17725: Unclear error message

- Change error message when fileinfo is missing
- Added fileinfo to Installer requirements

* Fixed issue #17725: Unclear error message

- Fixed message

Co-authored-by: encuestabizdevgit <devgit@encuesta.biz>
  • Loading branch information
gabrieljenik and encuestabizdevgit committed Dec 21, 2021
1 parent 3cf66a7 commit 55deb69
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions application/core/LSYii_ImageValidator.php
Expand Up @@ -48,7 +48,7 @@ public static function validateImage($file)
$result = [];

/** @var ?? */
$checkImage = CFileHelper::getMimeType($path);
$checkImage = CFileHelper::getMimeType($path, null, false); // Don't fallback to checking the file extension because the tmp file name doesn't have one.
$result['debug'] = $checkImage;

// TODO: Why hard-coded?
Expand All @@ -73,8 +73,14 @@ public static function validateImage($file)
$result['uploadresult'] = '';
$result['check'] = true;
} else {
$result['uploadresult'] = sprintf(gT("This file is not a supported image format - only the following ones are allowed: %s"),strtoupper(Yii::app()->getConfig('allowedthemeimageformats')));
$result['check'] = false;
// If $checkImage is empty, it's most probably because fileinfo is missing. But we check it to be sure.
if (is_null($checkImage) && !function_exists('finfo_open')) {
$result['uploadresult'] = gT("Fileinfo extension wasn't found. Couldn't validate the image format of the file is supported.");
$result['check'] = false;
} else {
$result['uploadresult'] = sprintf(gT("This file is not a supported image format - only the following ones are allowed: %s"),strtoupper(Yii::app()->getConfig('allowedthemeimageformats')));
$result['check'] = false;
}
}
return $result;
}
Expand Down
5 changes: 5 additions & 0 deletions application/models/InstallerConfigForm.php
Expand Up @@ -103,6 +103,9 @@ class InstallerConfigForm extends CFormModel
/** @var bool */
public $isPhpMbStringPresent = false;

/** @var bool */
public $isPhpFileInfoPresent = false;

/** @var bool */
public $isPhpZlibPresent = false;

Expand Down Expand Up @@ -204,6 +207,7 @@ public function validate($attributes = null, $clearErrors = true)
private function checkStatus()
{
$this->isPhpMbStringPresent = function_exists('mb_convert_encoding');
$this->isPhpFileInfoPresent = function_exists('finfo_open');
$this->isPhpZlibPresent = function_exists('zlib_get_coding_type');
$this->isPhpJsonPresent = function_exists('json_encode');
$this->isMemoryLimitOK = $this->checkMemoryLimit();
Expand Down Expand Up @@ -234,6 +238,7 @@ public function getHasMinimumRequirements()
or !$this->isConfigDirWriteable
or !$this->isPhpVersionOK
or !$this->isPhpMbStringPresent
or !$this->isPhpFileInfoPresent
or !$this->isPhpZlibPresent
or !$this->isPhpJsonPresent
) {
Expand Down
5 changes: 5 additions & 0 deletions application/views/installer/precheck_view.php
Expand Up @@ -64,6 +64,11 @@
<td><span class='fa fa-check text-success'></span></td>
<td><?= $model->isPhpMbStringPresent ? $iconOk : $iconFail ?></td>
</tr>
<tr>
<td><?php eT("PHP fileinfo library"); ?></td>
<td><span class='fa fa-check text-success'></span></td>
<td><?= $model->isPhpFileInfoPresent ? $iconOk : $iconFail ?></td>
</tr>
<tr>
<td><?php eT("PHP zlib library");?></td>
<td><span class='fa fa-check text-success'></span></td>
Expand Down

0 comments on commit 55deb69

Please sign in to comment.