Index: branches/uploadwizard/phase3/includes/upload/SessionStash.php |
— | — | @@ -90,13 +90,15 @@ |
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | | - * Stash a file in a temp directory and record that we did this in the session, along with other parameters. |
| 94 | + * Stash a file in a temp directory and record that we did this in the session, along with other metadata. |
95 | 95 | * We store data in a flat key-val namespace because that's how UploadBase did it. This also means we have to |
96 | 96 | * ensure that the key-val pairs in $data do not overwrite other required fields. |
97 | 97 | * |
98 | 98 | * @param {String} $path: path to file you want stashed |
99 | | - * @param {Array} $data: optional, other data you want added to the session. Do not use 'mTempPath', 'mFileProps', 'mFileSize', or 'version' as keys here |
100 | | - * @param {String} $key: optional, unique key for this session. Used for directory hashing when storing, otherwise not important |
| 99 | + * @param {Array} $data: optional, other data you want associated with the file. Do not use 'mTempPath', 'mFileProps', 'mFileSize', or 'version' as keys here |
| 100 | + * @param {String} $key: optional, unique key for this file in this session. Used for directory hashing when storing, otherwise not important |
| 101 | + * @throws SessionStashBadPathException |
| 102 | + * @throws SessionStashFileException |
101 | 103 | * @return {null|SessionStashFile} file, or null on failure |
102 | 104 | */ |
103 | 105 | public function stashFile( $path, $data = array(), $key = null ) { |
— | — | @@ -112,9 +114,21 @@ |
113 | 115 | } |
114 | 116 | |
115 | 117 | // if not already in a temporary area, put it there |
116 | | - $status = $this->repo->storeTemp( basename($path), $path ); |
117 | | - if( !$status->isOK() ) { |
118 | | - return null; |
| 118 | + $status = $this->repo->storeTemp( basename( $path ), $path ); |
| 119 | + if( ! $status->isOK() ) { |
| 120 | + // It is a convention in MediaWiki to only return one error per API exception, even if multiple errors |
| 121 | + // are available. We use reset() to pick the "first" thing that was wrong, preferring errors to warnings. |
| 122 | + // This is a bit lame, as we may have more info in the $status and we're throwing it away, but to fix it means |
| 123 | + // redesigning API errors significantly. |
| 124 | + // $status->value just contains the virtual URL (if anything) which is probably useless to the caller |
| 125 | + $error = reset( $status->getErrorsArray() ); |
| 126 | + if ( ! count( $error ) ) { |
| 127 | + $error = reset( $status->getWarningsArray() ); |
| 128 | + if ( ! count( $error ) ) { |
| 129 | + $error = array( 'unknown', 'no error recorded' ); |
| 130 | + } |
| 131 | + } |
| 132 | + throw new SessionStashFileException( "error storing file in '$path': " . join( '; ', $error ) ); |
119 | 133 | } |
120 | 134 | $stashPath = $status->value; |
121 | 135 | |