Commit | Line | Data |
---|---|---|
11ade432 AE |
1 | <?php |
2 | namespace wcf\system\package\plugin; | |
3 | use wcf\system\event\EventHandler; | |
870b0938 | 4 | use wcf\system\package\PackageArchive; |
11ade432 AE |
5 | use wcf\system\package\PackageInstallationDispatcher; |
6 | use wcf\system\WCF; | |
7 | ||
8 | /** | |
a17de04e | 9 | * Abstract implementation of a package installation plugin. |
11ade432 | 10 | * |
849f69b7 | 11 | * @author Alexander Ebert |
ca4ba303 | 12 | * @copyright 2001-2014 WoltLab GmbH |
11ade432 AE |
13 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
14 | * @package com.woltlab.wcf | |
15 | * @subpackage system.package.plugin | |
9f959ced | 16 | * @category Community Framework |
11ade432 | 17 | */ |
b522d4f1 | 18 | abstract class AbstractPackageInstallationPlugin implements IPackageInstallationPlugin { |
fbcb7171 AE |
19 | /** |
20 | * table application prefix | |
21 | * @var string | |
22 | */ | |
23 | public $application = 'wcf'; | |
24 | ||
11ade432 | 25 | /** |
88c45cf8 | 26 | * database table name |
8fd71145 | 27 | * @var string |
11ade432 AE |
28 | */ |
29 | public $tableName = ''; | |
30 | ||
31 | /** | |
8fd71145 | 32 | * active instance of PackageInstallationDispatcher |
0ad90fc3 | 33 | * @var \wcf\system\package\PackageInstallationDispatcher |
11ade432 AE |
34 | */ |
35 | public $installation = null; | |
36 | ||
37 | /** | |
38 | * install/update instructions | |
8fd71145 | 39 | * @var array |
11ade432 AE |
40 | */ |
41 | public $instruction = array(); | |
42 | ||
43 | /** | |
44 | * Creates a new AbstractPackageInstallationPlugin object. | |
45 | * | |
0ad90fc3 | 46 | * @param \wcf\system\package\PackageInstallationDispatcher $installation |
8fd71145 | 47 | * @param array $instruction |
11ade432 AE |
48 | */ |
49 | public function __construct(PackageInstallationDispatcher $installation, $instruction = array()) { | |
50 | $this->installation = $installation; | |
51 | $this->instruction = $instruction; | |
52 | ||
a17de04e | 53 | // call 'construct' event |
11ade432 AE |
54 | EventHandler::getInstance()->fireAction($this, 'construct'); |
55 | } | |
56 | ||
57 | /** | |
0ad90fc3 | 58 | * @see \wcf\system\package\plugin\IPackageInstallationPlugin::install() |
11ade432 AE |
59 | */ |
60 | public function install() { | |
a17de04e | 61 | // call 'install' event |
11ade432 AE |
62 | EventHandler::getInstance()->fireAction($this, 'install'); |
63 | } | |
64 | ||
65 | /** | |
0ad90fc3 | 66 | * @see \wcf\system\package\plugin\IPackageInstallationPlugin::update() |
11ade432 AE |
67 | */ |
68 | public function update() { | |
a17de04e | 69 | // call 'update' event |
11ade432 | 70 | EventHandler::getInstance()->fireAction($this, 'update'); |
a17de04e | 71 | |
11ade432 AE |
72 | return $this->install(); |
73 | } | |
74 | ||
75 | /** | |
0ad90fc3 | 76 | * @see \wcf\system\package\plugin\IPackageInstallationPlugin::hasUninstall() |
11ade432 AE |
77 | */ |
78 | public function hasUninstall() { | |
a17de04e | 79 | // call 'hasUninstall' event |
11ade432 AE |
80 | EventHandler::getInstance()->fireAction($this, 'hasUninstall'); |
81 | ||
82 | $sql = "SELECT COUNT(*) AS count | |
fbcb7171 | 83 | FROM ".$this->application.WCF_N."_".$this->tableName." |
11ade432 AE |
84 | WHERE packageID = ?"; |
85 | $statement = WCF::getDB()->prepareStatement($sql); | |
86 | $statement->execute(array($this->installation->getPackageID())); | |
87 | $installationCount = $statement->fetchArray(); | |
88 | return $installationCount['count']; | |
89 | } | |
90 | ||
91 | /** | |
0ad90fc3 | 92 | * @see \wcf\system\package\plugin\IPackageInstallationPlugin::uninstall() |
11ade432 AE |
93 | */ |
94 | public function uninstall() { | |
a17de04e | 95 | // call 'uninstall' event |
11ade432 AE |
96 | EventHandler::getInstance()->fireAction($this, 'uninstall'); |
97 | ||
fbcb7171 | 98 | $sql = "DELETE FROM ".$this->application.WCF_N."_".$this->tableName." |
11ade432 AE |
99 | WHERE packageID = ?"; |
100 | $statement = WCF::getDB()->prepareStatement($sql); | |
101 | $statement->execute(array($this->installation->getPackageID())); | |
102 | } | |
870b0938 AE |
103 | |
104 | /** | |
105 | * @see \wcf\system\package\plugin\IPackageInstallationPlugin::isValid() | |
106 | */ | |
107 | public static function isValid(PackageArchive $archive, $instruction) { | |
108 | return true; | |
109 | } | |
11ade432 | 110 | } |