2 namespace wcf\system\package\plugin;
3 use wcf\data\object\type\definition\ObjectTypeDefinitionEditor;
4 use wcf\data\object\type\ObjectTypeCache;
5 use wcf\system\devtools\pip\IDevtoolsPipEntryList;
6 use wcf\system\devtools\pip\IGuiPackageInstallationPlugin;
7 use wcf\system\devtools\pip\TXmlGuiPackageInstallationPlugin;
8 use wcf\system\form\builder\container\FormContainer;
9 use wcf\system\form\builder\field\validation\FormFieldValidationError;
10 use wcf\system\form\builder\field\validation\FormFieldValidator;
11 use wcf\system\form\builder\field\TextFormField;
12 use wcf\system\form\builder\field\validation\FormFieldValidatorUtil;
13 use wcf\system\form\builder\IFormDocument;
17 * Installs, updates and deletes object type definitions.
19 * @author Alexander Ebert
20 * @copyright 2001-2018 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
22 * @package WoltLabSuite\Core\Acp\Package\Plugin
24 class ObjectTypeDefinitionPackageInstallationPlugin extends AbstractXMLPackageInstallationPlugin implements IGuiPackageInstallationPlugin {
25 use TXmlGuiPackageInstallationPlugin;
30 public $className = ObjectTypeDefinitionEditor::class;
35 public $tagName = 'definition';
40 protected function handleDelete(array $items) {
41 $sql = "DELETE FROM wcf".WCF_N."_".$this->tableName."
42 WHERE definitionName = ?
44 $statement = WCF::getDB()->prepareStatement($sql);
45 foreach ($items as $item) {
47 $item['attributes']['name'],
48 $this->installation->getPackageID()
56 protected function prepareImport(array $data) {
58 'interfaceName' => isset($data['elements']['interfacename']) ? $data['elements']['interfacename'] : '',
59 'definitionName' => $data['elements']['name'],
60 'categoryName' => isset($data['elements']['categoryname']) ? $data['elements']['categoryname'] : ''
67 protected function findExistingItem(array $data) {
69 FROM wcf".WCF_N."_".$this->tableName."
70 WHERE definitionName = ?";
71 $parameters = [$data['definitionName']];
75 'parameters' => $parameters
83 public static function getSyncDependencies() {
91 protected function addFormFields(IFormDocument $form) {
92 /** @var FormContainer $dataContainer */
93 $dataContainer = $form->getNodeById('data');
95 $dataContainer->appendChildren([
96 TextFormField::create('definitionName')
97 ->objectProperty('name')
98 ->label('wcf.acp.pip.objectTypeDefinition.definitionName')
99 ->description('wcf.acp.pip.objectTypeDefinition.definitionName.description', ['project' => $this->installation->getProject()])
101 ->addValidator(FormFieldValidatorUtil::getDotSeparatedStringValidator(
102 'wcf.acp.pip.objectTypeDefinition.definitionName',
105 ->addValidator(new FormFieldValidator('uniqueness', function(TextFormField $formField) {
106 if ($formField->getValue()) {
107 $objectTypeDefinition = ObjectTypeCache::getInstance()->getDefinitionByName($formField->getValue());
109 // the definition name is not unique if such an object type definition
110 // already exists and (a) a new definition is added or (b) an existing
111 // definition is edited but the new definition name is not the old definition
112 // name so that the existing definition is not the definition currently edited
113 if ($objectTypeDefinition !== null && (
114 $formField->getDocument()->getFormMode() === IFormDocument::FORM_MODE_CREATE ||
115 $this->editedEntry->getElementsByTagName('name')->item(0)->nodeValue !== $formField->getValue()
117 $formField->addValidationError(
118 new FormFieldValidationError(
120 'wcf.acp.pip.objectTypeDefinition.definitionName.error.notUnique'
127 TextFormField::create('interfaceName')
128 ->objectProperty('interfacename')
129 ->label('wcf.acp.pip.objectTypeDefinition.interfaceName')
130 ->description('wcf.acp.pip.objectTypeDefinition.interfaceName.description')
131 ->addValidator(new FormFieldValidator('interfaceExists', function(TextFormField $formField) {
132 if ($formField->getValue() && !interface_exists($formField->getValue())) {
133 $formField->addValidationError(
134 new FormFieldValidationError(
136 'wcf.acp.pip.objectTypeDefinition.interfaceName.error.nonExistent'
148 protected function doGetElementData(\DOMElement $element, $saveData) {
150 'definitionName' => $element->getElementsByTagName('name')->item(0)->nodeValue,
151 'packageID' => $this->installation->getPackage()->packageID
154 $interfaceName = $element->getElementsByTagName('interfacename')->item(0);
155 if ($interfaceName) {
156 $data['interfaceName'] = $interfaceName->nodeValue;
158 else if ($saveData) {
159 $data['interfaceName'] = '';
169 public function getElementIdentifier(\DOMElement $element) {
170 return $element->getElementsByTagName('name')->item(0)->nodeValue;
177 protected function setEntryListKeys(IDevtoolsPipEntryList $entryList) {
178 $entryList->setKeys([
179 'definitionName' => 'wcf.acp.pip.objectTypeDefinition.definitionName',
180 'interfaceName' => 'wcf.acp.pip.objectTypeDefinition.interfaceName'
188 protected function doCreateXmlElement(\DOMDocument $document, IFormDocument $form) {
189 $definition = $document->createElement($this->tagName);
191 $this->appendElementChildren(
195 'interfacename' => ''