Added application package id for cms pages
authorMarcel Werk <burntime@woltlab.com>
Sun, 17 Apr 2016 15:21:48 +0000 (17:21 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 17 Apr 2016 15:21:53 +0000 (17:21 +0200)
wcfsetup/install/files/acp/templates/pageAdd.tpl
wcfsetup/install/files/acp/templates/pageList.tpl
wcfsetup/install/files/lib/acp/form/PageAddForm.class.php
wcfsetup/install/files/lib/acp/form/PageEditForm.class.php
wcfsetup/install/files/lib/acp/page/PageListPage.class.php
wcfsetup/install/files/lib/data/page/Page.class.php
wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php
wcfsetup/install/files/lib/system/package/plugin/PagePackageInstallationPlugin.class.php
wcfsetup/setup/db/install.sql

index 4d1b85d80fdbb8d57a63e4af4fc1ca7dd1eca410..d10e09554b685414b3e8224df9133813ea0ffc7a 100644 (file)
                        </dd>
                </dl>
                
-               <dl{if $errorField == 'packageID'} class="formError"{/if}>
-                       <dt><label for="packageID">{lang}wcf.acp.page.packageID{/lang}</label></dt>
+               <dl{if $errorField == 'applicationPackageID'} class="formError"{/if}>
+                       <dt><label for="applicationPackageID">{lang}wcf.acp.page.applicationPackageID{/lang}</label></dt>
                        <dd>
-                               <select name="packageID" id="packageID"{if $action == 'edit' && $page->originIsSystem} disabled="disabled"{/if}>
+                               <select name="applicationPackageID" id="applicationPackageID"{if $action == 'edit' && $page->originIsSystem} disabled="disabled"{/if}>
                                        {foreach from=$availableApplications item=availableApplication}
-                                               <option value="{@$availableApplication->packageID}"{if $availableApplication->packageID == $packageID} selected="selected"{/if}>{$availableApplication->getAbbreviation()}: {$availableApplication->domainName}{$availableApplication->domainPath}</option>
+                                               <option value="{@$availableApplication->packageID}"{if $availableApplication->packageID == $applicationPackageID} selected="selected"{/if}>{$availableApplication->getAbbreviation()}: {$availableApplication->domainName}{$availableApplication->domainPath}</option>
                                        {/foreach}
                                </select>
-                               {if $errorField == 'parentPageID'}
+                               {if $errorField == 'applicationPackageID'}
                                        <small class="innerError">
                                                {if $errorType == 'empty'}
                                                        {lang}wcf.global.form.error.empty{/lang}
                                                {else}
-                                                       {lang}wcf.acp.page.packageID.error.{@$errorType}{/lang}
+                                                       {lang}wcf.acp.page.applicationPackageID.error.{@$errorType}{/lang}
                                                {/if}
                                        </small>
                                {/if}
index 1972e72de7492eecfa9efd70f4b254835c6859b5..3b6c80afe4c6da01121c6570e26884f89113827e 100644 (file)
@@ -32,7 +32,7 @@
                        {if $name}{capture append=linkParameters}&name={@$name|rawurlencode}{/capture}{/if}
                        {if $title}{capture append=linkParameters}&title={@$title|rawurlencode}{/capture}{/if}
                        {if $content}{capture append=linkParameters}&content={@$content|rawurlencode}{/capture}{/if}
-                       {if $packageID}{capture append=linkParameters}&packageID={@$packageID}{/capture}{/if}
+                       {if $applicationPackageID}{capture append=linkParameters}&applicationPackageID={@$applicationPackageID}{/capture}{/if}
                        {if $pageType}{capture append=linkParameters}&pageType={@$pageType|rawurlencode}{/capture}{/if}
                        
                        {pages print=true assign=pagesLinks controller="PageList" link="pageNo=%d&sortField=$sortField&sortOrder=$sortOrder$linkParameters"}
                                <dt></dt>
                                <dd>
                                        <label class="selectDropdown">
-                                               <select name="packageID" id="packageID">
-                                                       <option value="0">{lang}wcf.acp.page.packageID{/lang}</option>
+                                               <select name="applicationPackageID" id="applicationPackageID">
+                                                       <option value="0">{lang}wcf.acp.page.applicationPackageID{/lang}</option>
                                                        {foreach from=$availableApplications item=availableApplication}
-                                                               <option value="{@$availableApplication->packageID}"{if $availableApplication->packageID == $packageID} selected="selected"{/if}>{$availableApplication->getAbbreviation()}: {$availableApplication->domainName}{$availableApplication->domainPath}</option>
+                                                               <option value="{@$availableApplication->packageID}"{if $availableApplication->packageID == $applicationPackageID} selected="selected"{/if}>{$availableApplication->getAbbreviation()}: {$availableApplication->domainName}{$availableApplication->domainPath}</option>
                                                        {/foreach}
                                                </select>
                                        </label>
index 36072c5da07ff3e8c78bcb5e4035a5d20d312130..28a195450077d3bdd1b98c61bb68ae114485699f 100644 (file)
@@ -75,10 +75,10 @@ class PageAddForm extends AbstractForm {
        public $isLandingPage = 0;
        
        /**
-        * package id of the page
+        * application id of the page
         * @var integer
         */
-       public $packageID = 1;
+       public $applicationPackageID = 1;
        
        /**
         * list of available applications
@@ -165,7 +165,7 @@ class PageAddForm extends AbstractForm {
                if (isset($_POST['name'])) $this->name = StringUtil::trim($_POST['name']);
                if (isset($_POST['isDisabled'])) $this->isDisabled = 1;
                if (isset($_POST['isLandingPage'])) $this->isLandingPage = 1;
-               if (isset($_POST['packageID'])) $this->packageID = intval($_POST['packageID']);
+               if (isset($_POST['applicationPackageID'])) $this->applicationPackageID = intval($_POST['applicationPackageID']);
                if (isset($_POST['controller'])) $this->controller = StringUtil::trim($_POST['controller']);
                
                if (isset($_POST['customURL']) && is_array($_POST['customURL'])) $this->customURL = ArrayUtil::trim($_POST['customURL']);
@@ -188,7 +188,7 @@ class PageAddForm extends AbstractForm {
                
                $this->validateParentPageID();
                
-               $this->validatePackageID();
+               $this->validateApplicationPackageID();
                
                $this->validateController();
                
@@ -233,9 +233,9 @@ class PageAddForm extends AbstractForm {
        /**
         * Validates package id.
         */
-       protected function validatePackageID() {
-               if (!isset($this->availableApplications[$this->packageID])) {
-                       throw new UserInputException('packageID', 'invalid');
+       protected function validateApplicationPackageID() {
+               if (!isset($this->availableApplications[$this->applicationPackageID])) {
+                       throw new UserInputException('applicationPackageID', 'invalid');
                }
        }
        
@@ -340,11 +340,12 @@ class PageAddForm extends AbstractForm {
                        'name' => $this->name,
                        'isDisabled' => ($this->isDisabled) ? 1 : 0,
                        'isLandingPage' => 0,
-                       'packageID' => ($this->packageID ?: null),
+                       'applicationPackageID' => $this->applicationPackageID,
                        'lastUpdateTime' => TIME_NOW,
                        'isMultilingual' => $this->isMultilingual,
                        'identifier' => '',
-                       'controller' => $this->controller
+                       'controller' => $this->controller,
+                       'packageID' => 1
                ]), 'content' => $content, 'boxToPage' => $this->getBoxToPage()]);
                
                /** @var Page $page */
@@ -368,7 +369,7 @@ class PageAddForm extends AbstractForm {
                
                // reset variables
                $this->parentPageID = $this->isDisabled = $this->isLandingPage = 0;
-               $this->packageID = 1;
+               $this->applicationPackageID = 1;
                $this->name = $this->controller = '';
                $this->pageType = 'text';
                $this->customURL = $this->title = $this->content = $this->metaDescription = $this->metaKeywords = [];
@@ -404,7 +405,7 @@ class PageAddForm extends AbstractForm {
                        'isDisabled' => $this->isDisabled,
                        'isLandingPage' => $this->isLandingPage,
                        'isMultilingual' => $this->isMultilingual,
-                       'packageID' => $this->packageID,
+                       'applicationPackageID' => $this->applicationPackageID,
                        'controller' => $this->controller,
                        'customURL' => $this->customURL,
                        'title' => $this->title,
index 78858b5916d9c0eb844572c4fe14ab0a2348b282..bca4e3ceee573364871858126b00d1bfc9f587f5 100644 (file)
@@ -59,7 +59,7 @@ class PageEditForm extends PageAddForm {
                $this->pageType = $this->page->pageType;
                if ($this->page->originIsSystem) {
                        $this->parentPageID = $this->page->parentPageID;
-                       $this->packageID = $this->page->packageID;
+                       $this->applicationPackageID = $this->page->applicationPackageID;
                        $this->controller = $this->page->controller;
                }
                
@@ -89,7 +89,7 @@ class PageEditForm extends PageAddForm {
                        'isDisabled' => ($this->isDisabled) ? 1 : 0,
                        'lastUpdateTime' => TIME_NOW,
                        'parentPageID' => ($this->parentPageID ?: null),
-                       'packageID' => $this->packageID
+                       'applicationPackageID' => $this->applicationPackageID
                );
                
                if ($this->pageType == 'system') {
@@ -145,7 +145,7 @@ class PageEditForm extends PageAddForm {
                        $this->name = $this->page->name;
                        $this->parentPageID = $this->page->parentPageID;
                        $this->pageType = $this->page->pageType;
-                       $this->packageID = $this->page->packageID;
+                       $this->applicationPackageID = $this->page->applicationPackageID;
                        $this->controller = $this->page->controller;
                        if ($this->page->controllerCustomURL) $this->customURL[0] = $this->page->controllerCustomURL;
                        if ($this->page->isLandingPage) $this->isLandingPage = 1;
@@ -176,7 +176,7 @@ class PageEditForm extends PageAddForm {
        }
        
        /**
-        * @see \wcf\page\IPage::assignVariables()
+        * @inheritDoc
         */
        public function assignVariables() {
                parent::assignVariables();
index 9f7d66b82302a41741a7241597421cd28d2bfa3e..f782a616cea1e0608dda1de39f6844675bf04aff 100644 (file)
@@ -61,10 +61,10 @@ class PageListPage extends SortablePage {
        public $content = '';
        
        /**
-        * package id of the page
+        * application id of the page
         * @var integer
         */
-       public $packageID = 0;
+       public $applicationPackageID = 0;
        
        /**
         * page type
@@ -87,7 +87,7 @@ class PageListPage extends SortablePage {
                if (!empty($_REQUEST['name'])) $this->name = StringUtil::trim($_REQUEST['name']);
                if (!empty($_REQUEST['title'])) $this->title = StringUtil::trim($_REQUEST['title']);
                if (!empty($_REQUEST['content'])) $this->content = StringUtil::trim($_REQUEST['content']);
-               if (isset($_REQUEST['packageID'])) $this->packageID = intval($_REQUEST['packageID']);
+               if (isset($_REQUEST['applicationPackageID'])) $this->applicationPackageID = intval($_REQUEST['applicationPackageID']);
                if (!empty($_REQUEST['pageType'])) $this->pageType = $_REQUEST['pageType'];
                
                // get available applications
@@ -111,8 +111,8 @@ class PageListPage extends SortablePage {
                if (!empty($this->content)) {
                        $this->objectList->getConditionBuilder()->add('page.pageID IN (SELECT pageID FROM wcf'.WCF_N.'_page_content WHERE content LIKE ?)', array('%'.$this->content.'%'));
                }
-               if (!empty($this->packageID)) {
-                       $this->objectList->getConditionBuilder()->add('page.packageID = ?', array($this->packageID));
+               if (!empty($this->applicationPackageID)) {
+                       $this->objectList->getConditionBuilder()->add('page.applicationPackageID = ?', array($this->applicationPackageID));
                }
                if ($this->pageType == 'static') {
                        $this->objectList->getConditionBuilder()->add('page.pageType IN (?, ?, ?)', array('text', 'html', 'tpl'));
@@ -132,7 +132,7 @@ class PageListPage extends SortablePage {
                        'name' => $this->name,
                        'title' => $this->title,
                        'content' => $this->content,
-                       'packageID' => $this->packageID,
+                       'applicationPackageID' => $this->applicationPackageID,
                        'pageType' => $this->pageType,
                        'availableApplications' => $this->availableApplications
                ));
index 92634afc7dd42dd0409d8388de912f233ce24501..20229c2c412ebdef441c025e9c29c971ab6c59a5 100644 (file)
@@ -24,11 +24,13 @@ use wcf\system\WCF;
  * @property-read      integer|null    $parentPageID
  * @property-read      string          $identifier
  * @property-read      string          $name
+ * @property-read      string          $pageType
  * @property-read      integer         $isDisabled
  * @property-read      integer         $isLandingPage
  * @property-read      integer         $isMultilingual
  * @property-read      integer         $originIsSystem
  * @property-read      integer         $packageID
+ * @property-read      integer         $applicationPackageID
  * @property-read      string          $controller
  * @property-read      string          $handler
  * @property-read      string          $controllerCustomURL
@@ -180,7 +182,7 @@ class Page extends DatabaseObject {
         * @return      \wcf\data\application\Application
         */
        public function getApplication() {
-               return ApplicationHandler::getInstance()->getApplicationByID($this->packageID);
+               return ApplicationHandler::getInstance()->getApplicationByID($this->applicationPackageID);
        }
        
        /**
index 0b66b41ba77452579fd1889a0729863c2f7f5682..a187f11089093d32bd2486685a624912cf705c53 100644 (file)
@@ -107,7 +107,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder {
                }
                
                // fetch pages with a controller and a custom url
-               $sql = "SELECT  controller, controllerCustomURL, packageID
+               $sql = "SELECT  controller, controllerCustomURL, applicationPackageID
                        FROM    wcf".WCF_N."_page
                        WHERE   controller <> ''
                                AND controllerCustomURL <> ''";
@@ -119,7 +119,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder {
                }
                
                // fetch content pages using the common page controller
-               $sql = "SELECT          page_content.customURL AS controllerCustomURL, page_content.pageID, page_content.languageID, page.packageID
+               $sql = "SELECT          page_content.customURL AS controllerCustomURL, page_content.pageID, page_content.languageID, page.applicationPackageID
                        FROM            wcf".WCF_N."_page_content page_content
                        LEFT JOIN       wcf".WCF_N."_page page
                        ON              (page.pageID = page_content.pageID)";
@@ -132,7 +132,7 @@ class RoutingCacheBuilder extends AbstractCacheBuilder {
                $abbreviations = [];
                foreach ($rows as $row) {
                        $customUrl = FileUtil::removeLeadingSlash(FileUtil::removeTrailingSlash($row['controllerCustomURL']));
-                       $packageID = $row['packageID'];
+                       $packageID = $row['applicationPackageID'];
                        if (!isset($abbreviations[$packageID])) {
                                $abbreviations[$packageID] = ApplicationHandler::getInstance()->getAbbreviation($packageID);
                        }
index 13d26ac66e81df346576496b6c778a65e08b1601..158d9a7cf63c72c6d38e9a77331abfd4a2f0d4d5 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace wcf\system\package\plugin;
+use wcf\data\package\Package;
+use wcf\data\package\PackageCache;
 use wcf\data\page\PageEditor;
 use wcf\system\exception\SystemException;
 use wcf\system\language\LanguageFactory;
@@ -184,6 +186,19 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                                break;
                }
                
+               // get application package id
+               $applicationPackageID = 1;
+               if ($this->installation->getPackage()->isApplication) {
+                       $applicationPackageID = $this->installation->getPackageID();
+               }
+               if (!empty($data['elements']['application'])) {
+                       $application = PackageCache::getInstance()->getPackageByIdentifier($data['elements']['application']);
+                       if ($application === null || !$application->isApplication) {
+                               throw new SystemException("Unknown application '".$data['elements']['application']."' for page '{$identifier}");
+                       }
+                       $applicationPackageID = $application->packageID;
+               }
+               
                return [
                        'pageType' => $pageType,
                        'content' => ($isStatic) ? $data['elements']['content'] : [],
@@ -196,6 +211,7 @@ class PagePackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin
                        'name' => $name,
                        'originIsSystem' => 1,
                        'parentPageID' => $parentPageID,
+                       'applicationPackageID' => $applicationPackageID,
                        'requireObjectID' => (!empty($data['elements']['requireObjectID'])) ? 1 : 0,
                        'options' => (isset($data['elements']['options'])) ? $data['elements']['options'] : '',
                        'permissions' => (isset($data['elements']['permissions'])) ? $data['elements']['permissions'] : ''
index e3fa182578a40743cd5085ab3a5d7cfb024fa7ad..1f31a49103eba5cc21ed14e050fec076eff7f1e9 100644 (file)
@@ -908,6 +908,7 @@ CREATE TABLE wcf1_page (
        isMultilingual TINYINT(1) NOT NULL DEFAULT 0,
        originIsSystem TINYINT(1) NOT NULL DEFAULT 0,
        packageID INT(10) NOT NULL,
+       applicationPackageID INT(10),
        controller VARCHAR(255) NOT NULL DEFAULT '',
        handler VARCHAR(255) NOT NULL DEFAULT '',
        controllerCustomURL VARCHAR(255) NOT NULL DEFAULT '',
@@ -1742,6 +1743,7 @@ ALTER TABLE wcf1_paid_subscription_transaction_log ADD FOREIGN KEY (paymentMetho
 
 ALTER TABLE wcf1_page ADD FOREIGN KEY (parentPageID) REFERENCES wcf1_page (pageID) ON DELETE SET NULL;
 ALTER TABLE wcf1_page ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE;
+ALTER TABLE wcf1_page ADD FOREIGN KEY (applicationPackageID) REFERENCES wcf1_package (packageID) ON DELETE SET NULL;
 
 ALTER TABLE wcf1_page_content ADD FOREIGN KEY (pageID) REFERENCES wcf1_page (pageID) ON DELETE CASCADE;
 ALTER TABLE wcf1_page_content ADD FOREIGN KEY (languageID) REFERENCES wcf1_language (languageID) ON DELETE CASCADE;