Merge pull request #5987 from WoltLab/acp-dahsboard-box-hight
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / package / plugin / AbstractPackageInstallationPlugin.class.php
CommitLineData
11ade432 1<?php
a9229942 2
11ade432 3namespace wcf\system\package\plugin;
a9229942 4
11ade432 5use wcf\system\event\EventHandler;
870b0938 6use wcf\system\package\PackageArchive;
11ade432
AE
7use wcf\system\package\PackageInstallationDispatcher;
8use wcf\system\WCF;
9
10/**
a17de04e 11 * Abstract implementation of a package installation plugin.
a9229942
TD
12 *
13 * @author Alexander Ebert
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11ade432 16 */
a9229942
TD
17abstract class AbstractPackageInstallationPlugin implements IPackageInstallationPlugin
18{
19 /**
20 * table application prefix
21 * @var string
22 */
23 public $application = 'wcf';
24
25 /**
26 * database table name
27 * @var string
28 */
29 public $tableName = '';
30
31 /**
32 * active instance of PackageInstallationDispatcher
33 * @var PackageInstallationDispatcher
34 */
35 public $installation;
36
37 /**
38 * install/update instructions
39 * @var array
40 */
41 public $instruction = [];
42
43 /**
44 * Creates a new AbstractPackageInstallationPlugin object.
45 *
46 * @param PackageInstallationDispatcher $installation
47 * @param array $instruction
48 */
49 public function __construct(PackageInstallationDispatcher $installation, $instruction = [])
50 {
51 $this->installation = $installation;
52 $this->instruction = $instruction;
53
54 // call 'construct' event
55 EventHandler::getInstance()->fireAction($this, 'construct');
56 }
57
58 /**
59 * @inheritDoc
60 */
61 public function install()
62 {
63 // call 'install' event
64 EventHandler::getInstance()->fireAction($this, 'install');
65 }
66
67 /**
68 * @inheritDoc
69 */
70 public function update()
71 {
72 // call 'update' event
73 EventHandler::getInstance()->fireAction($this, 'update');
74
75 return $this->install();
76 }
77
78 /**
79 * @inheritDoc
80 */
81 public function hasUninstall()
82 {
83 // call 'hasUninstall' event
84 EventHandler::getInstance()->fireAction($this, 'hasUninstall');
85
86 $sql = "SELECT COUNT(*)
87 FROM " . $this->application . WCF_N . "_" . $this->tableName . "
88 WHERE packageID = ?";
89 $statement = WCF::getDB()->prepareStatement($sql);
90 $statement->execute([$this->installation->getPackageID()]);
91
92 return $statement->fetchSingleColumn() > 0;
93 }
94
95 /**
96 * @inheritDoc
97 */
98 public function uninstall()
99 {
100 // call 'uninstall' event
101 EventHandler::getInstance()->fireAction($this, 'uninstall');
102
103 $sql = "DELETE FROM " . $this->application . WCF_N . "_" . $this->tableName . "
104 WHERE packageID = ?";
105 $statement = WCF::getDB()->prepareStatement($sql);
106 $statement->execute([$this->installation->getPackageID()]);
107 }
108
109 /**
110 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::getDefaultFilename()
111 * @since 3.0
112 */
113 public static function getDefaultFilename()
114 {
5227ebc7 115 return null;
a9229942
TD
116 }
117
118 /**
119 * @inheritDoc
120 */
16600646 121 public static function isValid(PackageArchive $packageArchive, $instruction)
a9229942
TD
122 {
123 return true;
124 }
11ade432 125}