Enh #49: File Converter Logging Issue (#6319)

* Enh #49: File Converter Logging Issue

* Update CHANGELOG-DEV.md

---------

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
yuriimaz 2023-05-11 17:50:08 +03:00 committed by GitHub
parent 1837cdb982
commit 6d6a0cd4ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 37 deletions

View File

@ -30,3 +30,4 @@ HumHub Changelog
- Enh #6298: Move the "Write a new comment" field style to a generic field that can be used by other modules
- Enh #6310: Module information is localized with `docs/uk/README.md` or `README.uk.md`.
- Enh #6311: Added {cols, rows} to textarea() control.
- Enh #6319: Duplicate File Converter Logs

View File

@ -8,12 +8,13 @@
namespace humhub\modules\file\converter;
use humhub\modules\admin\models\Log;
use humhub\modules\file\libs\ImageHelper;
use humhub\modules\file\Module;
use Imagine\Image\ImageInterface;
use Yii;
use humhub\modules\file\models\File;
use humhub\libs\Html;
use Yii;
use yii\imagine\Image;
/**
@ -24,7 +25,6 @@ use yii\imagine\Image;
*/
class PreviewImage extends BaseConverter
{
/**
* @var ImageInterface
*/
@ -87,7 +87,6 @@ class PreviewImage extends BaseConverter
protected function convert($fileName)
{
try {
if (!is_file($this->file->store->get($fileName))) {
$image = Image::getImagine()->open($this->file->store->get());
ImageHelper::fixJpegOrientation($image, $this->file);
@ -108,7 +107,12 @@ class PreviewImage extends BaseConverter
$image->save($this->file->store->get($fileName), $options);
}
} catch (\Exception $ex) {
Yii::warning('Could not convert file with id ' . $this->file->id . '. Error: ' . $ex->getMessage());
$message = 'Could not convert file with id ' . $this->file->id . '. Error: ' . $ex->getMessage();
$count = Log::find()->where(['message' => $message])->count();
if ($count == 0) {
Yii::warning($message);
}
}
}
@ -175,5 +179,4 @@ class PreviewImage extends BaseConverter
{
return Html::a($this->render(), $this->file->getUrl(), array_merge($htmlOptions, ['data-ui-gallery' => 'gallery-' . $this->file->guid]));
}
}

View File

