edwardspec / mediawiki-aws-s3

Extension:AWS allows MediaWiki to use Amazon S3 (instead of the local directory) to store images.
https://www.mediawiki.org/wiki/Extension:AWS
GNU General Public License v2.0
42 stars 32 forks source link

Undefined index: src in AmazonS3FileBackend.php on line 795 #41

Closed tim1mike closed 3 years ago

tim1mike commented 3 years ago

I'm only beginner, just installed AWS extension on my wiki and it works fine, a bit slow but I got used to it, And now I see this problem every time when someone edits the article with images

PHP Notice: Undefined index: src in /var/www/w/extensions/AWS/s3/AmazonS3FileBackend.php on line 795, referer: http://my_site.com/wiki/article_1?veaction=edit

I checked the line 795 it contains: 'srcs' => $params['src'],

the more details from AmazonS3FileBackend.php

/**
 * Obtain local copies of files from Amazon S3.
 * @param array $params
 * @return array
 *
 * @phan-return array<string,FSFile|null>
 */
protected function doGetLocalCopyMulti( array $params ) {
    $fsFiles = [];
    $params += [
        'srcs' => $params['src'],
        'concurrency' => isset( $params['srcs'] ) ? count( $params['srcs'] ) : 1
    ];
    foreach ( array_chunk( $params['srcs'], $params['concurrency'] ) as $pathBatch ) {
        foreach ( $pathBatch as $src ) {
            // TODO: remove this duplicate check, getFileHttpUrl() already checks this.
            list( $bucket, $key, ) = $this->getBucketAndObject( $src );
            if ( $bucket === null || $key === null ) {
                $fsFiles[$src] = null;
                continue;
            }

            $fsFiles[$src] = $this->getLocalCopyCached( $src );

            $this->logger->log(
                $fsFiles[$src] ? LogLevel::DEBUG : LogLevel::ERROR,
                'S3FileBackend: doGetLocalCopyMulti: {key} from S3 bucket ' .
                '{bucket} {result}: {dst}',
                [
                    'result' => $fsFiles[$src] ? 'is stored locally' : 'couldn\'t be copied to',
                    'key' => $key,
                    'bucket' => $bucket,
                    'dst' => $fsFiles[$src] ? $fsFiles[$src]->getPath() : null
                ]
            );
        }
    }
    return $fsFiles;
}

Hot to fix the problem? Thanks

edwardspec commented 3 years ago

Fixed. Thank you for noticing this.