16
16
use Chamilo \UserBundle \Entity \User ;
17
17
use Doctrine \ORM \Query \Expr \Join ;
18
18
use Mpdf \MpdfException ;
19
+ use Symfony \Component \Filesystem \Exception \FileNotFoundException ;
19
20
use Symfony \Component \Filesystem \Filesystem ;
20
21
use Symfony \Component \HttpFoundation \Request as HttpRequest ;
21
22
@@ -2359,10 +2360,14 @@ public function exportZip(HttpRequest $httpRequest)
2359
2360
2360
2361
foreach ($ imagePaths as $ imagePath ) {
2361
2362
$ inlineFile = dirname ($ itemFilename ).'/ ' .basename ($ imagePath );
2362
- $ filenames [] = $ inlineFile ;
2363
- $ fs ->copy ($ imagePath , $ inlineFile );
2364
- }
2365
2363
2364
+ try {
2365
+ $ filenames [] = $ inlineFile ;
2366
+ $ fs ->copy ($ imagePath , $ inlineFile );
2367
+ } catch (FileNotFoundException $ notFoundException ) {
2368
+ continue ;
2369
+ }
2370
+ }
2366
2371
2367
2372
$ attachments = $ attachmentsRepo ->findFromItem ($ item );
2368
2373
@@ -2375,12 +2380,15 @@ public function exportZip(HttpRequest $httpRequest)
2375
2380
$ attachment ->getFilename ()
2376
2381
);
2377
2382
2378
- $ fs ->copy (
2379
- $ attachmentsDirectory .$ attachment ->getPath (),
2380
- $ attachmentFilename
2381
- );
2382
-
2383
- $ filenames [] = $ attachmentFilename ;
2383
+ try {
2384
+ $ fs ->copy (
2385
+ $ attachmentsDirectory .$ attachment ->getPath (),
2386
+ $ attachmentFilename
2387
+ );
2388
+ $ filenames [] = $ attachmentFilename ;
2389
+ } catch (FileNotFoundException $ notFoundException ) {
2390
+ continue ;
2391
+ }
2384
2392
}
2385
2393
2386
2394
$ tblItemsData [] = [
@@ -2415,8 +2423,13 @@ public function exportZip(HttpRequest $httpRequest)
2415
2423
2416
2424
foreach ($ imagePaths as $ imagePath ) {
2417
2425
$ inlineFile = dirname ($ commentFilename ).'/ ' .basename ($ imagePath );
2418
- $ filenames [] = $ inlineFile ;
2419
- $ fs ->copy ($ imagePath , $ inlineFile );
2426
+
2427
+ try {
2428
+ $ filenames [] = $ inlineFile ;
2429
+ $ fs ->copy ($ imagePath , $ inlineFile );
2430
+ } catch (FileNotFoundException $ notFoundException ) {
2431
+ continue ;
2432
+ }
2420
2433
}
2421
2434
2422
2435
$ attachments = $ attachmentsRepo ->findFromComment ($ comment );
@@ -2430,12 +2443,15 @@ public function exportZip(HttpRequest $httpRequest)
2430
2443
$ attachment ->getFilename ()
2431
2444
);
2432
2445
2433
- $ fs ->copy (
2434
- $ attachmentsDirectory .$ attachment ->getPath (),
2435
- $ attachmentFilename
2436
- );
2437
-
2438
- $ filenames [] = $ attachmentFilename ;
2446
+ try {
2447
+ $ fs ->copy (
2448
+ $ attachmentsDirectory .$ attachment ->getPath (),
2449
+ $ attachmentFilename
2450
+ );
2451
+ $ filenames [] = $ attachmentFilename ;
2452
+ } catch (FileNotFoundException $ notFoundException ) {
2453
+ continue ;
2454
+ }
2439
2455
}
2440
2456
2441
2457
$ tblCommentsData [] = [
@@ -4339,6 +4355,7 @@ private function fixMediaSourcesToHtml(string $htmlContent, array &$imagePaths):
4339
4355
continue ;
4340
4356
}
4341
4357
4358
+ // to search anchors linking to files
4342
4359
if ($ anchorElements ->length > 0 ) {
4343
4360
foreach ($ anchorElements as $ anchorElement ) {
4344
4361
if (!$ anchorElement ->hasAttribute ('href ' )) {
0 commit comments