Skip to content

Commit 405b142

Browse files
committed
Portfolio: Fix exporting to ZIP when files are not found - refs BT#22709
1 parent d0e1aff commit 405b142

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

main/inc/lib/PortfolioController.php

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Chamilo\UserBundle\Entity\User;
1717
use Doctrine\ORM\Query\Expr\Join;
1818
use Mpdf\MpdfException;
19+
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
1920
use Symfony\Component\Filesystem\Filesystem;
2021
use Symfony\Component\HttpFoundation\Request as HttpRequest;
2122

@@ -2359,10 +2360,14 @@ public function exportZip(HttpRequest $httpRequest)
23592360

23602361
foreach ($imagePaths as $imagePath) {
23612362
$inlineFile = dirname($itemFilename).'/'.basename($imagePath);
2362-
$filenames[] = $inlineFile;
2363-
$fs->copy($imagePath, $inlineFile);
2364-
}
23652363

2364+
try {
2365+
$filenames[] = $inlineFile;
2366+
$fs->copy($imagePath, $inlineFile);
2367+
} catch (FileNotFoundException $notFoundException) {
2368+
continue;
2369+
}
2370+
}
23662371

23672372
$attachments = $attachmentsRepo->findFromItem($item);
23682373

@@ -2375,12 +2380,15 @@ public function exportZip(HttpRequest $httpRequest)
23752380
$attachment->getFilename()
23762381
);
23772382

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+
}
23842392
}
23852393

23862394
$tblItemsData[] = [
@@ -2415,8 +2423,13 @@ public function exportZip(HttpRequest $httpRequest)
24152423

24162424
foreach ($imagePaths as $imagePath) {
24172425
$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+
}
24202433
}
24212434

24222435
$attachments = $attachmentsRepo->findFromComment($comment);
@@ -2430,12 +2443,15 @@ public function exportZip(HttpRequest $httpRequest)
24302443
$attachment->getFilename()
24312444
);
24322445

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+
}
24392455
}
24402456

24412457
$tblCommentsData[] = [
@@ -4339,6 +4355,7 @@ private function fixMediaSourcesToHtml(string $htmlContent, array &$imagePaths):
43394355
continue;
43404356
}
43414357

4358+
// to search anchors linking to files
43424359
if ($anchorElements->length > 0) {
43434360
foreach ($anchorElements as $anchorElement) {
43444361
if (!$anchorElement->hasAttribute('href')) {

0 commit comments

Comments
 (0)