b174f9a4a20fb078ec380c5a439baa3330c09a9c
[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 WoltLabSuite\Core\System\Package\Plugin
14 */
15 class ACPSearchProviderPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin {
16 /**
17 * @inheritDoc
18 */
19 public $className = ACPSearchProviderEditor::class;
20
21 /**
22 * @inheritDoc
23 */
24 protected function handleDelete(array $items) {
25 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
26 WHERE providerName = ?
27 AND packageID = ?";
28 $statement = WCF::getDB()->prepareStatement($sql);
29
30 WCF::getDB()->beginTransaction();
31 foreach ($items as $item) {
32 $statement->execute([
33 $item['attributes']['name'],
34 $this->installation->getPackageID()
35 ]);
36 }
37 WCF::getDB()->commitTransaction();
38 }
39
40 /**
41 * @inheritDoc
42 */
43 protected function prepareImport(array $data) {
44 // get show order
45 $showOrder = (isset($data['elements']['showorder'])) ? $data['elements']['showorder'] : null;
46 $showOrder = $this->getShowOrder($showOrder);
47
48 return [
49 'className' => $data['elements']['classname'],
50 'providerName' => $data['attributes']['name'],
51 'showOrder' => $showOrder
52 ];
53 }
54
55 /**
56 * @inheritDoc
57 */
58 protected function findExistingItem(array $data) {
59 $sql = "SELECT *
60 FROM wcf".WCF_N."_".$this->tableName."
61 WHERE providerName = ?
62 AND packageID = ?";
63 $parameters = [
64 $data['providerName'],
65 $this->installation->getPackageID()
66 ];
67
68 return [
69 'sql' => $sql,
70 'parameters' => $parameters
71 ];
72 }
73
74 /**
75 * @inheritDoc
76 */
77 protected function cleanup() {
78 ACPSearchProviderCacheBuilder::getInstance()->reset();
79 }
80
81 /**
82 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::getDefaultFilename()
83 * @since 3.0
84 */
85 public static function getDefaultFilename() {
86 return 'acpSearchProvider.xml';
87 }
88 }