Skip to content

Commit

Permalink
Cleanup template loading
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Oct 15, 2021
1 parent c00fb87 commit 4a10f4b
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions lib/TemplateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,16 @@ class TemplateManager {
'presentation' => 'pptx'
];

const EMPTY_TEMPLATE_ID_TYPE = [
-1 => 'document',
-2 => 'spreadsheet',
-3 => 'presentation',
];
const EMPTY_TEMPLATE_TYPE_ID = [
'document' => -1,
'spreadsheet' => -2,
'presentation' => -3,
];


/**
* Template manager
*
* @param string $appName
* @param string $userId
* @param IConfig $config
* @param Factory $appDataFactory
* @param IAppData $appData
* @param IURLGenerator $urlGenerator
* @param IRootFolder $rootFolder
* @param IL10N $l
* @throws \OCP\Files\NotPermittedException
*/
public function __construct($appName,
$userId,
Expand All @@ -131,12 +118,10 @@ public function __construct($appName,


$this->appData = $appData;
$this->createAppDataFolders();

$this->l = $l;
}

private function createAppDataFolders() {
private function ensureAppDataFolders() {
/*
* Init the appdata folder
* We need an actual folder for the fileid and previews.
Expand Down Expand Up @@ -207,7 +192,7 @@ private function filterTemplates($templates, $type = null) {
});
}

private function getEmpty($type = null) {
public function getEmpty($type = null) {
$folder = $this->getEmptyTemplateDir();

$templateFiles = $folder->getDirectoryListing();
Expand All @@ -234,6 +219,7 @@ private function getEmpty($type = null) {
* Remove empty_templates in appdata and recreate it from the apps templates
*/
public function updateEmptyTemplates() {
$this->ensureAppDataFolders();
try {
$folder = $this->getEmptyTemplateDir();
$folder->delete();
Expand Down Expand Up @@ -424,6 +410,7 @@ private function getUserTemplateDir() {
* @return Folder
*/
private function getSystemTemplateDir() {
$this->ensureAppDataFolders();
$path = 'appdata_' . $this->config->getSystemValue('instanceid', null) . '/richdocuments/templates';
return $this->rootFolder->get($path);
}
Expand All @@ -432,6 +419,7 @@ private function getSystemTemplateDir() {
* @return Folder
*/
private function getEmptyTemplateDir() {
$this->ensureAppDataFolders();
$path = 'appdata_' . $this->config->getSystemValue('instanceid', null) . '/richdocuments/empty_templates';
return $this->rootFolder->get($path);
}
Expand Down

0 comments on commit 4a10f4b

Please sign in to comment.