6fa72676e1d950c8d5b3ed81d33ca7072a7d129e
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\package\plugin;
3 use wcf\data\object\type\definition\ObjectTypeDefinitionEditor;
4 use wcf\system\devtools\pip\IIdempotentPackageInstallationPlugin;
5 use wcf\system\WCF;
6
7 /**
8 * Installs, updates and deletes object type definitions.
9 *
10 * @author Alexander Ebert
11 * @copyright 2001-2017 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\Acp\Package\Plugin
14 */
15 class ObjectTypeDefinitionPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin implements IIdempotentPackageInstallationPlugin {
16 /**
17 * @inheritDoc
18 */
19 public $className = ObjectTypeDefinitionEditor::class;
20
21 /**
22 * @inheritDoc
23 */
24 public $tagName = 'definition';
25
26 /**
27 * @inheritDoc
28 */
29 protected function handleDelete(array $items) {
30 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
31 WHERE definitionName = ?
32 AND packageID = ?";
33 $statement = WCF::getDB()->prepareStatement($sql);
34 foreach ($items as $item) {
35 $statement->execute([
36 $item['attributes']['name'],
37 $this->installation->getPackageID()
38 ]);
39 }
40 }
41
42 /**
43 * @inheritDoc
44 */
45 protected function prepareImport(array $data) {
46 return [
47 'interfaceName' => isset($data['elements']['interfacename']) ? $data['elements']['interfacename'] : '',
48 'definitionName' => $data['elements']['name'],
49 'categoryName' => isset($data['elements']['categoryname']) ? $data['elements']['categoryname'] : ''
50 ];
51 }
52
53 /**
54 * @inheritDoc
55 */
56 protected function findExistingItem(array $data) {
57 $sql = "SELECT *
58 FROM wcf".WCF_N."_".$this->tableName."
59 WHERE definitionName = ?";
60 $parameters = [$data['definitionName']];
61
62 return [
63 'sql' => $sql,
64 'parameters' => $parameters
65 ];
66 }
67 }