Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rex_media Methode setValue() hinzufügen #5468

Open
alxndr-w opened this issue Dec 31, 2022 · 4 comments
Open

rex_media Methode setValue() hinzufügen #5468

alxndr-w opened this issue Dec 31, 2022 · 4 comments
Labels
Feature Additional functionality Mediapool "Mediapool"-Addon related things

Comments

@alxndr-w
Copy link
Contributor

Feature description / Feature Beschreibung
Momentan ist es zwar möglich, Eigenschaften aus der rex_media-Tabelle auszulesen, aber es scheint nicht möglich, diese mit passenden Methoden direkt zu ändern.

@gharlan
Copy link
Member

gharlan commented Dec 31, 2022

Doch, sollte über rex_media_service::updateMedia gehen.

Die Objekte selbst (rex_media, rex_article etc.) sind in REDAXO immer nur lesend.

@gharlan gharlan added the Mediapool "Mediapool"-Addon related things label Dec 31, 2022
@alxndr-w
Copy link
Contributor Author

Holt ein upgeloadetes File und legt es in den Medienpool Dabei wird kontrolliert ob das File schon vorhanden ist und es wird eventuell angepasst, weiterhin werden die Fileinformationen übergeben.

Das ist aus der Klassenbeschreibung und ich verstehe darunter, dass das File beim Aufruf noch nicht im Medienpool sein darf/soll.

https://friendsofredaxo.github.io/phpdoc/classes/rex-media-service.html#method_updateMedia

@alxndr-w
Copy link
Contributor Author

alxndr-w commented Jan 5, 2023

Ich habe mir das nochmal genauer angesehen. Mehr als den Titel und die Kategorie kann ich hier doch gar nicht in $data übergeben? Das wird doch gar nicht weiter verarbeitet...

public static function updateMedia(string $filename, array $data): array
{
if ('' === $filename) {
throw new rex_api_exception('Expecting Filename.');
}
$media = rex_media::get($filename);
if (!$media) {
throw new rex_api_exception(rex_i18n::msg('pool_file_not_found'));
}
$saveObject = rex_sql::factory();
$saveObject->setTable(rex::getTablePrefix() . 'media');
$saveObject->setWhere(['filename' => $filename]);
$saveObject->setValue('title', $data['title']);
$saveObject->setValue('category_id', (int) $data['category_id']);
$file = $data['file'] ?? null;
$filetype = null;
if ($file && !empty($file['name'])) {
$error = $file['error'] ?? null;
if (UPLOAD_ERR_INI_SIZE === $error) {
throw new rex_api_exception(rex_i18n::msg('pool_file_upload_error_size', rex_formatter::bytes(rex_ini_get('upload_max_filesize'))));
}
if ($error) {
throw new rex_api_exception(rex_i18n::msg('pool_file_upload_error'));
}
$file['path'] = $file['tmp_name'] ?? null;
if (empty($file['path'])) {
throw new rex_api_exception(rex_i18n::msg('pool_file_not_found'));
}
$filetype = rex_file::mimeType($file['path']);
$srcFile = $file['path'];
$dstFile = rex_path::media($filename);
$extensionNew = mb_strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
$extensionOld = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION));
static $jpgExtensions = ['jpg', 'jpeg'];
if (
$extensionNew == $extensionOld ||
in_array($extensionNew, $jpgExtensions) && in_array($extensionOld, $jpgExtensions)
) {
if (!rex_file::move($srcFile, $dstFile)) {
throw new rex_api_exception(rex_i18n::msg('pool_file_movefailed'));
}
@chmod($dstFile, rex::getFilePerm());
$saveObject->setValue('filetype', $filetype);
$saveObject->setValue('filesize', filesize($dstFile));
$saveObject->setValue('originalname', $file['name']);
if ($size = @getimagesize($dstFile)) {
$saveObject->setValue('width', $size[0]);
$saveObject->setValue('height', $size[1]);
}
@chmod($dstFile, rex::getFilePerm());
} else {
throw new rex_api_exception(rex_i18n::msg('pool_file_upload_errortype'));
}
}
$saveObject->addGlobalUpdateFields();
$saveObject->update();
rex_media_cache::delete($filename);
/**
* @deprecated $return
* in future only $data -> MEDIA_UPDATED and return $data;
*/
$return = $data;
$return['ok'] = 1;
$return['msg'] = rex_i18n::msg('pool_file_infos_updated');
$return['id'] = $media->getId();
$return['filename'] = $filename;
$return['type'] = $filetype;
$return['filetype'] = $filetype;
rex_extension::registerPoint(new rex_extension_point('MEDIA_UPDATED', '', $return));
return $return;
}

@gharlan
Copy link
Member

gharlan commented Jan 5, 2023

Ja stimmt, dann haben wir da leider noch keine Möglichkeit für.

@gharlan gharlan added the Feature Additional functionality label Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Additional functionality Mediapool "Mediapool"-Addon related things
Development

No branches or pull requests

2 participants