2 namespace wcf\system\package\plugin
;
3 use wcf\data\style\StyleEditor
;
4 use wcf\data\style\StyleList
;
5 use wcf\system\event\EventHandler
;
6 use wcf\system\style\StyleHandler
;
9 * Installs, updates and deletes styles.
12 * @copyright 2001-2019 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\System\Package\Plugin
16 class StylePackageInstallationPlugin
extends AbstractPackageInstallationPlugin
{
20 public $className = StyleEditor
::class;
25 public function install() {
29 $filename = $this->installation
->getArchive()->extractTar($this->instruction
['value'], 'style_');
31 // searches for non-tainted style for updating
32 $styleEditor = StyleHandler
::getInstance()->getStyleByName($this->installation
->getPackageName(), false);
35 $style = StyleEditor
::import($filename, $this->installation
->getPackageID(), $styleEditor, !PACKAGE_ID
);
37 // set style as default
38 if (isset($this->instruction
['attributes']['default'])) {
39 $style->setAsDefault();
49 public function uninstall() {
50 // call uninstall event
51 EventHandler
::getInstance()->fireAction($this, 'uninstall');
53 // get all style of this package
55 $styleList = new StyleList();
56 $styleList->getConditionBuilder()->add("packageID = ?", [$this->installation
->getPackageID()]);
57 $styleList->readObjects();
59 foreach ($styleList->getObjects() as $style) {
60 $styleEditor = new StyleEditor($style);
61 $styleEditor->delete();
63 $isDefault = $isDefault ||
$style->isDefault
;
66 // default style deleted
68 $styleList = new StyleList();
69 $styleList->sqlOrderBy
= 'style.styleID ASC';
70 $styleList->sqlLimit
= 1;
71 $styleList->readObjects();
72 $style = $styleList->getSingleObject();
74 if ($style !== null) {
75 (new StyleEditor($style))->setAsDefault();