e6ed2335a0db9cf0a3aff32172570766a6b8432e
[GitHub/WoltLab/WCF.git] /
1 <?php
2 declare(strict_types=1);
3 namespace wcf\system\package\plugin;
4 use wcf\data\acp\search\provider\ACPSearchProviderEditor;
5 use wcf\system\cache\builder\ACPSearchProviderCacheBuilder;
6 use wcf\system\devtools\pip\IIdempotentPackageInstallationPlugin;
7 use wcf\system\WCF;
8
9 /**
10 * Installs, updates and deletes ACP search providers.
11 *
12 * @author Alexander Ebert
13 * @copyright 2001-2018 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\Package\Plugin
16 */
17 class ACPSearchProviderPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin implements IIdempotentPackageInstallationPlugin {
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 3.0
86 */
87 public static function getDefaultFilename() {
88 return 'acpSearchProvider.xml';
89 }
90
91 /**
92 * @inheritDoc
93 */
94 public static function getSyncDependencies() {
95 return [];
96 }
97 }