* @return array
*/
protected function getApiWarnings() {
- $warnings = $this->mUpload->checkWarnings();
+ $warnings = UploadBase::makeWarningsSerializable( $this->mUpload->checkWarnings() );
return $this->transformWarnings( $warnings );
}
if ( isset( $warnings['duplicate'] ) ) {
$dupes = [];
- /** @var File $dupe */
foreach ( $warnings['duplicate'] as $dupe ) {
- $dupes[] = $dupe->getName();
+ $dupes[] = $dupe['fileName'];
}
ApiResult::setIndexedTagName( $dupes, 'duplicate' );
$warnings['duplicate'] = $dupes;
if ( isset( $warnings['exists'] ) ) {
$warning = $warnings['exists'];
unset( $warnings['exists'] );
- /** @var LocalFile $localFile */
$localFile = $warning['normalizedFile'] ?? $warning['file'];
- $warnings[$warning['warning']] = $localFile->getName();
+ $warnings[$warning['warning']] = $localFile['fileName'];
}
if ( isset( $warnings['no-change'] ) ) {
- /** @var File $file */
$file = $warnings['no-change'];
unset( $warnings['no-change'] );
$warnings['nochange'] = [
- 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() )
+ 'timestamp' => wfTimestamp( TS_ISO_8601, $file['timestamp'] )
];
}
if ( isset( $warnings['duplicate-version'] ) ) {
$dupes = [];
- /** @var File $dupe */
foreach ( $warnings['duplicate-version'] as $dupe ) {
$dupes[] = [
- 'timestamp' => wfTimestamp( TS_ISO_8601, $dupe->getTimestamp() )
+ 'timestamp' => wfTimestamp( TS_ISO_8601, $dupe['timestamp'] )
];
}
unset( $warnings['duplicate-version'] );
// We can only get warnings like 'duplicate' after concatenating the chunks
$status = Status::newGood();
- $status->value = [ 'warnings' => $upload->checkWarnings() ];
+ $status->value = [
+ 'warnings' => UploadBase::makeWarningsSerializable( $upload->checkWarnings() )
+ ];
// We have a new filekey for the fully concatenated file
$newFileKey = $upload->getStashFile()->getFileKey();
return $warnings;
}
+ /**
+ * Convert the warnings array returned by checkWarnings() to something that
+ * can be serialized. File objects will be converted to an associative array
+ * with the following keys:
+ *
+ * - fileName: The name of the file
+ * - timestamp: The upload timestamp
+ *
+ * @param mixed[] $warnings
+ * @return mixed[]
+ */
+ public static function makeWarningsSerializable( $warnings ) {
+ array_walk_recursive( $warnings, function ( &$param, $key ) {
+ if ( $param instanceof File ) {
+ $param = [
+ 'fileName' => $param->getName(),
+ 'timestamp' => $param->getTimestamp()
+ ];
+ } elseif ( is_object( $param ) ) {
+ throw new InvalidArgumentException(
+ 'UploadBase::makeWarningsSerializable: ' .
+ 'Unexpected object of class ' . get_class( $param ) );
+ }
+ } );
+ return $warnings;
+ }
+
/**
* Check whether the resulting filename is different from the desired one,
* but ignore things like ucfirst() and spaces/underscore things