From 180d226b3b476cef523e24dc8f2cc8bcefcc5733 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 22 Feb 2012 21:13:37 +0100 Subject: [PATCH] Added support for package icons --- com.woltlab.wcf/packageInstallationPlugin.xml | 1 + ...ageIconPackageInstallationPlugin.class.php | 54 +++++++++++++++++++ wcfsetup/setup/db/install.sql | 1 + 3 files changed, 56 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/package/plugin/PackageIconPackageInstallationPlugin.class.php diff --git a/com.woltlab.wcf/packageInstallationPlugin.xml b/com.woltlab.wcf/packageInstallationPlugin.xml index b91601ab9e..43c128328b 100644 --- a/com.woltlab.wcf/packageInstallationPlugin.xml +++ b/com.woltlab.wcf/packageInstallationPlugin.xml @@ -19,5 +19,6 @@ wcf\system\package\plugin\TemplatePackageInstallationPlugin wcf\system\package\plugin\UserGroupOptionPackageInstallationPlugin wcf\system\package\plugin\UserOptionPackageInstallationPlugin + wcf\system\package\plugin\PackageIconPackageInstallationPlugin diff --git a/wcfsetup/install/files/lib/system/package/plugin/PackageIconPackageInstallationPlugin.class.php b/wcfsetup/install/files/lib/system/package/plugin/PackageIconPackageInstallationPlugin.class.php new file mode 100644 index 0000000000..e29d51e992 --- /dev/null +++ b/wcfsetup/install/files/lib/system/package/plugin/PackageIconPackageInstallationPlugin.class.php @@ -0,0 +1,54 @@ + + * @package com.woltlab.wcf + * @subpackage system.package.plugin + * @category Community Framework + */ +class PackageIconPackageInstallationPlugin extends AbstractPackageInstallationPlugin { + /** + * @see wcf\system\package\plugin\IPackageInstallationPlugin::install() + */ + public function install() { + parent::install(); + + // search sql files in package archive + if (($fileIndex = $this->installation->getArchive()->getTar()->getIndexByFilename($this->instruction['value'])) === false) { + throw new SystemException("Package icon '".$this->instruction['value']."' not found."); + } + + // get extension + $extension = substr($this->instruction['value'], strrpos($this->instruction['value'], '.')); + + // extract image + $this->installation->getArchive()->getTar()->extract($fileIndex, WCF_DIR . 'icon/packages/' . $this->installation->getPackage()->packageID . $extension); + + // update package + $packageEditor = new PackageEditor($this->installation->getPackage()); + $packageEditor->update(array( + 'packageIcon' => 'icon/packages/' . $packageEditor->packageID . $extension + )); + } + + /** + * @see wcf\system\package\plugin\IPackageInstallationPlugin::uninstall() + */ + public function uninstall() { + // call uninstall event + EventHandler::getInstance()->fireAction($this, 'uninstall'); + + $packageIcon = $this->installation->getPackage()->packageIcon; + if (!empty($packageIcon)) { + @unlink(WCF_DIR . $packageIcon); + } + } +} diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 7077cbf018..e8394cafe2 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -294,6 +294,7 @@ CREATE TABLE wcf1_package ( isApplication TINYINT(1) NOT NULL DEFAULT 0, author VARCHAR(255) NOT NULL DEFAULT '', authorURL VARCHAR(255) NOT NULL DEFAULT '', + packageIcon VARCHAR(30) NOT NULL DEFAULT '', KEY package (package) ); -- 2.20.1