Skip to content

Commit

Permalink
Merge pull request #47863 from nextcloud/backport/47860/stable30
Browse files Browse the repository at this point in the history
[stable30] fix: Only write once to template instead of create/copy
  • Loading branch information
juliusknorr authored Sep 10, 2024
2 parents 5017d50 + a137eeb commit 33c9638
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/private/Files/Template/TemplateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,21 @@ public function createFromTemplate(string $filePath, string $templateId = '', st
throw new GenericFileException($this->l10n->t('Invalid path'));
}
$folder = $userFolder->get(dirname($filePath));
$targetFile = $folder->newFile(basename($filePath));
$template = null;
if ($templateType === 'user' && $templateId !== '') {
$template = $userFolder->get($templateId);
$template->copy($targetFile->getPath());
} else {
$matchingProvider = array_filter($this->getRegisteredProviders(), function (ICustomTemplateProvider $provider) use ($templateType) {
return $templateType === get_class($provider);
});
$provider = array_shift($matchingProvider);
if ($provider) {
$template = $provider->getCustomTemplate($templateId);
$template->copy($targetFile->getPath());
}
}

$targetFile = $folder->newFile(basename($filePath), ($template instanceof File ? $template->fopen('rb') : null));

$this->eventDispatcher->dispatchTyped(new FileCreatedFromTemplateEvent($template, $targetFile, $templateFields));
return $this->formatFile($userFolder->get($filePath));
} catch (\Exception $e) {
Expand Down

0 comments on commit 33c9638

Please sign in to comment.