2 namespace wcf\system\package\plugin;
3 use wcf\data\acp\search\provider\ACPSearchProviderEditor;
4 use wcf\data\acp\search\provider\ACPSearchProviderList;
5 use wcf\system\cache\builder\ACPSearchProviderCacheBuilder;
6 use wcf\system\devtools\pip\IDevtoolsPipEntryList;
7 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
8 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
9 use wcf\system\form\builder\container\FormContainer;
10 use wcf\system\form\builder\field\validation\FormFieldValidationError;
11 use wcf\system\form\builder\field\validation\FormFieldValidator;
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\FormFieldValidatorUtil;
16 use wcf\system\form\builder\IFormDocument;
17 use wcf\system\search\acp\IACPSearchResultProvider;
21 * Installs, updates and deletes ACP search providers.
23 * @author Alexander Ebert
24 * @copyright 2001-2019 WoltLab GmbH
25 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
26 * @package WoltLabSuite\Core\System\Package\Plugin
28 class ACPSearchProviderPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin implements IGuiPackageInstallationPlugin {
29 use TXmlGuiPackageInstallationPlugin;
34 public $className = ACPSearchProviderEditor::class;
39 protected function handleDelete(array $items) {
40 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
41 WHERE providerName = ?
43 $statement = WCF::getDB()->prepareStatement($sql);
45 WCF::getDB()->beginTransaction();
46 foreach ($items as $item) {
48 $item['attributes']['name'],
49 $this->installation->getPackageID()
52 WCF::getDB()->commitTransaction();
58 protected function prepareImport(array $data) {
60 $showOrder = isset($data['elements']['showorder']) ? $data['elements']['showorder'] : null;
61 $showOrder = $this->getShowOrder($showOrder);
64 'className' => $data['elements']['classname'],
65 'providerName' => $data['attributes']['name'],
66 'showOrder' => $showOrder
73 protected function findExistingItem(array $data) {
75 FROM wcf".WCF_N."_".$this->tableName."
76 WHERE providerName = ?
79 $data['providerName'],
80 $this->installation->getPackageID()
85 'parameters' => $parameters
92 protected function cleanup() {
93 ACPSearchProviderCacheBuilder::getInstance()->reset();
97 * @see \wcf\system\package\plugin\IPackageInstallationPlugin::getDefaultFilename()
100 public static function getDefaultFilename() {
101 return 'acpSearchProvider.xml';
108 public static function getSyncDependencies() {
116 protected function fetchElementData(\DOMElement $element, $saveData) {
118 'className' => $element->getElementsByTagName('classname')->item(0)->nodeValue,
119 'packageID' => $this->installation->getPackage()->packageID,
120 'providerName' => $element->getAttribute('name')
123 $showOrder = $element->getElementsByTagName('showorder')->item(0);
125 $data['showOrder'] = $showOrder->nodeValue;
127 else if ($saveData) {
128 $data['showOrder'] = $this->getShowOrder(null);
138 public function getElementIdentifier(\DOMElement $element) {
139 return $element->getAttribute('name');
146 protected function addFormFields(IFormDocument $form) {
147 /** @var FormContainer $dataContainer */
148 $dataContainer = $form->getNodeById('data');
150 $dataContainer->appendChildren([
151 TextFormField::create('providerName')
152 ->objectProperty('name')
153 ->label('wcf.acp.pip.acpSearchProvider.providerName')
154 ->description('wcf.acp.pip.acpSearchProvider.providerName.description', ['project' => $this->installation->getProject()])
156 ->addValidator(FormFieldValidatorUtil::getDotSeparatedStringValidator(
157 'wcf.acp.pip.acpSearchProvider.providerName',
160 ->addValidator(new FormFieldValidator('uniqueness', function(TextFormField $formField) {
162 $formField->getDocument()->getFormMode() === IFormDocument::FORM_MODE_CREATE ||
163 $this->editedEntry->getAttribute('name') !== $formField->getValue()
165 $providerList = new ACPSearchProviderList();
166 $providerList->getConditionBuilder()->add('providerName = ?', [$formField->getValue()]);
168 if ($providerList->countObjects() > 0) {
169 $formField->addValidationError(
170 new FormFieldValidationError(
172 'wcf.acp.pip.acpSearchProvider.providerName.error.notUnique'
179 ClassNameFormField::create('className')
180 ->objectProperty('classname')
182 ->implementedInterface(IACPSearchResultProvider::class),
184 IntegerFormField::create('showOrder')
185 ->objectProperty('showorder')
186 ->label('wcf.form.field.showOrder')
187 ->description('wcf.acp.pip.acpSearchProvider.showOrder.description')
197 protected function setEntryListKeys(IDevtoolsPipEntryList $entryList) {
198 $entryList->setKeys([
199 'providerName' => 'wcf.acp.pip.acpSearchProvider.providerName',
200 'className' => 'wcf.form.field.className'
208 protected function prepareXmlElement(\DOMDocument $document, IFormDocument $form) {
209 $data = $form->getData()['data'];
211 $acpSearchProvider = $document->createElement($this->tagName);
212 $acpSearchProvider->setAttribute('name', $data['name']);
214 $this->appendElementChildren(
223 return $acpSearchProvider;