You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$response->setViolation($this->t('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', ['@file' => $file->getClientOriginalName(), '@maxsize' => $maxUploadSize]));
154
-
$this->logger->error('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', ['@file' => $file->getFilename(), '@maxsize' => $maxUploadSize]);
159
+
$response->addViolation($this->t('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', [
160
+
'@file' => $file->getClientOriginalName(),
161
+
'@maxsize' => $maxUploadSize,
162
+
]));
155
163
return$response;
156
164
157
165
caseUPLOAD_ERR_PARTIAL:
158
166
caseUPLOAD_ERR_NO_FILE:
159
-
$response->setViolation($this->t('The file "@file" could not be saved because the upload did not complete.', ['@file' => $file->getClientOriginalName()]));
160
-
$this->logger->error('The file "@file" could not be saved because the upload did not complete.', ['@file' => $file->getFilename()]);
167
+
$response->addViolation($this->t('The file "@file" could not be saved because the upload did not complete.', [
168
+
'@file' => $file->getClientOriginalName(),
169
+
]));
161
170
return$response;
162
171
163
172
caseUPLOAD_ERR_OK:
164
173
// Final check that this is a valid upload, if it isn't, use the
165
174
// default error handler.
166
-
if (is_uploaded_file($file->getRealPath())) {
175
+
if ($file->isValid()) {
167
176
break;
168
177
}
169
178
170
179
default:
171
-
$response->setViolation($this->t('Unknown error while uploading the file "@file".', ['@file' => $file->getClientOriginalName()]));
172
-
$this->logger->error('Error while uploading the file "@file" with an error code "@code".', ['@file' => $file->getFilename(), '@code' => $file->getError()]);
180
+
$response->addViolation($this->t('Unknown error while uploading the file "@file".', ['@file' => $file->getClientOriginalName()]));
181
+
$this->logger->error('Error while uploading the file "@file" with an error code "@code".', [
182
+
'@file' => $file->getFilename(),
183
+
'@code' => $file->getError(),
184
+
]);
173
185
return$response;
174
186
}
175
187
188
+
if (empty($settings['uri_scheme']) || empty($settings['file_directory'])) {
189
+
thrownew \RuntimeException('uri_scheme or file_directory missing in settings');
if ($violations = file_validate($fileEntity, $this->getUploadValidators($settings))) {
208
-
$response->setViolations($violations);
227
+
$response->addViolations($violations);
209
228
return$response;
210
229
}
211
230
212
231
// Move uploaded files from PHP's upload_tmp_dir to Drupal's temporary
213
232
// directory. This overcomes open_basedir restrictions for future file
214
233
// operations.
215
234
if (!$this->fileSystem->moveUploadedFile($file->getRealPath(), $fileEntity->getFileUri())) {
216
-
$response->setViolation($this->t('Unknown error while uploading the file "@file".', ['@file' => $file->getClientOriginalName()]));
217
-
$this->logger->error('Unable to move file from "@file" to "@destination".', ['@file' => $file->getRealPath(), '@destination' => $fileEntity->getFileUri()]);
235
+
$response->addViolation($this->t('Unknown error while uploading the file "@file".', [
236
+
'@file' => $file->getClientOriginalName(),
237
+
]));
238
+
$this->logger->error('Unable to move file from "@file" to "@destination".', [
239
+
'@file' => $file->getRealPath(),
240
+
'@destination' => $fileEntity->getFileUri(),
241
+
]);
218
242
return$response;
219
243
}
220
244
221
245
// Adjust permissions.
222
246
if (!$this->fileSystem->chmod($fileEntity->getFileUri())) {
223
-
$response->setViolation($this->t('Unknown error while uploading the file "@file".', ['@file' => $file->getClientOriginalName()]));
247
+
$response->addViolation($this->t('Unknown error while uploading the file "@file".', ['@file' => $file->getClientOriginalName()]));
224
248
$this->logger->error('Unable to set file permission for file "@file".', ['@file' => $fileEntity->getFileUri()]);
0 commit comments