From 480508730bfa164b669e4247e0e2d46ff29bb92e Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 4 Mar 2012 17:40:40 +0100 Subject: [PATCH] Package requirements/dependencies: objects 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. --- .../files/acp/templates/packageView.tpl | 62 ++++++------ .../lib/acp/page/PackageViewPage.class.php | 38 +------- .../files/lib/data/package/Package.class.php | 94 ++++++++++++------- 3 files changed, 95 insertions(+), 99 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/packageView.tpl b/wcfsetup/install/files/acp/templates/packageView.tpl index c361334c56..beab616587 100644 --- a/wcfsetup/install/files/acp/templates/packageView.tpl +++ b/wcfsetup/install/files/acp/templates/packageView.tpl @@ -20,7 +20,9 @@ @@ -92,12 +94,16 @@ {/if} - {if $requiredPackages|count || $dependentPackages|count} + {if $package->getRequiredPackages()|count || $package->getDependentPackages()|count}
@@ -123,34 +129,34 @@ {content} - {foreach from=$requiredPackages item=requiredPackage} + {foreach from=$package->getRequiredPackages() item=requiredPackage} {if $__wcf->session->getPermission('admin.system.package.canUpdatePackage')} - + {else} {/if} - {if $__wcf->session->getPermission('admin.system.package.canUninstallPackage') && $requiredPackage.package != 'com.woltlab.wcf' && $requiredPackage.packageID != PACKAGE_ID} - + {if $__wcf->session->getPermission('admin.system.package.canUninstallPackage') && $requiredPackage->package != 'com.woltlab.wcf' && $requiredPackage->packageID != PACKAGE_ID} + {else} {/if} -

{@$requiredPackage.packageID}

+

{@$requiredPackage->packageID}

- {if $requiredPackage.isApplication} + {if $requiredPackage->isApplication} - {elseif $requiredPackage.parentPackageID} + {elseif $requiredPackage->parentPackageID} {else} {/if} -

{$requiredPackage.packageName}{if $requiredPackage.instanceNo > 1 && $requiredPackage.instanceName == ''} (#{#$requiredPackage.instanceNo}){/if}

- {if $requiredPackage.authorURL}

{$requiredPackage.author}{else}{$requiredPackage.author}

{/if} -

{$requiredPackage.packageVersion}

-

{@$requiredPackage.packageDate|date}

+

{$requiredPackage->packageName}{if $requiredPackage->instanceNo > 1 && $requiredPackage->instanceName == ''} (#{#$requiredPackage->instanceNo}){/if}

+ {if $requiredPackage->authorURL}

{$requiredPackage->author}{else}{$requiredPackage->author}

{/if} +

{$requiredPackage->packageVersion}

+

{@$requiredPackage->packageDate|date}

{event name='requirementColumns'} @@ -183,34 +189,34 @@ {content} - {foreach from=$dependentPackages item=dependentPackage} + {foreach from=$package->getDependentPackages() item=dependentPackage} {if $__wcf->session->getPermission('admin.system.package.canUpdatePackage')} - + {else} {/if} - {if $__wcf->session->getPermission('admin.system.package.canUninstallPackage') && $dependentPackage.package != 'com.woltlab.wcf' && $dependentPackage.packageID != PACKAGE_ID} - + {if $__wcf->session->getPermission('admin.system.package.canUninstallPackage') && $dependentPackage->package != 'com.woltlab.wcf' && $dependentPackage->packageID != PACKAGE_ID} + {else} {/if} -

{@$dependentPackage.packageID}

+

{@$dependentPackage->packageID}

- {if $dependentPackage.isApplication} + {if $dependentPackage->isApplication} - {elseif $dependentPackage.parentPackageID} + {elseif $dependentPackage->parentPackageID} {else} {/if} -

{$dependentPackage.packageName}{if $dependentPackage.instanceNo > 1 && $dependentPackage.instanceName == ''} (#{#$dependentPackage.instanceNo}){/if}

- {if $dependentPackage.authorURL}

{$dependentPackage.author}{else}{$dependentPackage.author}

{/if} -

{$dependentPackage.packageVersion}

-

{@$dependentPackage.packageDate|date}

+

{$dependentPackage->packageName}{if $dependentPackage->instanceNo > 1 && $dependentPackage->instanceName == ''} (#{#$dependentPackage->instanceNo}){/if}

+ {if $dependentPackage->authorURL}

{$dependentPackage->author}{else}{$dependentPackage->author}

{/if} +

{$dependentPackage->packageVersion}

+

{@$dependentPackage->packageDate|date}

{event name='dependencyColumns'} @@ -225,8 +231,8 @@
{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} diff --git a/wcfsetup/install/files/lib/acp/page/PackageViewPage.class.php b/wcfsetup/install/files/lib/acp/page/PackageViewPage.class.php index 02fc9186af..eb6da838e9 100755 --- a/wcfsetup/install/files/lib/acp/page/PackageViewPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/PackageViewPage.class.php @@ -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 - */ - public $requiredPackages = array(); - - /** - * list with data of dependent packages - * @var array - */ - public $dependentPackages = array(); - - /** - * list with data of required packages - * @var array - */ - 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); } /** diff --git a/wcfsetup/install/files/lib/data/package/Package.class.php b/wcfsetup/install/files/lib/data/package/Package.class.php index e47df20aa2..dd1ddb58b7 100644 --- a/wcfsetup/install/files/lib/data/package/Package.class.php +++ b/wcfsetup/install/files/lib/data/package/Package.class.php @@ -30,13 +30,30 @@ class Package extends DatabaseObject { */ protected static $databaseTableIndexName = 'packageID'; + /** + * list of packages that this package requires + * @var array + */ + protected $dependencies = null; + + /** + * list of packages that require this package + * @var array + */ + protected $dependentPackages = null; + /** * installation directory - * * @var string */ protected $dir = ''; + /** + * list of packages that were given as required packages during installation + * @var array + */ + 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; } /** -- 2.20.1