@ -21,7 +21,6 @@ use humhub\modules\file\converter\TextConverter;
*/
class FilePreview extends JsWidget
{
/**
* @inheritdoc
*/
@ -113,7 +112,7 @@ class FilePreview extends JsWidget
foreach ($files as $file) {
if ($file) {
if(is_string($file)) {
if (is_string($file)) {
$file = File::findOne(['guid' => $file]);
}
$result[] = ArrayHelper::merge(FileHelper::getFileInfos($file), ['highlight' => $this->isHighlighed($file)]);
@ -133,11 +132,11 @@ class FilePreview extends JsWidget
return $this->items;
}
if(!($this->model instanceof ActiveRecord) && $this->attribute) {
if (!($this->model instanceof ActiveRecord) && $this->attribute) {
return Html::getAttributeValue($this->model, $this->attribute);
}
if(!($this->model instanceof ActiveRecord)) {
if (!($this->model instanceof ActiveRecord)) {
return [];
}
@ -159,8 +158,10 @@ class FilePreview extends JsWidget
if (Yii::$app->controller instanceof SearchController) {
if (SearchController::$keyword !== null) {
$converter = new TextConverter();
if ($converter->applyFile($file) &&
SearchHelper::matchQuery(SearchController::$keyword, $converter->getContentAsText())) {
if (
$converter->applyFile($file) &&
SearchHelper::matchQuery(SearchController::$keyword, $converter->getContentAsText())
) {
return true;
}
}
@ -168,5 +169,4 @@ class FilePreview extends JsWidget
return false;
}
}

View File

@ -9,10 +9,8 @@
namespace humhub\modules\file\widgets;
use humhub\components\ActiveRecord;
use humhub\modules\content\widgets\WallEntry;
use humhub\modules\file\converter\PreviewImage;
use Yii;
use humhub\modules\content\components\ContentActiveRecord;
/**
* This widget is used include the files functionality to a wall entry.
@ -21,7 +19,6 @@ use humhub\modules\content\components\ContentActiveRecord;
*/
class ShowFiles extends \yii\base\Widget
{
/**
* @var ActiveRecord Object to show files from
*/
@ -42,21 +39,18 @@ class ShowFiles extends \yii\base\Widget
*/
public function run()
{
if(!$this->active) {
if (!$this->active) {
return;
}
$excludeMediaFilesPreview = ($this->preview) ? Yii::$app->getModule('file')->settings->get('excludeMediaFilesPreview') : false;
return $this->render('showFiles', [
'files' => $this->object->fileManager->findStreamFiles(),
'object' => $this->object,
'previewImage' => new PreviewImage(),
'showPreview' => $this->preview,
'excludeMediaFilesPreview' => $excludeMediaFilesPreview
'previewImage' => new PreviewImage(),
'files' => $this->object->fileManager->findStreamFiles(),
'object' => $this->object,
'excludeMediaFilesPreview' => $excludeMediaFilesPreview,
'showPreview' => $this->preview
]);
}
}
?>

View File

@ -1,28 +1,28 @@
<?php
use humhub\modules\file\libs\FileHelper;
use humhub\modules\file\widgets\FilePreview;
use humhub\modules\file\libs\FileHelper;
use humhub\modules\ui\view\helpers\ThemeHelper;
use humhub\widgets\JPlayerPlaylistWidget;
use yii\helpers\Html;
/* @var $showPreview boolean */
/* @var $files \humhub\modules\file\models\File[] */
/* @var $previewImage \humhub\modules\file\converter\PreviewImage */
/* @var $files \humhub\modules\file\models\File[] */
/* @var $object \humhub\components\ActiveRecord */
/* @var $excludeMediaFilesPreview boolean */
/* @var $showPreview boolean */
$videoExtensions = ['webm', 'mp4', 'ogv', 'mov'];
$images = [];
$videos = [];
$audios = [];
foreach($files as $file) {
foreach ($files as $file) {
if ($previewImage->applyFile($file)) {
$images[] = $file;
} else if (in_array(FileHelper::getExtension($file->file_name), $videoExtensions, true)) {
} elseif (in_array(FileHelper::getExtension($file->file_name), $videoExtensions, true)) {
$videos[] = $file;
} else if (FileHelper::getExtension($file->file_name) === 'mp3') {
} elseif (FileHelper::getExtension($file->file_name) === 'mp3') {
$audios[] = $file;
}
}
@ -34,15 +34,13 @@ $fluidColumnClass = 'col-media col-xs-3 col-sm-3 col-md-2';
$galleryColumnClass = ThemeHelper::isFluid() ? $fluidColumnClass : $nonFluidColumnClass;
?>
<?php if (count($files) > 0) : ?>
<?php if (count($files) > 0): ?>
<!-- hideOnEdit mandatory since 1.2 -->
<div class="hideOnEdit">
<!-- Show Images as Thumbnails -->
<?php if($showPreview) :?>
<?php if ($showPreview):?>
<div class="post-files clearfix" id="post-files-<?= $object->getUniqueId() ?>">
<?php if(!empty($audios)) : ?>
<?php if (!empty($audios)): ?>
<div class="<?= $fullWidthColumnClass ?>">
<?= JPlayerPlaylistWidget::widget(['playlist' => $audios]) ?>
</div>
@ -84,7 +82,6 @@ $galleryColumnClass = ThemeHelper::isFluid() ? $fluidColumnClass : $nonFluidCol
</a>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
@ -94,6 +91,5 @@ $galleryColumnClass = ThemeHelper::isFluid() ? $fluidColumnClass : $nonFluidCol
'items' => $files,
'model' => $object,
]) ?>
</div>
<?php endif; ?>