| 1 | <?php |
| 2 | |
| 3 | namespace wcf\system\package\plugin; |
| 4 | |
| 5 | use wcf\system\event\EventHandler; |
| 6 | use wcf\system\package\PackageArchive; |
| 7 | use wcf\system\package\PackageInstallationDispatcher; |
| 8 | use wcf\system\WCF; |
| 9 | |
| 10 | /** |
| 11 | * Abstract implementation of a package installation plugin. |
| 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> |
| 16 | */ |
| 17 | abstract 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 | { |
| 115 | return null; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @inheritDoc |
| 120 | */ |
| 121 | public static function isValid(PackageArchive $packageArchive, $instruction) |
| 122 | { |
| 123 | return true; |
| 124 | } |
| 125 | } |