Better checking TechnicalDataSet return type.

This commit is contained in:
Benoît Burnichon
2015-07-10 09:48:09 +02:00
parent 02cd830491
commit 4c1fcff4e6
6 changed files with 34 additions and 14 deletions

View File

@@ -897,14 +897,20 @@ class Bridge_Api_Dailymotion extends Bridge_Api_Abstract implements Bridge_Api_I
private function check_record_constraints(record_adapter $record) private function check_record_constraints(record_adapter $record)
{ {
$errors = []; $errors = [];
if ( ! $record->get_hd_file() instanceof \SplFileInfo) //Record must rely on real file
$errors["file_size"] = $this->translator->trans("Le record n'a pas de fichier physique"); //Record must rely on real file if (!$record->get_hd_file() instanceof \SplFileInfo) {
$errors["file_size"] = $this->translator->trans("Le record n'a pas de fichier physique");
}
if ($record->get_duration() > self::AUTH_VIDEO_DURATION) if ($record->get_duration() > self::AUTH_VIDEO_DURATION) {
$errors["duration"] = $this->translator->trans("La taille maximale d'une video est de %duration% minutes.", ['%duration%' => self::AUTH_VIDEO_DURATION / 60]); $errors["duration"] = $this->translator->trans("La taille maximale d'une video est de %duration% minutes.", ['%duration%' => self::AUTH_VIDEO_DURATION / 60]);
}
if ($record->get_technical_infos('size')->getValue() > self::AUTH_VIDEO_SIZE) $size = $record->get_technical_infos('size');
$size = $size ? $size->getValue() : PHP_INT_MAX;
if ($size > self::AUTH_VIDEO_SIZE) {
$errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]); $errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
}
return $errors; return $errors;
} }

View File

@@ -805,10 +805,16 @@ class Bridge_Api_Flickr extends Bridge_Api_Abstract implements Bridge_Api_Interf
private function check_record_constraints(record_adapter $record) private function check_record_constraints(record_adapter $record)
{ {
$errors = []; $errors = [];
if ( ! $record->get_hd_file() instanceof \SplFileInfo) //Record must rely on real file
$errors["file_size"] = $this->translator->trans("Le record n'a pas de fichier physique"); //Record must rely on real file if ( ! $record->get_hd_file() instanceof \SplFileInfo) {
if ($record->get_technical_infos('size')->getValue() > self::AUTH_PHOTO_SIZE) $errors["file_size"] = $this->translator->trans("Le record n'a pas de fichier physique");
}
$size = $record->get_technical_infos('size');
$size = $size ? $size->getValue() : PHP_INT_MAX;
if ($size > self::AUTH_PHOTO_SIZE) {
$errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]); $errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
}
return $errors; return $errors;
} }

View File

@@ -1013,14 +1013,20 @@ class Bridge_Api_Youtube extends Bridge_Api_Abstract implements Bridge_Api_Inter
{ {
$errors = []; $errors = [];
$key = $record->get_serialize_key(); $key = $record->get_serialize_key();
if ( ! $record->get_hd_file() instanceof SplFileInfo) //Record must rely on real file
$errors["file_size_" . $key] = $this->translator->trans("Le record n'a pas de fichier physique"); //Record must rely on real file if ( ! $record->get_hd_file() instanceof SplFileInfo) {
$errors["file_size_" . $key] = $this->translator->trans("Le record n'a pas de fichier physique");
}
if ($record->get_duration() > self::AUTH_VIDEO_DURATION) if ($record->get_duration() > self::AUTH_VIDEO_DURATION) {
$errors["duration_" . $key] = $this->translator->trans("La taille maximale d'une video est de %duration% minutes.", ['%duration%' => self::AUTH_VIDEO_DURATION / 60]); $errors["duration_" . $key] = $this->translator->trans("La taille maximale d'une video est de %duration% minutes.", ['%duration%' => self::AUTH_VIDEO_DURATION / 60]);
}
if ($record->get_technical_infos('size')->getValue() > self::AUTH_VIDEO_SIZE) $size = $record->get_technical_infos('size');
$size = $size ? $size->getValue() : PHP_INT_MAX;
if ($size > self::AUTH_VIDEO_SIZE) {
$errors["size_" . $key] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]); $errors["size_" . $key] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
}
return $errors; return $errors;
} }

View File

@@ -320,7 +320,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
public function get_duration() public function get_duration()
{ {
if (!$this->duration) { if (!$this->duration) {
$this->duration = round($this->get_technical_infos(media_subdef::TC_DATA_DURATION)->getValue()); $duration = $this->get_technical_infos(media_subdef::TC_DATA_DURATION);
$this->duration = $duration ? round($duration->getValue()) : 0;
} }
return $this->duration; return $this->duration;

View File

@@ -110,8 +110,9 @@
{% set dataW = constant('media_subdef::TC_DATA_WIDTH') %} {% set dataW = constant('media_subdef::TC_DATA_WIDTH') %}
{% set dataH = constant('media_subdef::TC_DATA_HEIGHT') %} {% set dataH = constant('media_subdef::TC_DATA_HEIGHT') %}
{% set width = record.get_technical_infos(dataW).value %} {% set technical_info = record.get_technical_infos %}
{% set height = record.get_technical_infos(dataH).value %} {% set width = technical_info[dataW].value %}
{% set height = technical_infos[dataH].value %}
{% if width and height %} {% if width and height %}
{% set ratio = (width / height)|number_format(2, '.') %} {% set ratio = (width / height)|number_format(2, '.') %}