37592e27dbfdcb538f30d51aabfac7f8a342953d
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\package\plugin;
3 use wcf\data\acp\search\provider\ACPSearchProviderEditor;
4 use wcf\system\cache\builder\ACPSearchProviderCacheBuilder;
5 use wcf\system\WCF;
6
7 /**
8 * Installs, updates and deletes ACP search providers.
9 *
10 * @author Alexander Ebert
11 * @copyright 2001-2016 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package com.woltlab.wcf
14 * @subpackage system.package.plugin
15 * @category Community Framework
16 */
17 class ACPSearchProviderPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
18 /**
19 * @inheritDoc
20 */
21 public $className = ACPSearchProviderEditor::class;
22
23 /**
24 * @inheritDoc
25 */
26 protected function handleDelete(array $items) {
27 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
28 WHERE providerName = ?
29 AND packageID = ?";
30 $statement = WCF::getDB()->prepareStatement($sql);
31
32 WCF::getDB()->beginTransaction();
33 foreach ($items as $item) {
34 $statement->execute([
35 $item['attributes']['name'],
36 $this->installation->getPackageID()
37 ]);
38 }
39 WCF::getDB()->commitTransaction();
40 }
41
42 /**
43 * @inheritDoc
44 */
45 protected function prepareImport(array $data) {
46 // get show order
47 $showOrder = (isset($data['elements']['showorder'])) ? $data['elements']['showorder'] : null;
48 $showOrder = $this->getShowOrder($showOrder);
49
50 return [
51 'className' => $data['elements']['classname'],
52 'providerName' => $data['attributes']['name'],
53 'showOrder' => $showOrder
54 ];
55 }
56
57 /**
58 * @inheritDoc
59 */
60 protected function findExistingItem(array $data) {
61 $sql = "SELECT *
62 FROM wcf".WCF_N."_".$this->tableName."
63 WHERE providerName = ?
64 AND packageID = ?";
65 $parameters = [
66 $data['providerName'],
67 $this->installation->getPackageID()
68 ];
69
70 return [
71 'sql' => $sql,
72 'parameters' => $parameters
73 ];
74 }
75
76 /**
77 * @inheritDoc
78 */
79 protected function cleanup() {
80 ACPSearchProviderCacheBuilder::getInstance()->reset();
81 }
82
83 /**
84 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::getDefaultFilename()
85 * @since 2.2
86 */
87 public static function getDefaultFilename() {
88 return 'acpSearchProvider.xml';
89 }
90 }