From 91800d661a6815c3dee94fe341b6c3a039208bbd Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 20 Dec 2017 23:47:38 +0100 Subject: [PATCH] Update tpl-type page's template in a single method --- .../files/lib/data/page/PageAction.class.php | 5 +++-- .../files/lib/data/page/PageEditor.class.php | 14 ++++++++++++++ .../plugin/PagePackageInstallationPlugin.class.php | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/data/page/PageAction.class.php b/wcfsetup/install/files/lib/data/page/PageAction.class.php index 95f3ed6142..17be30f503 100644 --- a/wcfsetup/install/files/lib/data/page/PageAction.class.php +++ b/wcfsetup/install/files/lib/data/page/PageAction.class.php @@ -135,8 +135,9 @@ class PageAction extends AbstractDatabaseObjectAction implements ISearchAction, // save template if ($page->pageType == 'tpl') { if (!empty($this->parameters['content'])) { + $pageEditor = new PageEditor($page); foreach ($this->parameters['content'] as $languageID => $content) { - file_put_contents(WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl', $content['content']); + $pageEditor->updateTemplate($languageID ?: null, $content['content']); } } } @@ -232,7 +233,7 @@ class PageAction extends AbstractDatabaseObjectAction implements ISearchAction, // save template if ($page->pageType == 'tpl') { foreach ($this->parameters['content'] as $languageID => $content) { - file_put_contents(WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl', $content['content']); + $page->updateTemplate($languageID ?: null, $content['content']); } } diff --git a/wcfsetup/install/files/lib/data/page/PageEditor.class.php b/wcfsetup/install/files/lib/data/page/PageEditor.class.php index 7dfdd3f1b5..6fa0eb0f2d 100644 --- a/wcfsetup/install/files/lib/data/page/PageEditor.class.php +++ b/wcfsetup/install/files/lib/data/page/PageEditor.class.php @@ -29,6 +29,20 @@ class PageEditor extends DatabaseObjectEditor implements IEditableCachedObject { */ protected static $baseClass = Page::class; + /** + * Creates or updates the page's template file. + * + * @param integer $languageID language id or `null` + * @param string $content template content + */ + public function updateTemplate($languageID, $content) { + if ($this->pageType !== 'tpl') { + throw new \RuntimeException("Only tpl-type pages support template files."); + } + + file_put_contents(WCF_DIR . 'templates/' . $this->getTplName(($languageID ?: null)) . '.tpl', $content); + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php index c9aec69530..9025449f23 100644 --- a/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php +++ b/wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php @@ -336,7 +336,7 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin // generate template if page's type is 'tpl' $page = new Page($pageID); if ($page->pageType == 'tpl') { - file_put_contents(WCF_DIR . 'templates/' . $page->getTplName(($languageID ?: null)) . '.tpl', $content['content']); + (new PageEditor($page))->updateTemplate($languageID, $content['content']); } } } -- 2.20.1