From: Marcel Werk Date: Thu, 25 Apr 2013 13:27:43 +0000 (+0200) Subject: Added template administration (WIP) X-Git-Tag: 2.0.0_Beta_1~298^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6570e38e96efa249c0dd4dffe90410790ae465e9;p=GitHub%2FWoltLab%2FWCF.git Added template administration (WIP) --- diff --git a/com.woltlab.wcf/acpMenu.xml b/com.woltlab.wcf/acpMenu.xml index e2b0691afe..255223befb 100644 --- a/com.woltlab.wcf/acpMenu.xml +++ b/com.woltlab.wcf/acpMenu.xml @@ -329,6 +329,32 @@ + + + wcf.acp.menu.link.display + + + + wcf.acp.menu.link.template + admin.template.canManageTemplate + + + + wcf.acp.menu.link.template + admin.template.canManageTemplate + + + + wcf.acp.menu.link.template + admin.template.canManageTemplate + + + + wcf.acp.menu.link.template + admin.template.canManageTemplate + + + wcf.acp.menu.link.display diff --git a/com.woltlab.wcf/userGroupOption.xml b/com.woltlab.wcf/userGroupOption.xml index faafa5c716..c40358e2bd 100644 --- a/com.woltlab.wcf/userGroupOption.xml +++ b/com.woltlab.wcf/userGroupOption.xml @@ -47,6 +47,9 @@ admin.display + + admin.display + admin @@ -205,28 +208,24 @@ boolean 0 1 - 1 + diff --git a/wcfsetup/install/files/acp/templates/languageItemList.tpl b/wcfsetup/install/files/acp/templates/languageItemList.tpl index 9a22112eae..7bbdbd2dac 100644 --- a/wcfsetup/install/files/acp/templates/languageItemList.tpl +++ b/wcfsetup/install/files/acp/templates/languageItemList.tpl @@ -84,7 +84,7 @@ {if $objects|count}
-
    +
      {foreach from=$objects item=item}
    1. diff --git a/wcfsetup/install/files/acp/templates/templateAdd.tpl b/wcfsetup/install/files/acp/templates/templateAdd.tpl new file mode 100644 index 0000000000..7cf910fd12 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/templateAdd.tpl @@ -0,0 +1,88 @@ +{include file='header'} + +
      +
      +

      {lang}wcf.acp.template.{$action}{/lang}

      +
      +
      + +{if $errorField} +

      {lang}wcf.global.form.error{/lang}

      +{/if} + +{if $success|isset} +

      {lang}wcf.global.success.{$action}{/lang}

      +{/if} + +
      + +
      + +{if $availableTemplateGroups|count} +
      +
      +
      + {lang}wcf.global.form.data{/lang} + +
      +
      +
      + +
      +
      + + +
      +
      + + {if $errorField == 'templateName'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.template.name.error.{@$errorType}{/lang} + {/if} + + {/if} +
      + + + {event name='dataFields'} +
      + + +
      + + +
      +
      +
      + +
      +
      +
      + + + {event name='fieldsets'} +
      + +
      + +
      +
      +{else} +

      {lang}wcf.acp.template.error.noGroups{/lang}

      +{/if} + + +{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/templateGroupAdd.tpl b/wcfsetup/install/files/acp/templates/templateGroupAdd.tpl new file mode 100644 index 0000000000..a4f1cea4d1 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/templateGroupAdd.tpl @@ -0,0 +1,91 @@ +{include file='header'} + +
      +
      +

      {lang}wcf.acp.template.group.{$action}{/lang}

      +
      +
      + +{if $errorField} +

      {lang}wcf.global.form.error{/lang}

      +{/if} + +{if $success|isset} +

      {lang}wcf.global.success.{$action}{/lang}

      +{/if} + +
      + +
      + +
      +
      +
      + {lang}wcf.global.form.data{/lang} + + {if $availableTemplateGroups|count} +
      +
      +
      + +
      +
      + {/if} + + +
      +
      + + {if $errorField == 'templateGroupName'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.template.group.name.error.{@$errorType}{/lang} + {/if} + + {/if} +
      + + + +
      +
      + + {if $errorField == 'templateGroupFolderName'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.template.group.name.error.{@$errorType}{/lang} + {/if} + + {/if} + {lang}wcf.acp.template.group.folderName.description{/lang} +
      + + + {event name='dataFields'} +
      + + {event name='fieldsets'} +
      + +
      + +
      +
      + + +{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/templateGroupList.tpl b/wcfsetup/install/files/acp/templates/templateGroupList.tpl new file mode 100644 index 0000000000..59144f2605 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/templateGroupList.tpl @@ -0,0 +1,84 @@ +{include file='header' pageTitle='wcf.acp.template.group.list'} + +
      +
      +

      {lang}wcf.acp.template.group.list{/lang}

      +
      + + +
      + +
      + {pages print=true assign=pagesLinks controller="TemplateGroupList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder"} + + +
      + +{if $objects|count} +
      +
      +

      {lang}wcf.acp.template.group.list{/lang} {#$items}

      +
      + + + + + + + + + + {event name='columnHeads'} + + + + + {foreach from=$objects item=templateGroup} + + + + + + + + {event name='columns'} + + {/foreach} + +
      {lang}wcf.global.objectID{/lang}{lang}wcf.global.name{/lang}{lang}wcf.acp.template.group.folderName{/lang}{lang}wcf.acp.template.group.templates{/lang}
      + + + + {event name='rowButtons'} + {@$templateGroup->templateGroupID}{$templateGroup->templateGroupName}{$templateGroup->templateGroupFolderName}{#$templateGroup->templates}
      + +
      + +
      + {@$pagesLinks} + + +
      +{else} +

      {lang}wcf.acp.template.group.noItems{/lang}

      +{/if} + +{include file='footer'} diff --git a/wcfsetup/install/files/acp/templates/templateList.tpl b/wcfsetup/install/files/acp/templates/templateList.tpl new file mode 100644 index 0000000000..914f2ff421 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/templateList.tpl @@ -0,0 +1,124 @@ +{include file='header' pageTitle="wcf.acp.template.list"} + + + +
      +
      +

      {lang}wcf.acp.template.list{/lang}

      +
      +
      + +
      +
      +
      + {lang}wcf.acp.template.list.filter{/lang} + +
      +
      +
      + +
      +
      + +
      +
      +
      + +
      +
      +
      +
      + +
      + +
      +
      + +
      + {assign var='linkParameters' value=''} + {if $templateGroupID}{capture append=linkParameters}&templateGroupID={@$templateGroupID}{/capture}{/if} + {if $searchTemplateName}{capture append=linkParameters}&searchTemplateName={@$searchTemplateName|rawurlencode}{/capture}{/if} + + {pages print=true assign=pagesLinks controller="TemplateList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder$linkParameters"} + + +
      + +{if $objects|count} +
      +
      +

      {lang}wcf.acp.template.list{/lang} {#$items}

      +
      + + + + + + + + + {event name='columnHeads'} + + + + + {foreach from=$objects item=template} + + + + + + + {event name='columns'} + + {/foreach} + +
      {lang}wcf.global.objectID{/lang}{lang}wcf.global.name{/lang}{lang}wcf.acp.template.lastModificationTime{/lang}
      + + + {if $template->templateGroupID} + + + {else} + + + {/if} + + {event name='rowButtons'} + {@$template->templateID}{if $template->templateGroupID}{$template->templateName}{else}{$template->templateName}{/if}{@$template->lastModificationTime|time}
      + +
      + +
      + {@$pagesLinks} + + +
      +{else} +

      {lang}wcf.acp.template.noItems{/lang}

      +{/if} + +{include file='footer'} diff --git a/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php b/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php new file mode 100644 index 0000000000..c89bfb1411 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/TemplateAddForm.class.php @@ -0,0 +1,198 @@ + + * @package com.woltlab.wcf + * @subpackage acp.form + * @category Community Framework + */ +class TemplateAddForm extends AbstractForm { + /** + * @see wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.template.add'; + + /** + * @see wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.template.canManageTemplate'); + + /** + * template name + * @var string + */ + public $tplName = ''; + + /** + * template group id + * @var integer + */ + public $templateGroupID = 0; + + /** + * template source code + * @var string + */ + public $templateSource = ''; + + /** + * available template groups + * @var array + */ + public $availableTemplateGroups = array(); + + /** + * template's package id + * @var integer + */ + public $packageID = PACKAGE_ID; + + /** + * @see wcf\form\IForm::readFormParameters() + */ + public function readFormParameters() { + parent::readFormParameters(); + + if (isset($_POST['tplName'])) $this->tplName = StringUtil::trim($_POST['tplName']); + if (isset($_POST['templateSource'])) $this->templateSource = $_POST['templateSource']; + if (isset($_POST['templateGroupID'])) $this->templateGroupID = intval($_POST['templateGroupID']); + + // get package id for this template + $sql = "SELECT packageID + FROM wcf".WCF_N."_template + WHERE templateName = ? + AND templateGroupID IS NULL"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($this->tplName)); + $row = $statement->fetchArray(); + if ($row !== false) { + $this->packageID = $row['packageID']; + } + } + + /** + * @see wcf\form\IForm::validate() + */ + public function validate() { + parent::validate(); + + $this->validateName(); + $this->validateGroup(); + } + + /** + * Validates the template name. + */ + protected function validateName() { + if (empty($this->tplName)) { + throw new UserInputException('tplName'); + } + + if (!preg_match('^/[a-z0-9_\-]+$/i', $this->tplName)) { + throw new UserInputException('tplName', 'notValid'); + } + + $sql = "SELECT COUNT(*) AS count + FROM wcf".WCF_N."_template + WHERE templateName = ? + AND packageID = ? + AND templateGroupID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + $this->tplName, + $this->packageID, + $this->templateGroupID + )); + $row = $statement->fetchArray(); + if ($row['count']) { + throw new UserInputException('tplName', 'notUnique'); + } + } + + /** + * Validates the selected template group. + */ + protected function validateGroup() { + if (!$this->templateGroupID) { + throw new UserInputException('templateGroupID'); + } + + $templateGroup = new TemplateGroup($this->templateGroupID); + if (!$templateGroup->templateGroupID) { + throw new UserInputException('templateGroupID'); + } + } + + /** + * @see wcf\form\IForm::save() + */ + public function save() { + parent::save(); + + $this->objectAction = new TemplateAction(array(), 'create', array('data' => array( + 'templateName' => $this->templateName, + 'packageID' => $this->packageID, + 'templateGroupID' => ($this->templateGroupID) + ), 'source' => $this->templateSource)); + $this->objectAction->executeAction(); + $this->saved(); + + // reset values + $this->templateName = $this->source = ''; + $this->templateGroupID = 0; + + // show success + WCF::getTPL()->assign(array( + 'success' => true + )); + } + + /** + * @see wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + $templateGroupList = new TemplateGroupList(); + $templateGroupList->readObjects(); + $this->availableTemplateGroups = $templateGroupList->getObjects(); + + if (!count($_POST)) { + if (!empty($_REQUEST['copy'])) { + $templateID = intval($_REQUEST['copy']); + $template = new Template($templateID); + $this->tplName = $template->templateName; + $this->templateSource = $template->getSource(); + } + } + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'action' => 'add', + 'tplName' => $this->tplName, + 'templateGroupID' => $this->templateGroupID, + 'templateSource' => $this->templateSource, + 'availableTemplateGroups' => $this->availableTemplateGroups + )); + } +} diff --git a/wcfsetup/install/files/lib/acp/form/TemplateGroupAddForm.class.php b/wcfsetup/install/files/lib/acp/form/TemplateGroupAddForm.class.php new file mode 100644 index 0000000000..b504e9f8ae --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/TemplateGroupAddForm.class.php @@ -0,0 +1,166 @@ + + * @package com.woltlab.wcf + * @subpackage acp.form + * @category Community Framework + */ +class TemplateGroupAddForm extends AbstractForm { + /** + * @see wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.template.group.add'; + + /** + * @see wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.template.canManageTemplate'); + + /** + * template group name + * @var string + */ + public $templateGroupName = ''; + + /** + * template group folder + * @var integer + */ + public $templateGroupFolderName = ''; + + /** + * parent template group id + * @var integer + */ + public $parentTemplateGroupID = 0; + + /** + * available template groups + * @var array + */ + public $availableTemplateGroups = array(); + + /** + * @see wcf\form\IForm::readFormParameters() + */ + public function readFormParameters() { + parent::readFormParameters(); + + if (isset($_POST['templateGroupName'])) $this->templateGroupName = StringUtil::trim($_POST['templateGroupName']); + if (isset($_POST['templateGroupFolderName'])) $this->templateGroupFolderName = StringUtil::trim($_POST['templateGroupFolderName']); + if (isset($_POST['parentTemplateGroupID'])) $this->parentTemplateGroupID = intval($_POST['parentTemplateGroupID']); + } + + /** + * @see wcf\form\IForm::validate() + */ + public function validate() { + parent::validate(); + + $this->validateName(); + $this->validateFolderName(); + } + + /** + * Validates the template group name. + */ + protected function validateName() { + if (empty($this->templateGroupName)) { + throw new UserInputException('templateGroupName'); + } + + $sql = "SELECT COUNT(*) AS count + FROM wcf".WCF_N."_template_group + WHERE templateGroupName = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($this->templateGroupName)); + $row = $statement->fetchArray(); + if ($row['count']) { + throw new UserInputException('templateGroupName', 'notUnique'); + } + } + + /** + * Validates the template group folder name. + */ + protected function validateFolderName() { + if (empty($this->templateGroupFolderName)) { + throw new UserInputException('templateGroupFolderName'); + } + + if ($this->templateGroupFolderName == '/') { + throw new UserInputException('templateGroupFolderName', 'notUnique'); + } + + $sql = "SELECT COUNT(*) AS count + FROM wcf".WCF_N."_template_group + WHERE templateGroupFolderName = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($this->templateGroupFolderName)); + $row = $statement->fetchArray(); + if ($row['count']) { + throw new UserInputException('templateGroupFolderName', 'notUnique'); + } + } + + /** + * @see wcf\form\IForm::save() + */ + public function save() { + parent::save(); + + $this->objectAction = new TemplateGroupAction(array(), 'create', array('data' => array( + 'templateGroupName' => $this->templateGroupName, + 'templateGroupFolderName' => $this->templateGroupFolderName, + 'parentTemplateGroupID' => ($this->parentTemplateGroupID ?: null) + ))); + $this->objectAction->executeAction(); + $this->saved(); + + // reset values + $this->templateGroupName = $this->templateGroupFolderName = ''; + + // show success + WCF::getTPL()->assign(array( + 'success' => true + )); + } + + /** + * @see wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + $templateGroupList = new TemplateGroupList(); + $templateGroupList->readObjects(); + $this->availableTemplateGroups = $templateGroupList->getObjects(); + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'action' => 'add', + 'templateGroupName' => $this->templateGroupName, + 'templateGroupFolderName' => $this->templateGroupFolderName, + 'parentTemplateGroupID' => $this->parentTemplateGroupID, + 'availableTemplateGroups' => $this->availableTemplateGroups + )); + } +} diff --git a/wcfsetup/install/files/lib/acp/form/TemplateGroupEditForm.class.php b/wcfsetup/install/files/lib/acp/form/TemplateGroupEditForm.class.php new file mode 100644 index 0000000000..009417f2b8 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/TemplateGroupEditForm.class.php @@ -0,0 +1,120 @@ + + * @package com.woltlab.wcf + * @subpackage acp.form + * @category Community Framework + */ +class TemplateGroupEditForm extends TemplateGroupAddForm { + /** + * @see wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.template'; + + /** + * template group id + * @var integer + */ + public $templateGroupID = 0; + + /** + * template group object + * @var wcf\data\template\group\TemplateGroup + */ + public $templateGroup = null; + + /** + * @see wcf\patge\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_REQUEST['id'])) $this->templateGroupID = intval($_REQUEST['id']); + $this->templateGroup = new TemplateGroup($this->templateGroupID); + if (!$this->templateGroup->templateGroupID) { + throw new IllegalLinkException(); + } + } + + /** + * @see wcf\acp\form\TemplateGroupAddForm::validateName() + */ + protected function validateName() { + if ($this->templateGroupName != $this->templateGroup->templateGroupName) { + parent::validateName(); + } + } + + /** + * @see wcf\acp\form\TemplateGroupAddForm::validateFolderName() + */ + protected function validateFolderName() { + if ($this->templateGroupFolderName != $this->templateGroup->templateGroupFolderName) { + parent::validateFolderName(); + } + } + + /** + * @see wcf\form\IForm::save() + */ + public function save() { + AbstractForm::save(); + + $this->objectAction = new TemplateGroupAction(array($this->templateGroup), 'update', array('data' => array( + 'templateGroupName' => $this->templateGroupName, + 'templateGroupFolderName' => $this->templateGroupFolderName, + 'parentTemplateGroupID' => ($this->parentTemplateGroupID ?: null) + ))); + $this->objectAction->executeAction(); + $this->saved(); + + // show success + WCF::getTPL()->assign(array( + 'success' => true + )); + } + + /** + * @see wcf\page\IPage::readData() + */ + public function readData() { + AbstractForm::readData(); + + $templateGroupList = new TemplateGroupList(); + $templateGroupList->getConditionBuilder()->add('templateGroupID <> ?', array($this->templateGroupID)); + $templateGroupList->readObjects(); + $this->availableTemplateGroups = $templateGroupList->getObjects(); + + // default values + if (!count($_POST)) { + $this->templateGroupName = $this->templateGroup->templateGroupName; + $this->templateGroupFolderName = $this->templateGroup->templateGroupFolderName; + $this->parentTemplateGroupID = $this->templateGroup->parentTemplateGroupID; + } + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'action' => 'edit', + 'templateGroupID' => $this->templateGroupID, + 'templateGroup' => $this->templateGroup + )); + } +} diff --git a/wcfsetup/install/files/lib/acp/page/TemplateGroupListPage.class.php b/wcfsetup/install/files/lib/acp/page/TemplateGroupListPage.class.php new file mode 100644 index 0000000000..ba1021b4a0 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/page/TemplateGroupListPage.class.php @@ -0,0 +1,49 @@ + + * @package com.woltlab.wcf + * @subpackage acp.page + * @category Community Framework + */ +class TemplateGroupListPage extends SortablePage { + /** + * @see wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.template.group.list'; + + /** + * @see wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.template.canManageTemplate'); + + /** + * @see wcf\page\SortablePage::$defaultSortField + */ + public $defaultSortField = 'templateGroupName'; + + /** + * @see wcf\page\MultipleLinkPage::$objectListClassName + */ + public $objectListClassName = 'wcf\data\template\group\TemplateGroupList'; + + /** + * @see wcf\page\SortablePage::$defaultSortField + */ + public $validSortFields = array('templateGroupID', 'templateGroupName', 'templateGroupFolderName', 'templates'); + + /** + * @see wcf\page\MultipleLinkPage::initObjectList + */ + protected function initObjectList() { + parent::initObjectList(); + + $this->objectList->sqlSelects = "(SELECT COUNT(*) FROM wcf".WCF_N."_template WHERE templateGroupID = template_group.templateGroupID) AS templates"; + } +} diff --git a/wcfsetup/install/files/lib/acp/page/TemplateListPage.class.php b/wcfsetup/install/files/lib/acp/page/TemplateListPage.class.php new file mode 100644 index 0000000000..e0147317c5 --- /dev/null +++ b/wcfsetup/install/files/lib/acp/page/TemplateListPage.class.php @@ -0,0 +1,113 @@ + + * @package com.woltlab.wcf + * @subpackage acp.page + * @category Community Framework + */ +class TemplateListPage extends SortablePage { + /** + * @see wcf\page\AbstractPage::$activeMenuItem + */ + public $activeMenuItem = 'wcf.acp.menu.link.template.list'; + + /** + * @see wcf\page\AbstractPage::$neededPermissions + */ + public $neededPermissions = array('admin.template.canManageTemplate'); + + /** + * @see wcf\page\MultipleLinkPage::$objectListClassName + */ + public $objectListClassName = 'wcf\data\template\TemplateList'; + + /** + * @see wcf\page\MultipleLinkPage::$itemsPerPage + */ + public $itemsPerPage = 100; + + /** + * @see wcf\page\SortablePage::$itemsPerPage + */ + public $defaultSortField = 'templateName'; + + /** + * @see wcf\page\SortablePage::$validSortFields + */ + public $validSortFields = array('templateID', 'templateName', 'lastModificationTime'); + + /** + * template group id + * @var integer + */ + public $templateGroupID = 0; + + /** + * template name + * @var string + */ + public $searchTemplateName = ''; + + /** + * available template groups + * @var array + */ + public $availableTemplateGroups = array(); + + /** + * @see wcf\page\IPage::readParameters() + */ + public function readParameters() { + parent::readParameters(); + + if (isset($_REQUEST['templateGroupID'])) $this->templateGroupID = intval($_REQUEST['templateGroupID']); + if (isset($_REQUEST['searchTemplateName'])) $this->searchTemplateName = StringUtil::trim($_REQUEST['searchTemplateName']); + } + + /** + * @see wcf\page\MultipleLinkPage::initObjectList() + */ + protected function initObjectList() { + parent::initObjectList(); + + if ($this->templateGroupID) $this->objectList->getConditionBuilder()->add('template.templateGroupID = ?', array($this->templateGroupID)); + else $this->objectList->getConditionBuilder()->add('template.templateGroupID IS NULL'); + + if ($this->searchTemplateName) $this->objectList->getConditionBuilder()->add('templateName LIKE ?', array($this->searchTemplateName.'%')); + } + + /** + * @see wcf\page\IPage::readData() + */ + public function readData() { + parent::readData(); + + // get template groups + $templateGroupList = new TemplateGroupList(); + $templateGroupList->readObjects(); + $this->availableTemplateGroups = $templateGroupList->getObjects(); + } + + /** + * @see wcf\page\IPage::assignVariables() + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign(array( + 'templateGroupID' => $this->templateGroupID, + 'searchTemplateName' => $this->searchTemplateName, + 'availableTemplateGroups' => $this->availableTemplateGroups + )); + } +} diff --git a/wcfsetup/install/files/lib/data/template/Template.class.php b/wcfsetup/install/files/lib/data/template/Template.class.php index 3491ef5015..13600a0f8b 100644 --- a/wcfsetup/install/files/lib/data/template/Template.class.php +++ b/wcfsetup/install/files/lib/data/template/Template.class.php @@ -32,13 +32,13 @@ class Template extends DatabaseObject { */ public function __construct($id, $row = null, DatabaseObject $object = null) { if ($id !== null) { - $sql = "SELECT template.*, group.templateGroupFolderName, package.packageDir + $sql = "SELECT template.*, template_group.templateGroupFolderName, package.packageDir FROM wcf".WCF_N."_template template - LEFT JOIN wcf".WCF_N."_template_group group - ON (group.templateGroupID = template.templateGroupID) + LEFT JOIN wcf".WCF_N."_template_group template_group + ON (template_group.templateGroupID = template.templateGroupID) LEFT JOIN wcf".WCF_N."_package package ON (package.packageID = template.packageID) - WHERE template.templateID = ?".$id; + WHERE template.templateID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($id)); $row = $statement->fetchArray(); diff --git a/wcfsetup/install/files/lib/data/template/TemplateAction.class.php b/wcfsetup/install/files/lib/data/template/TemplateAction.class.php index afbf1166df..94f5319d25 100644 --- a/wcfsetup/install/files/lib/data/template/TemplateAction.class.php +++ b/wcfsetup/install/files/lib/data/template/TemplateAction.class.php @@ -21,15 +21,15 @@ class TemplateAction extends AbstractDatabaseObjectAction { /** * @see wcf\data\AbstractDatabaseObjectAction::$permissionsCreate */ - protected $permissionsCreate = array('admin.template.canAddTemplate'); + protected $permissionsCreate = array('admin.template.canManageTemplate'); /** * @see wcf\data\AbstractDatabaseObjectAction::$permissionsDelete */ - protected $permissionsDelete = array('admin.template.canDeleteTemplate'); + protected $permissionsDelete = array('admin.template.canManageTemplate'); /** * @see wcf\data\AbstractDatabaseObjectAction::$permissionsUpdate */ - protected $permissionsUpdate = array('admin.template.canEditTemplate'); + protected $permissionsUpdate = array('admin.template.canManageTemplate'); } diff --git a/wcfsetup/install/files/lib/data/template/group/TemplateGroupAction.class.php b/wcfsetup/install/files/lib/data/template/group/TemplateGroupAction.class.php index d3cb6a85ab..51b6dc3688 100644 --- a/wcfsetup/install/files/lib/data/template/group/TemplateGroupAction.class.php +++ b/wcfsetup/install/files/lib/data/template/group/TemplateGroupAction.class.php @@ -21,15 +21,15 @@ class TemplateGroupAction extends AbstractDatabaseObjectAction { /** * @see wcf\data\AbstractDatabaseObjectAction::$permissionsCreate */ - protected $permissionsCreate = array('admin.template.canAddTemplateGroup'); + protected $permissionsCreate = array('admin.template.canManageTemplate'); /** * @see wcf\data\AbstractDatabaseObjectAction::$permissionsDelete */ - protected $permissionsDelete = array('admin.template.canDeleteTemplateGroup'); + protected $permissionsDelete = array('admin.template.canManageTemplate'); /** * @see wcf\data\AbstractDatabaseObjectAction::$permissionsUpdate */ - protected $permissionsUpdate = array('admin.template.canEditTemplateGroup'); + protected $permissionsUpdate = array('admin.template.canManageTemplate'); } diff --git a/wcfsetup/install/files/lib/data/template/group/TemplateGroupEditor.class.php b/wcfsetup/install/files/lib/data/template/group/TemplateGroupEditor.class.php index 99d1cf89d8..62c9f6c93e 100644 --- a/wcfsetup/install/files/lib/data/template/group/TemplateGroupEditor.class.php +++ b/wcfsetup/install/files/lib/data/template/group/TemplateGroupEditor.class.php @@ -1,21 +1,21 @@ * @package com.woltlab.wcf * @subpackage data.template.group * @category Community Framework */ -class TemplateGroupEditor extends DatabaseObjectEditor { +class TemplateGroupEditor extends DatabaseObjectEditor implements IEditableCachedObject { /** * @see wcf\data\DatabaseObjectDecorator::$baseClass */ @@ -28,67 +28,36 @@ class TemplateGroupEditor extends DatabaseObjectEditor { parent::update($parameters); if (isset($parameters['templateGroupFolderName']) && ($parameters['templateGroupFolderName'] != $this->templateGroupFolderName)) { - $this->renameFolders($parameters['templateGroupFolderName']); + @rename(WCF_DIR . 'templates/' . $this->templateGroupFolderName, WCF_DIR . 'templates/' . $parameters['templateGroupFolderName']); } } /** - * Renames the folders of this template group. - * - * @param string $newFolderName + * @see wcf\data\IEditableObject::deleteAll() */ - public function renameFolders($newFolderName) { - // default template dir - $folders = array(WCF_DIR . 'templates/' . $this->templateGroupFolderName => WCF_DIR . 'templates/' . $newFolderName); - - // get package dirs - $sql = "SELECT packageDir - FROM wcf".WCF_N."_package - WHERE packageDir <> ''"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(); - while ($row = $statement->fetchArray()) { - $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); - $folders[$packageDir . 'templates/' . $this->templateGroupFolderName] = $packageDir . 'templates/' . $newFolderName; + public static function deleteAll(array $objectIDs = array()) { + $list = new TemplateGroupList(); + $list->setObjectIDs($objectIDs); + $list->readObjects(); + foreach ($list as $object) { + $editor = new TemplateGroupEditor($object); + $editor->deleteFolder(); } - // rename folders - foreach ($folders as $oldName => $newName) { - if (file_exists($oldName)) { - @rename($oldName, $newName); - } - } + return parent::deleteAll($objectIDs); } /** - * @see wcf\data\IEditableObject::delete() + * Deletes the folder of this template group. */ - public function delete() { - // update children - $sql = "UPDATE wcf".WCF_N."_template_group - SET parentTemplateGroupID = ? - WHERE parentTemplateGroupID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($this->parentTemplateGroupID, $this->templateGroupID)); - - parent::delete(); - - $this->deleteFolders(); + public function deleteFolder() { + DirectoryUtil::getInstance(WCF_DIR . 'templates/' . $this->templateGroupFolderName)->removeAll(); } /** - * Deletes the folders of this template group. + * @see wcf\data\IEditableCachedObject::resetCache() */ - public function deleteFolders() { - // get package dirs - $sql = "SELECT packageDir - FROM wcf".WCF_N."_package - WHERE packageDir <> ''"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(); - while ($row = $statement->fetchArray()) { - $packageDir = FileUtil::getRealPath(WCF_DIR . $row['packageDir']); - DirectoryUtil::getInstance($packageDir . 'templates/' . $this->templateGroupFolderName)->deleteAll(); - } + public static function resetCache() { + TemplateGroupCacheBuilder::getInstance()->reset(); } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index b468d7830c..a198ed8eac 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -271,6 +271,11 @@ + + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index bfbc57261c..023aa42aee 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -271,6 +271,11 @@ + + + + + diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index f0c130ad72..0a0d3f9f90 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -585,7 +585,7 @@ CREATE TABLE wcf1_template ( packageID INT(10) NOT NULL, templateName VARCHAR(255) NOT NULL DEFAULT '', templateGroupID INT(10), - obsolete TINYINT(1) NOT NULL DEFAULT 0, + lastModificationTime INT(10) NOT NULL DEFAULT 0, KEY packageID (packageID, templateName), KEY templateGroupID (packageID, templateGroupID, templateName) ); @@ -593,7 +593,7 @@ CREATE TABLE wcf1_template ( DROP TABLE IF EXISTS wcf1_template_group; CREATE TABLE wcf1_template_group ( templateGroupID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, - parentTemplateGroupID INT(10) NOT NULL DEFAULT 0, + parentTemplateGroupID INT(10), templateGroupName VARCHAR(255) NOT NULL DEFAULT '', templateGroupFolderName VARCHAR(255) NOT NULL DEFAULT '' ); @@ -855,6 +855,8 @@ ALTER TABLE wcf1_style_variable_value ADD FOREIGN KEY (variableID) REFERENCES wc ALTER TABLE wcf1_template ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE; ALTER TABLE wcf1_template ADD FOREIGN KEY (templateGroupID) REFERENCES wcf1_template_group (templateGroupID) ON DELETE CASCADE; +ALTER TABLE wcf1_template_group ADD FOREIGN KEY (parentTemplateGroupID) REFERENCES wcf1_template_group (templateGroupID) ON DELETE SET NULL; + ALTER TABLE wcf1_template_listener ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE; ALTER TABLE wcf1_user_collapsible_content ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE;