3 namespace wcf\system\package\plugin;
5 use wcf\data\acp\search\provider\ACPSearchProviderEditor;
6 use wcf\data\acp\search\provider\ACPSearchProviderList;
7 use wcf\system\cache\builder\ACPSearchProviderCacheBuilder;
8 use wcf\system\devtools\pip\IDevtoolsPipEntryList;
9 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
10 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
11 use wcf\system\form\builder\container\FormContainer;
12 use wcf\system\form\builder\field\ClassNameFormField;
13 use wcf\system\form\builder\field\IntegerFormField;
14 use wcf\system\form\builder\field\TextFormField;
15 use wcf\system\form\builder\field\validation\FormFieldValidationError;
16 use wcf\system\form\builder\field\validation\FormFieldValidator;
17 use wcf\system\form\builder\field\validation\FormFieldValidatorUtil;
18 use wcf\system\form\builder\IFormDocument;
19 use wcf\system\search\acp\IACPSearchResultProvider;
23 * Installs, updates and deletes ACP search providers.
25 * @author Alexander Ebert
26 * @copyright 2001-2019 WoltLab GmbH
27 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
29 class ACPSearchProviderPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin implements
30 IGuiPackageInstallationPlugin,
31 IUniqueNameXMLPackageInstallationPlugin
33 use TXmlGuiPackageInstallationPlugin;
38 public $className = ACPSearchProviderEditor::class;
43 protected function handleDelete(array $items)
45 $sql = "DELETE FROM wcf" . WCF_N . "_" . $this->tableName . "
46 WHERE providerName = ?
48 $statement = WCF::getDB()->prepareStatement($sql);
50 WCF::getDB()->beginTransaction();
51 foreach ($items as $item) {
53 $item['attributes']['name'],
54 $this->installation->getPackageID(),
57 WCF::getDB()->commitTransaction();
63 protected function prepareImport(array $data)
66 $showOrder = $data['elements']['showorder'] ?? null;
67 $showOrder = $this->getShowOrder($showOrder);
70 'className' => $data['elements']['classname'],
71 'providerName' => $data['attributes']['name'],
72 'showOrder' => $showOrder,
79 protected function findExistingItem(array $data)
82 FROM wcf" . WCF_N . "_" . $this->tableName . "
83 WHERE providerName = ?
86 $data['providerName'],
87 $this->installation->getPackageID(),
92 'parameters' => $parameters,
99 protected function cleanup()
101 ACPSearchProviderCacheBuilder::getInstance()->reset();
107 public function getNameByData(array $data): string
109 return $data['providerName'];
113 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::getDefaultFilename()
116 public static function getDefaultFilename()
118 return 'acpSearchProvider.xml';
125 public static function getSyncDependencies()
134 protected function fetchElementData(\DOMElement $element, $saveData)
137 'className' => $element->getElementsByTagName('classname')->item(0)->nodeValue,
138 'packageID' => $this->installation->getPackage()->packageID,
139 'providerName' => $element->getAttribute('name'),
142 $showOrder = $element->getElementsByTagName('showorder')->item(0);
144 $data['showOrder'] = $showOrder->nodeValue;
145 } elseif ($saveData) {
146 $data['showOrder'] = $this->getShowOrder(null);
156 public function getElementIdentifier(\DOMElement $element)
158 return $element->getAttribute('name');
165 protected function getXsdFilename()
167 return 'acpSearchProvider';
174 protected function addFormFields(IFormDocument $form)
176 /** @var FormContainer $dataContainer */
177 $dataContainer = $form->getNodeById('data');
179 $dataContainer->appendChildren([
180 TextFormField::create('providerName')
181 ->objectProperty('name')
182 ->label('wcf.acp.pip.acpSearchProvider.providerName')
184 'wcf.acp.pip.acpSearchProvider.providerName.description',
185 ['project' => $this->installation->getProject()]
188 ->addValidator(FormFieldValidatorUtil::getDotSeparatedStringValidator(
189 'wcf.acp.pip.acpSearchProvider.providerName',
192 ->addValidator(new FormFieldValidator('uniqueness', function (TextFormField $formField) {
194 $formField->getDocument()->getFormMode() === IFormDocument::FORM_MODE_CREATE
195 || $this->editedEntry->getAttribute('name') !== $formField->getValue()
197 $providerList = new ACPSearchProviderList();
198 $providerList->getConditionBuilder()->add('providerName = ?', [$formField->getValue()]);
200 if ($providerList->countObjects() > 0) {
201 $formField->addValidationError(
202 new FormFieldValidationError(
204 'wcf.acp.pip.acpSearchProvider.providerName.error.notUnique'
211 ClassNameFormField::create('className')
212 ->objectProperty('classname')
214 ->implementedInterface(IACPSearchResultProvider::class),
216 IntegerFormField::create('showOrder')
217 ->objectProperty('showorder')
218 ->label('wcf.form.field.showOrder')
219 ->description('wcf.acp.pip.acpSearchProvider.showOrder.description')
229 protected function setEntryListKeys(IDevtoolsPipEntryList $entryList)
231 $entryList->setKeys([
232 'providerName' => 'wcf.acp.pip.acpSearchProvider.providerName',
233 'className' => 'wcf.form.field.className',
241 protected function prepareXmlElement(\DOMDocument $document, IFormDocument $form)
243 $data = $form->getData()['data'];
245 $acpSearchProvider = $document->createElement($this->tagName);
246 $acpSearchProvider->setAttribute('name', $data['name']);
248 $this->appendElementChildren(
257 return $acpSearchProvider;