Skip to content

Commit

Permalink
fix: Only write once to template instead of create/copy
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Knorr <jus@bitgrid.net>
  • Loading branch information
juliusknorr authored and backportbot[bot] committed Sep 10, 2024
1 parent bf35b27 commit a137eeb
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 a137eeb

Please sign in to comment.