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 committed Sep 10, 2024
1 parent 33ccc43 commit 4b333e1
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lib/private/Files/Template/TemplateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,19 @@ 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));
return $this->formatFile($userFolder->get($filePath));
} catch (\Exception $e) {
Expand Down

0 comments on commit 4b333e1

Please sign in to comment.