Skip to content

Commit

Permalink
Merge pull request #4360 from nextcloud/fix/template-errors
Browse files Browse the repository at this point in the history
Skip errors that may interrupt file creation
  • Loading branch information
juliusknorr authored Dec 30, 2024
2 parents 01fd95a + 6ba7ef1 commit e71d855
Show file tree
Hide file tree
Showing 3 changed files with 463 additions and 358 deletions.
10 changes: 8 additions & 2 deletions lib/Listener/FileCreatedFromTemplateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Files\Template\FileCreatedFromTemplateEvent;
use Psr\Log\LoggerInterface;

/** @template-implements IEventListener<Event|FileCreatedFromTemplateEvent> */
class FileCreatedFromTemplateListener implements IEventListener {
Expand All @@ -24,6 +25,7 @@ public function __construct(
private TemplateManager $templateManager,
private TemplateFieldService $templateFieldService,
private CapabilitiesService $capabilitiesService,
private LoggerInterface $logger,
) {
}

Expand Down Expand Up @@ -58,8 +60,12 @@ public function handle(Event $event): void {
}

if ($this->capabilitiesService->hasFormFilling()) {
$filledTemplate = $this->templateFieldService->fillFields($templateFile, $event->getTemplateFields());
$event->getTarget()->putContent($filledTemplate);
try {
$filledTemplate = $this->templateFieldService->fillFields($templateFile, $event->getTemplateFields());
$event->getTarget()->putContent($filledTemplate);
} catch (\Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
}
}

// Avoid having the mimetype of the source file set
Expand Down
11 changes: 9 additions & 2 deletions lib/Service/RemoteOptionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@

namespace OCA\Richdocuments\Service;

use OCP\IAppConfig;

class RemoteOptionsService {
public const REMOTE_TIMEOUT_DEFAULT = 5;

public static function getDefaultOptions(int $timeout = self::REMOTE_TIMEOUT_DEFAULT): array {
return [
$options = [
'timeout' => $timeout,
'nextcloud' => [
'allow_local_address' => true,
]
];
}

if (\OCP\Server::get(IAppConfig::class)->getValueString('richdocuments', 'disable_certificate_verification') === 'yes') {
$options['verify'] = false;
}

return $options;
}
}
Loading

0 comments on commit e71d855

Please sign in to comment.