From c4575796546e8936c87b6824b8c9d5a5898ca254 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 6 Nov 2012 21:50:54 +0100 Subject: [PATCH] Added option to set default application within a group --- .../acp/templates/applicationGroupAdd.tpl | 2 ++ .../acp/templates/applicationManagement.tpl | 12 +++++++++- .../form/ApplicationGroupAddForm.class.php | 23 +++++++++++++++++-- .../form/ApplicationGroupEditForm.class.php | 10 +++++++- .../application/ApplicationAction.class.php | 9 ++++++-- .../group/ApplicationGroupAction.class.php | 16 ++++++++----- .../install/files/lib/system/WCF.class.php | 6 +++-- wcfsetup/install/lang/de.xml | 1 + 8 files changed, 65 insertions(+), 14 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/applicationGroupAdd.tpl b/wcfsetup/install/files/acp/templates/applicationGroupAdd.tpl index 5554d8c87e..d9b5a5b097 100644 --- a/wcfsetup/install/files/acp/templates/applicationGroupAdd.tpl +++ b/wcfsetup/install/files/acp/templates/applicationGroupAdd.tpl @@ -65,6 +65,7 @@ {lang}wcf.global.objectID{/lang} + {lang}wcf.acp.application.primaryApplication{/lang} {lang}wcf.acp.package.name{/lang} {lang}wcf.acp.application.domainName{/lang} {lang}wcf.acp.application.domainPath{/lang} @@ -81,6 +82,7 @@ packageID|in_array:$applications} checked="checked"{/if} /> {#$application->packageID} + packageID} checked="checked"{/if} /> {lang}{$application->getPackage()->getName()}{/lang} {$application->domainName} {$application->domainPath} diff --git a/wcfsetup/install/files/acp/templates/applicationManagement.tpl b/wcfsetup/install/files/acp/templates/applicationManagement.tpl index c9b91a755b..639821f0a8 100644 --- a/wcfsetup/install/files/acp/templates/applicationManagement.tpl +++ b/wcfsetup/install/files/acp/templates/applicationManagement.tpl @@ -39,7 +39,17 @@ {#$application->packageID} - {lang}{$application->getPackage()->getName()}{/lang} + + {lang}{$application->getPackage()->getName()}{/lang} + + {if $application->isPrimary} + + {/if} + {$application->domainName} {$application->domainPath} {$application->cookieDomain} diff --git a/wcfsetup/install/files/lib/acp/form/ApplicationGroupAddForm.class.php b/wcfsetup/install/files/lib/acp/form/ApplicationGroupAddForm.class.php index aed21ff54d..58c395aef8 100644 --- a/wcfsetup/install/files/lib/acp/form/ApplicationGroupAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/ApplicationGroupAddForm.class.php @@ -46,6 +46,12 @@ class ApplicationGroupAddForm extends ACPForm { */ public $neededPermissions = array('admin.system.canManageApplication'); + /** + * primary application's package id + * @var integer + */ + public $primaryApplication = 0; + /** * @see wcf\page\IPage::readParameters() */ @@ -75,6 +81,7 @@ class ApplicationGroupAddForm extends ACPForm { if (isset($_POST['applications']) && is_array($_POST['applications'])) $this->applications = ArrayUtil::toIntegerArray($_POST['applications']); if (isset($_POST['groupName'])) $this->groupName = StringUtil::trim($_POST['groupName']); + if (isset($_POST['primaryApplication'])) $this->primaryApplication = intval($_POST['primaryApplication']); } /** @@ -115,6 +122,15 @@ class ApplicationGroupAddForm extends ACPForm { $packages[] = $application->getPackage()->package; } } + + if ($this->primaryApplication == 0) { + throw new UserInputException('applications', 'primaryApplication.empty'); + } + else { + if (!in_array($this->primaryApplication, $this->applications)) { + throw new UserInputException('applications', 'primaryApplication.notValid'); + } + } } /** @@ -149,7 +165,8 @@ class ApplicationGroupAddForm extends ACPForm { 'applications' => $this->applications, 'data' => array( 'groupName' => $this->groupName - ) + ), + 'primaryApplication' => $this->primaryApplication )); $this->objectAction->executeAction(); $this->saved(); @@ -157,6 +174,7 @@ class ApplicationGroupAddForm extends ACPForm { // reset values $this->applications = array(); $this->groupName = ''; + $this->primaryApplication = 0; // reload available applications $this->readAvailableApplications(); @@ -177,7 +195,8 @@ class ApplicationGroupAddForm extends ACPForm { 'action' => 'add', 'applications' => $this->applications, 'availableApplications' => $this->availableApplications, - 'groupName' => $this->groupName + 'groupName' => $this->groupName, + 'primaryApplication' => $this->primaryApplication, )); } } diff --git a/wcfsetup/install/files/lib/acp/form/ApplicationGroupEditForm.class.php b/wcfsetup/install/files/lib/acp/form/ApplicationGroupEditForm.class.php index 0baa76619f..6eac299545 100644 --- a/wcfsetup/install/files/lib/acp/form/ApplicationGroupEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/ApplicationGroupEditForm.class.php @@ -93,6 +93,13 @@ class ApplicationGroupEditForm extends ApplicationGroupAddForm { if (empty($_POST)) { $this->groupName = $this->applicationGroup->groupName; + + foreach ($this->availableApplications as $application) { + if ($application->isPrimary) { + $this->primaryApplication = $application->packageID; + break; + } + } } } @@ -107,7 +114,8 @@ class ApplicationGroupEditForm extends ApplicationGroupAddForm { 'applications' => $this->applications, 'data' => array( 'groupName' => $this->groupName - ) + ), + 'primaryApplication' => $this->primaryApplication )); $this->objectAction->executeAction(); $this->saved(); diff --git a/wcfsetup/install/files/lib/data/application/ApplicationAction.class.php b/wcfsetup/install/files/lib/data/application/ApplicationAction.class.php index 7a16d1880b..8e4f888188 100644 --- a/wcfsetup/install/files/lib/data/application/ApplicationAction.class.php +++ b/wcfsetup/install/files/lib/data/application/ApplicationAction.class.php @@ -34,7 +34,8 @@ class ApplicationAction extends AbstractDatabaseObjectAction { $sql = "UPDATE wcf".WCF_N."_application SET groupID = ?, cookieDomain = ?, - cookiePath = ? + cookiePath = ?, + isPrimary = ? WHERE packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); @@ -75,10 +76,13 @@ class ApplicationAction extends AbstractDatabaseObjectAction { $path = FileUtil::addLeadingSlash(FileUtil::addTrailingSlash(implode('/', $path))); foreach (array_keys($data) as $packageID) { + $isPrimary = ($this->parameters['primaryApplication'] == $packageID) ? 1 : 0; + $statement->execute(array( $this->parameters['groupID'], $domainName, $path, + $isPrimary, $packageID )); } @@ -99,7 +103,8 @@ class ApplicationAction extends AbstractDatabaseObjectAction { $sql = "UPDATE wcf".WCF_N."_application SET groupID = ?, cookieDomain = domainName, - cookiePath = domainPath + cookiePath = domainPath, + isPrimary = 0 WHERE packageID = ?"; $statement = WCF::getDB()->prepareStatement($sql); diff --git a/wcfsetup/install/files/lib/data/application/group/ApplicationGroupAction.class.php b/wcfsetup/install/files/lib/data/application/group/ApplicationGroupAction.class.php index c57de1a275..e724384488 100644 --- a/wcfsetup/install/files/lib/data/application/group/ApplicationGroupAction.class.php +++ b/wcfsetup/install/files/lib/data/application/group/ApplicationGroupAction.class.php @@ -33,10 +33,11 @@ class ApplicationGroupAction extends AbstractDatabaseObjectAction { public function create() { $applicationGroup = parent::create(); - if (isset($this->parameters['applications'])) { - $applicationAction = new ApplicationAction($this->parameters['applications'], 'group', array('groupID' => $applicationGroup->groupID)); - $applicationAction->executeAction(); - } + $applicationAction = new ApplicationAction($this->parameters['applications'], 'group', array( + 'groupID' => $applicationGroup->groupID, + 'primaryApplication' => $this->parameters['primaryApplication'] + )); + $applicationAction->executeAction(); return $applicationGroup; } @@ -48,7 +49,7 @@ class ApplicationGroupAction extends AbstractDatabaseObjectAction { parent::update(); // read list of currently associated applications - $applicationGroup = current($this->objects); + $applicationGroup = current(reset($this->objects)); $applicationList = new ApplicationList(); $applicationList->getConditionBuilder()->add("application.groupID = ?", array($applicationGroup->groupID)); $applicationList->sqlLimit = 0; @@ -76,7 +77,10 @@ class ApplicationGroupAction extends AbstractDatabaseObjectAction { } // rebuild current group - $applicationAction = new ApplicationAction($updateApplications, 'group', array('groupID' => $applicationGroup->groupID)); + $applicationAction = new ApplicationAction($updateApplications, 'group', array( + 'groupID' => $applicationGroup->groupID, + 'primaryApplication' => $this->parameters['primaryApplication'] + )); $applicationAction->executeAction(); // remove applications from group diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 14dd4f2424..e100988299 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -425,8 +425,10 @@ class WCF { } // step 2) run each application - foreach ($loadedApplications as $application) { - $application->__run(); + if (!class_exists('wcf\system\WCFACP', false)) { + foreach ($loadedApplications as $application) { + $application->__run(); + } } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 5826c3a18e..6bd7fccee1 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -36,6 +36,7 @@ groupName}“]]> + -- 2.20.1