Package requirements/dependencies: objects
authorMatthias Schmidt <gravatronics@live.com>
Sun, 4 Mar 2012 16:40:40 +0000 (17:40 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 4 Mar 2012 16:41:28 +0000 (17:41 +0100)
Package requirements and dependencies are now locally stored `wcf\data\package\Package` objects. This means, the the API of the relevant three methods changed since they return arrays containing `wcf\data\package\Package` objects instead of arrays with the package data but I couldn't find any place within the other public packages where these methods were used.

wcfsetup/install/files/acp/templates/packageView.tpl
wcfsetup/install/files/lib/acp/page/PackageViewPage.class.php
wcfsetup/install/files/lib/data/package/Package.class.php

index c361334c56ed1b1845f0246d77f80a6dff1fb50c..beab616587302ae8804f532fa72845ecff6ac689 100644 (file)
@@ -20,7 +20,9 @@
        <nav class="wcf-tabMenu">
                <ul>
                        <li><a href="#information">{lang}wcf.acp.package.information.title{/lang}</a></li>
-                       {if $requiredPackages|count || $dependentPackages|count}<li><a href="#dependencies">{lang}wcf.acp.package.dependencies.title{/lang}</a></li>{/if}
+                       {if $package->getRequiredPackages()|count || $package->getDependentPackages()|count}
+                               <li><a href="#dependencies">{lang}wcf.acp.package.dependencies.title{/lang}</a></li>
+                       {/if}
                </ul>
        </nav>
 
                {/if}
        </div>
 
-       {if $requiredPackages|count || $dependentPackages|count}
+       {if $package->getRequiredPackages()|count || $package->getDependentPackages()|count}
                <div id="dependencies" class="wcf-border wcf-tabMenuContainer wcf-tabMenuContent">
                        <nav class="wcf-menu">
                                <ul>
-                                       {if $requiredPackages|count}<li><a href="#dependencies-required">{lang}wcf.acp.package.dependencies.required{/lang}</a></li>{/if}
-                                       {if $dependentPackages|count}<li><a href="#dependencies-dependent">{lang}wcf.acp.package.dependencies.dependent{/lang}</a></li>{/if}
+                                       {if $package->getRequiredPackages()|count}
+                                               <li><a href="#dependencies-required">{lang}wcf.acp.package.dependencies.required{/lang}</a></li>
+                                       {/if}
+                                       {if $package->getDependentPackages()|count}
+                                               <li><a href="#dependencies-dependent">{lang}wcf.acp.package.dependencies.dependent{/lang}</a></li>
+                                       {/if}
                                </ul>
                        </nav>
 
                        
                                                <tbody>
                                                        {content}
-                                                               {foreach from=$requiredPackages item=requiredPackage}
+                                                               {foreach from=$package->getRequiredPackages() item=requiredPackage}
                                                                        <tr>
                                                                                <td class="columnIcon">
                                                                                        {if $__wcf->session->getPermission('admin.system.package.canUpdatePackage')}
-                                                                                               <a href="{link controller='PackageStartInstall' id=$requiredPackage.packageID}action=update{/link}"><img src="{@$__wcf->getPath()}icon/update1.svg" alt="" title="{lang}wcf.acp.package.button.update{/lang}" class="jsTooltip" /></a>
+                                                                                               <a href="{link controller='PackageStartInstall' id=$requiredPackage->packageID}action=update{/link}"><img src="{@$__wcf->getPath()}icon/update1.svg" alt="" title="{lang}wcf.acp.package.button.update{/lang}" class="jsTooltip" /></a>
                                                                                        {else}
                                                                                                <img src="{@$__wcf->getPath()}icon/update1D.svg" alt="" title="{lang}wcf.acp.package.button.update{/lang}" />
                                                                                        {/if}
-                                                                                       {if $__wcf->session->getPermission('admin.system.package.canUninstallPackage') && $requiredPackage.package != 'com.woltlab.wcf' && $requiredPackage.packageID != PACKAGE_ID}
-                                                                                               <a onclick="return confirm('{lang}wcf.acp.package.button.uninstall.sure{/lang}')" href="{link controller='Package'}action=startUninstall&packageID={@$requiredPackage.packageID}{/link}"><img src="{@$__wcf->getPath()}icon/delete1.svg" alt="" title="{lang}wcf.acp.package.button.uninstall{/lang}" class="jsTooltip" /></a>
+                                                                                       {if $__wcf->session->getPermission('admin.system.package.canUninstallPackage') && $requiredPackage->package != 'com.woltlab.wcf' && $requiredPackage->packageID != PACKAGE_ID}
+                                                                                               <a onclick="return confirm('{lang}wcf.acp.package.button.uninstall.sure{/lang}')" href="{link controller='Package'}action=startUninstall&packageID={@$requiredPackage->packageID}{/link}"><img src="{@$__wcf->getPath()}icon/delete1.svg" alt="" title="{lang}wcf.acp.package.button.uninstall{/lang}" class="jsTooltip" /></a>
                                                                                        {else}
                                                                                                <img src="{@$__wcf->getPath()}icon/delete1D.svg" alt="" title="{lang}wcf.acp.package.button.uninstall{/lang}" />
                                                                                        {/if}
                                                                                </td>
-                                                                               <td class="columnID"><p>{@$requiredPackage.packageID}</p></td>
+                                                                               <td class="columnID"><p>{@$requiredPackage->packageID}</p></td>
                                                                                <td class="columnIcon">
-                                                                                       {if $requiredPackage.isApplication}
+                                                                                       {if $requiredPackage->isApplication}
                                                                                                <img src="{@$__wcf->getPath()}icon/packageApplication1.svg" alt="" title="{lang}wcf.acp.package.type.application{/lang}" class="jsTooltip" />
-                                                                                       {elseif $requiredPackage.parentPackageID}
+                                                                                       {elseif $requiredPackage->parentPackageID}
                                                                                                <img src="{@$__wcf->getPath()}icon/packagePlugin1.svg" alt="" title="{lang}wcf.acp.package.type.plugin{/lang}" class="jsTooltip" />
                                                                                        {else}
                                                                                                <img src="{@$__wcf->getPath()}icon/package1.svg" alt="" title="{lang}wcf.acp.package.type.other{/lang}" class="jsTooltip" />
                                                                                        {/if}
                                                                                </td>
-                                                                               <td class="columnTitle" title="{$requiredPackage.packageDescription}"><p><a href="{link controller='PackageView' id=$requiredPackage.packageID}{/link}">{$requiredPackage.packageName}{if $requiredPackage.instanceNo > 1 && $requiredPackage.instanceName == ''} (#{#$requiredPackage.instanceNo}){/if}</a></p></td>
-                                                                               <td class="columnText">{if $requiredPackage.authorURL}<p><a href="{@$__wcf->getPath()}acp/dereferrer.php?url={$requiredPackage.authorURL|rawurlencode}" class="wcf-externalURL">{$requiredPackage.author}</a>{else}{$requiredPackage.author}</p>{/if}</td>
-                                                                               <td class="columnText"><p>{$requiredPackage.packageVersion}</p></td>
-                                                                               <td class="columnDate"><p>{@$requiredPackage.packageDate|date}</p></td>
+                                                                               <td class="columnTitle" title="{$requiredPackage->packageDescription}"><p><a href="{link controller='PackageView' id=$requiredPackage->packageID}{/link}">{$requiredPackage->packageName}{if $requiredPackage->instanceNo > 1 && $requiredPackage->instanceName == ''} (#{#$requiredPackage->instanceNo}){/if}</a></p></td>
+                                                                               <td class="columnText">{if $requiredPackage->authorURL}<p><a href="{@$__wcf->getPath()}acp/dereferrer.php?url={$requiredPackage->authorURL|rawurlencode}" class="wcf-externalURL">{$requiredPackage->author}</a>{else}{$requiredPackage->author}</p>{/if}</td>
+                                                                               <td class="columnText"><p>{$requiredPackage->packageVersion}</p></td>
+                                                                               <td class="columnDate"><p>{@$requiredPackage->packageDate|date}</p></td>
                                                                                
                                                                                {event name='requirementColumns'}
                                                                        </tr>
                        
                                                <tbody>
                                                        {content}
-                                                               {foreach from=$dependentPackages item=dependentPackage}
+                                                               {foreach from=$package->getDependentPackages() item=dependentPackage}
                                                                        <tr>
                                                                                <td class="columnIcon">
                                                                                        {if $__wcf->session->getPermission('admin.system.package.canUpdatePackage')}
-                                                                                               <a href="{link controller='PackageStartInstall' id=$dependentPackage.packageID}action=update{/link}"><img src="{@$__wcf->getPath()}icon/update1.svg" alt="" title="{lang}wcf.acp.package.button.update{/lang}" class="jsTooltip" /></a>
+                                                                                               <a href="{link controller='PackageStartInstall' id=$dependentPackage->packageID}action=update{/link}"><img src="{@$__wcf->getPath()}icon/update1.svg" alt="" title="{lang}wcf.acp.package.button.update{/lang}" class="jsTooltip" /></a>
                                                                                        {else}
                                                                                                <img src="{@$__wcf->getPath()}icon/update1D.svg" alt="" title="{lang}wcf.acp.package.button.update{/lang}" />
                                                                                        {/if}
-                                                                                       {if $__wcf->session->getPermission('admin.system.package.canUninstallPackage') && $dependentPackage.package != 'com.woltlab.wcf' && $dependentPackage.packageID != PACKAGE_ID}
-                                                                                               <a onclick="return confirm('{lang}wcf.acp.package.button.uninstall.sure{/lang}')" href="{link controller='Package'}action=startUninstall&packageID={@$dependentPackage.packageID}{/link}"><img src="{@$__wcf->getPath()}icon/delete1.svg" alt="" title="{lang}wcf.acp.package.button.uninstall{/lang}" class="jsTooltip" /></a>
+                                                                                       {if $__wcf->session->getPermission('admin.system.package.canUninstallPackage') && $dependentPackage->package != 'com.woltlab.wcf' && $dependentPackage->packageID != PACKAGE_ID}
+                                                                                               <a onclick="return confirm('{lang}wcf.acp.package.button.uninstall.sure{/lang}')" href="{link controller='Package'}action=startUninstall&packageID={@$dependentPackage->packageID}{/link}"><img src="{@$__wcf->getPath()}icon/delete1.svg" alt="" title="{lang}wcf.acp.package.button.uninstall{/lang}" class="jsTooltip" /></a>
                                                                                        {else}
                                                                                                <img src="{@$__wcf->getPath()}icon/delete1D.svg" alt="" title="{lang}wcf.acp.package.button.uninstall{/lang}" />
                                                                                        {/if}
                                                                                </td>
-                                                                               <td class="columnID"><p>{@$dependentPackage.packageID}</p></td>
+                                                                               <td class="columnID"><p>{@$dependentPackage->packageID}</p></td>
                                                                                <td class="columnIcon">
-                                                                                       {if $dependentPackage.isApplication}
+                                                                                       {if $dependentPackage->isApplication}
                                                                                                <img src="{@$__wcf->getPath()}icon/packageApplication1.svg" alt="" title="{lang}wcf.acp.package.type.application{/lang}" class="jsTooltip" />
-                                                                                       {elseif $dependentPackage.parentPackageID}
+                                                                                       {elseif $dependentPackage->parentPackageID}
                                                                                                <img src="{@$__wcf->getPath()}icon/packagePlugin1.svg" alt="" title="{lang}wcf.acp.package.type.plugin{/lang}" class="jsTooltip" />
                                                                                        {else}
                                                                                                <img src="{@$__wcf->getPath()}icon/package1.svg" alt="" title="{lang}wcf.acp.package.type.other{/lang}" class="jsTooltip" />
                                                                                        {/if}
                                                                                </td>
-                                                                               <td class="columnTitle" title="{$dependentPackage.packageDescription}"><p><a href="{link controller='PackageView' id=$dependentPackage.packageID}{/link}">{$dependentPackage.packageName}{if $dependentPackage.instanceNo > 1 && $dependentPackage.instanceName == ''} (#{#$dependentPackage.instanceNo}){/if}</a></p></td>
-                                                                               <td class="columnText">{if $dependentPackage.authorURL}<p><a href="{@$__wcf->getPath()}acp/dereferrer.php?url={$dependentPackage.authorURL|rawurlencode}" class="wcf-externalURL">{$dependentPackage.author}</a>{else}{$dependentPackage.author}</p>{/if}</td>
-                                                                               <td class="columnText"><p>{$dependentPackage.packageVersion}</p></td>
-                                                                               <td class="columnDate"><p>{@$dependentPackage.packageDate|date}</p></td>
+                                                                               <td class="columnTitle" title="{$dependentPackage->packageDescription}"><p><a href="{link controller='PackageView' id=$dependentPackage->packageID}{/link}">{$dependentPackage->packageName}{if $dependentPackage->instanceNo > 1 && $dependentPackage->instanceName == ''} (#{#$dependentPackage->instanceNo}){/if}</a></p></td>
+                                                                               <td class="columnText">{if $dependentPackage->authorURL}<p><a href="{@$__wcf->getPath()}acp/dereferrer.php?url={$dependentPackage->authorURL|rawurlencode}" class="wcf-externalURL">{$dependentPackage->author}</a>{else}{$dependentPackage->author}</p>{/if}</td>
+                                                                               <td class="columnText"><p>{$dependentPackage->packageVersion}</p></td>
+                                                                               <td class="columnDate"><p>{@$dependentPackage->packageDate|date}</p></td>
                                                                                
                                                                                {event name='dependencyColumns'}
                                                                        </tr>
 </div>
 
 {assign var=noDependentIsActive value=true}
-{foreach from=$dependentPackages item=dependentPackage}
-       {if $dependentPackage.package != 'com.woltlab.wcf' && $dependentPackage.packageID == PACKAGE_ID}
+{foreach from=$package->getDependentPackages() item=dependentPackage}
+       {if $dependentPackage->package != 'com.woltlab.wcf' && $dependentPackage->packageID == PACKAGE_ID}
                {assign var=noDependentIsActive value=false}
                {* TODO: maybe show users that this package can't be uninstalled because a dependent package is the active application *}
        {/if}
index 02fc9186af4785f3946e9892318700872fc4b96d..eb6da838e9a4b90b108d500f56b732a04100086e 100755 (executable)
@@ -27,25 +27,6 @@ class PackageViewPage extends AbstractPage {
         */
        public $neededPermissions = array('admin.system.package.canUpdatePackage', 'admin.system.package.canUninstallPackage');
        
-       /**
-        * list with data of required packages explicitly given in the requiredPackages
-        * tag during installation
-        * @var array<string>
-        */
-       public $requiredPackages = array();
-       
-       /**
-        * list with data of dependent packages
-        * @var array<string>
-        */
-       public $dependentPackages = array();
-       
-       /**
-        * list with data of required packages
-        * @var array<string>
-        */
-       public $dependencies = array();
-       
        /**
         * id of the package
         * @var integer
@@ -71,30 +52,13 @@ class PackageViewPage extends AbstractPage {
                }
        }
        
-       /**
-        * @see wcf\page\IPage::readData()
-        */
-       public function readData() {
-               parent::readData();
-               
-               // get package data
-               $this->requiredPackages = $this->package->getRequiredPackages();
-               $this->dependentPackages = $this->package->getDependentPackages();
-               $this->dependencies = $this->package->getDependencies();
-       }
-       
        /**
         * @see wcf\page\IPage::assignVariables()
         */
        public function assignVariables() {
                parent::assignVariables();
                
-               WCF::getTPL()->assign(array(
-                       'requiredPackages' => $this->requiredPackages,
-                       'dependentPackages' => $this->dependentPackages,
-                       'dependencies' => $this->dependencies,
-                       'package' => $this->package
-               ));
+               WCF::getTPL()->assign('package', $this->package);
        }
        
        /**
index e47df20aa2d35f56241371576bf13757301cdef7..dd1ddb58b7092a616f7770009aa877a31c8ae2b3 100644 (file)
@@ -30,13 +30,30 @@ class Package extends DatabaseObject {
         */
        protected static $databaseTableIndexName = 'packageID';
        
+       /**
+        * list of packages that this package requires
+        * @var array<wcf\data\package\Package>
+        */
+       protected $dependencies = null;
+       
+       /**
+        * list of packages that require this package
+        * @var array<wcf\data\package\Package>
+        */
+       protected $dependentPackages = null;
+       
        /**
         * installation directory
-        *
         * @var string
         */
        protected $dir = '';
        
+       /**
+        * list of packages that were given as required packages during installation
+        * @var array<wcf\data\package\Package>
+        */
+       protected $requiredPackages = null;
+       
        /**
         * Returns true, if this package is required by other packages.
         *
@@ -104,19 +121,22 @@ class Package extends DatabaseObject {
         * @return      array
         */
        public function getDependencies() {
-               $sql = "SELECT          package.*, CASE WHEN instanceName <> '' THEN instanceName ELSE packageName END AS packageName
-                       FROM            wcf".WCF_N."_package_dependency package_dependency
-                       LEFT JOIN       wcf".WCF_N."_package package ON (package.packageID = package_dependency.dependency)
-                       WHERE           package_dependency.packageID = ?
-                       ORDER BY        packageName ASC";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array($this->packageID));
-               $packages = array();
-               while ($row = $statement->fetchArray()) {
-                       $packages[] = $row;
+               if ($this->dependencies === null) {
+                       $this->dependencies = array();
+                       
+                       $sql = "SELECT          package.*, CASE WHEN instanceName <> '' THEN instanceName ELSE packageName END AS packageName
+                               FROM            wcf".WCF_N."_package_dependency package_dependency
+                               LEFT JOIN       wcf".WCF_N."_package package ON (package.packageID = package_dependency.dependency)
+                               WHERE           package_dependency.packageID = ?
+                               ORDER BY        packageName ASC";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array($this->packageID));
+                       while ($package = $statement->fetchObject('wcf\data\package\Package')) {
+                               $this->dependencies[$package->packageID] = $package;
+                       }
                }
                
-               return $packages;
+               return $this->dependencies;
        }
        
        /**
@@ -126,19 +146,22 @@ class Package extends DatabaseObject {
         * @return      array
         */
        public function getDependentPackages() {
-               $sql = "SELECT          package.*, CASE WHEN instanceName <> '' THEN instanceName ELSE packageName END AS packageName
-                       FROM            wcf".WCF_N."_package_requirement package_requirement
-                       LEFT JOIN       wcf".WCF_N."_package package ON (package.packageID = package_requirement.packageID)
-                       WHERE           package_requirement.requirement = ?
-                       ORDER BY        packageName ASC";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array($this->packageID));
-               $packages = array();
-               while ($row = $statement->fetchArray()) {
-                       $packages[] = $row;
+               if ($this->dependentPackages === null) {
+                       $this->dependentPackages = array();
+                       
+                       $sql = "SELECT          package.*, CASE WHEN instanceName <> '' THEN instanceName ELSE packageName END AS packageName
+                               FROM            wcf".WCF_N."_package_requirement package_requirement
+                               LEFT JOIN       wcf".WCF_N."_package package ON (package.packageID = package_requirement.packageID)
+                               WHERE           package_requirement.requirement = ?
+                               ORDER BY        packageName ASC";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array($this->packageID));
+                       while ($package = $statement->fetchObject('wcf\data\package\Package')) {
+                               $this->dependentPackages[$package->packageID] = $package;
+                       }
                }
                
-               return $packages;
+               return $this->dependentPackages;
        }
        
        /**
@@ -148,19 +171,22 @@ class Package extends DatabaseObject {
         * @return      array
         */
        public function getRequiredPackages() {
-               $sql = "SELECT          package.*, CASE WHEN instanceName <> '' THEN instanceName ELSE packageName END AS packageName
-                       FROM            wcf".WCF_N."_package_requirement package_requirement
-                       LEFT JOIN       wcf".WCF_N."_package package ON (package.packageID = package_requirement.requirement)
-                       WHERE           package_requirement.packageID = ?
-                       ORDER BY        packageName ASC";
-               $statement = WCF::getDB()->prepareStatement($sql);
-               $statement->execute(array($this->packageID));
-               $packages = array();
-               while ($row = $statement->fetchArray()) {
-                       $packages[] = $row;
+               if ($this->requiredPackages === null) {
+                       $this->requiredPackages = array();
+                       
+                       $sql = "SELECT          package.*, CASE WHEN instanceName <> '' THEN instanceName ELSE packageName END AS packageName
+                               FROM            wcf".WCF_N."_package_requirement package_requirement
+                               LEFT JOIN       wcf".WCF_N."_package package ON (package.packageID = package_requirement.requirement)
+                               WHERE           package_requirement.packageID = ?
+                               ORDER BY        packageName ASC";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute(array($this->packageID));
+                       while ($package = $statement->fetchObject('wcf\data\package\Package')) {
+                               $this->requiredPackages[$package->packageID] = $package;
+                       }
                }
                
-               return $packages;
+               return $this->requiredPackages;
        }
        
        /**