Commit e32606c29d84fa3ffb638867ea572ea32dc022d3

Authored by kevin_fourie
1 parent 08f96c4e

Merged in from DEV trunk...

KTS-2257
"When changing document type in web interface, triggers are not called"
Fixed.

Reviewed By: Kevin Fourie


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/trunk@7052 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 68 additions and 56 deletions
plugins/ktcore/document/edit.php
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 * License Version 1.1.2 ("License"); You may not use this file except in 5 * License Version 1.1.2 ("License"); You may not use this file except in
6 * compliance with the License. You may obtain a copy of the License at 6 * compliance with the License. You may obtain a copy of the License at
7 * http://www.knowledgetree.com/KPL 7 * http://www.knowledgetree.com/KPL
8 - * 8 + *
9 * Software distributed under the License is distributed on an "AS IS" 9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
11 * See the License for the specific language governing rights and 11 * See the License for the specific language governing rights and
@@ -16,9 +16,9 @@ @@ -16,9 +16,9 @@
16 * (ii) the KnowledgeTree copyright notice 16 * (ii) the KnowledgeTree copyright notice
17 * in the same form as they appear in the distribution. See the License for 17 * in the same form as they appear in the distribution. See the License for
18 * requirements. 18 * requirements.
19 - * 19 + *
20 * The Original Code is: KnowledgeTree Open Source 20 * The Original Code is: KnowledgeTree Open Source
21 - * 21 + *
22 * The Initial Developer of the Original Code is The Jam Warehouse Software 22 * The Initial Developer of the Original Code is The Jam Warehouse Software
23 * (Pty) Ltd, trading as KnowledgeTree. 23 * (Pty) Ltd, trading as KnowledgeTree.
24 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright 24 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
@@ -50,7 +50,7 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -50,7 +50,7 @@ class KTDocumentEditAction extends KTDocumentAction {
50 50
51 var $_sShowPermission = "ktcore.permissions.write"; 51 var $_sShowPermission = "ktcore.permissions.write";
52 var $_bMutator = true; 52 var $_bMutator = true;
53 - var $sIconClass = 'edit_metadata'; 53 + var $sIconClass = 'edit_metadata';
54 54
55 function getInfo() { 55 function getInfo() {
56 if ($this->oDocument->getIsCheckedOut()) { 56 if ($this->oDocument->getIsCheckedOut()) {
@@ -62,11 +62,11 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -62,11 +62,11 @@ class KTDocumentEditAction extends KTDocumentAction {
62 function getDisplayName() { 62 function getDisplayName() {
63 return _kt('Edit Metadata'); 63 return _kt('Edit Metadata');
64 } 64 }
65 - 65 +
66 function predispatch() { 66 function predispatch() {
67 $this->persistParams(array('new_type')); 67 $this->persistParams(array('new_type'));
68 } 68 }
69 - 69 +
70 function form_edit() { 70 function form_edit() {
71 $oForm = new KTForm; 71 $oForm = new KTForm;
72 $oForm->setOptions(array( 72 $oForm->setOptions(array(
@@ -78,10 +78,10 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -78,10 +78,10 @@ class KTDocumentEditAction extends KTDocumentAction {
78 'context' => &$this, 78 'context' => &$this,
79 'extraargs' => $this->meldPersistQuery("","",true), 79 'extraargs' => $this->meldPersistQuery("","",true),
80 )); 80 ));
81 -  
82 - 81 +
  82 +
83 $oFReg =& KTFieldsetRegistry::getSingleton(); 83 $oFReg =& KTFieldsetRegistry::getSingleton();
84 - 84 +
85 $doctypeid = $this->oDocument->getDocumentTypeID(); 85 $doctypeid = $this->oDocument->getDocumentTypeID();
86 if ($_REQUEST['new_type']) { 86 if ($_REQUEST['new_type']) {
87 $oTestType = DocumentType::get($_REQUEST['new_type']); 87 $oTestType = DocumentType::get($_REQUEST['new_type']);
@@ -89,7 +89,7 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -89,7 +89,7 @@ class KTDocumentEditAction extends KTDocumentAction {
89 $doctypeid = $oTestType->getId(); 89 $doctypeid = $oTestType->getId();
90 } 90 }
91 } 91 }
92 - 92 +
93 $widgets = array( 93 $widgets = array(
94 array('ktcore.widgets.string', array( 94 array('ktcore.widgets.string', array(
95 'label' => _kt("Document Title"), 95 'label' => _kt("Document Title"),
@@ -106,46 +106,46 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -106,46 +106,46 @@ class KTDocumentEditAction extends KTDocumentAction {
106 )), 106 )),
107 ); 107 );
108 $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid); 108 $fieldsets = (array) KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid);
109 - 109 +
110 foreach ($fieldsets as $oFieldset) { 110 foreach ($fieldsets as $oFieldset) {
111 $widgets = kt_array_merge($widgets, $oFReg->widgetsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); 111 $widgets = kt_array_merge($widgets, $oFReg->widgetsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument));
112 - $validators = kt_array_merge($validators, $oFReg->validatorsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument)); 112 + $validators = kt_array_merge($validators, $oFReg->validatorsForFieldset($oFieldset, 'fieldset_' . $oFieldset->getId(), $this->oDocument));
113 } 113 }
114 114
115 $oForm->setWidgets($widgets); 115 $oForm->setWidgets($widgets);
116 - $oForm->setValidators($validators);  
117 - 116 + $oForm->setValidators($validators);
  117 +
118 return $oForm; 118 return $oForm;
119 } 119 }
120 -  
121 - function do_main() {  
122 - $this->oPage->setBreadcrumbDetails(_kt("Edit Metadata"));  
123 - 120 +
  121 + function do_main() {
  122 + $this->oPage->setBreadcrumbDetails(_kt("Edit Metadata"));
  123 +
124 $oTemplate = $this->oValidator->validateTemplate('ktcore/document/edit'); 124 $oTemplate = $this->oValidator->validateTemplate('ktcore/document/edit');
125 - 125 +
126 $doctypeid = $this->oDocument->getDocumentTypeID(); 126 $doctypeid = $this->oDocument->getDocumentTypeID();
127 $type = DocumentType::get($doctypeid); 127 $type = DocumentType::get($doctypeid);
128 -  
129 - 128 +
  129 +
130 $oForm = $this->form_edit(); 130 $oForm = $this->form_edit();
131 - 131 +
132 $oTemplate->setData(array( 132 $oTemplate->setData(array(
133 'context' => $this, 133 'context' => $this,
134 'form' => $oForm, 134 'form' => $oForm,
135 'document' => $this->oDocument, 135 'document' => $this->oDocument,
136 'type_name' => $type->getName(), 136 'type_name' => $type->getName(),
137 - )); 137 + ));
138 return $oTemplate->render(); 138 return $oTemplate->render();
139 } 139 }
140 - 140 +
141 function do_update() { 141 function do_update() {
142 $oForm = $this->form_edit(); 142 $oForm = $this->form_edit();
143 - 143 +
144 $res = $oForm->validate(); 144 $res = $oForm->validate();
145 if (!empty($res['errors'])) { 145 if (!empty($res['errors'])) {
146 return $oForm->handleError(); 146 return $oForm->handleError();
147 } 147 }
148 - 148 +
149 $data = $res['results']; 149 $data = $res['results'];
150 150
151 // we need to format these in MDPack format 151 // we need to format these in MDPack format
@@ -154,7 +154,7 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -154,7 +154,7 @@ class KTDocumentEditAction extends KTDocumentAction {
154 // array( 154 // array(
155 // array($oField, $sValue), 155 // array($oField, $sValue),
156 // array($oField, $sValue), 156 // array($oField, $sValue),
157 - // array($oField, $sValue), 157 + // array($oField, $sValue),
158 // ); 158 // );
159 // 159 //
160 // we do this the "easy" way. 160 // we do this the "easy" way.
@@ -165,27 +165,27 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -165,27 +165,27 @@ class KTDocumentEditAction extends KTDocumentAction {
165 $doctypeid = $oTestType->getId(); 165 $doctypeid = $oTestType->getId();
166 } 166 }
167 } 167 }
168 -  
169 - 168 +
  169 +
170 $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid); 170 $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid);
171 - 171 +
172 $MDPack = array(); 172 $MDPack = array();
173 foreach ($fieldsets as $oFieldset) { 173 foreach ($fieldsets as $oFieldset) {
174 $fields = $oFieldset->getFields(); 174 $fields = $oFieldset->getFields();
175 $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId()); 175 $values = (array) KTUtil::arrayGet($data, 'fieldset_' . $oFieldset->getId());
176 foreach ($fields as $oField) { 176 foreach ($fields as $oField) {
177 - $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId());  
178 - 177 + $val = KTUtil::arrayGet($values, 'metadata_' . $oField->getId());
  178 +
179 // FIXME "null" has strange meanings here. 179 // FIXME "null" has strange meanings here.
180 - if (!is_null($val)) { 180 + if (!is_null($val)) {
181 $MDPack[] = array( 181 $MDPack[] = array(
182 $oField, 182 $oField,
183 $val 183 $val
184 ); 184 );
185 } 185 }
186 - 186 +
187 } 187 }
188 - } 188 + }
189 189
190 $this->startTransaction(); 190 $this->startTransaction();
191 if ($this->oDocument->getDocumentTypeId() != $doctypeid) { 191 if ($this->oDocument->getDocumentTypeId() != $doctypeid) {
@@ -205,7 +205,7 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -205,7 +205,7 @@ class KTDocumentEditAction extends KTDocumentAction {
205 // post-triggers. 205 // post-triggers.
206 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 206 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
207 $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate'); 207 $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
208 - 208 +
209 foreach ($aTriggers as $aTrigger) { 209 foreach ($aTriggers as $aTrigger) {
210 $sTrigger = $aTrigger[0]; 210 $sTrigger = $aTrigger[0];
211 $oTrigger = new $sTrigger; 211 $oTrigger = new $sTrigger;
@@ -216,16 +216,16 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -216,16 +216,16 @@ class KTDocumentEditAction extends KTDocumentAction {
216 $oTrigger->setInfo($aInfo); 216 $oTrigger->setInfo($aInfo);
217 $ret = $oTrigger->postValidate(); 217 $ret = $oTrigger->postValidate();
218 } 218 }
219 - 219 +
220 $this->commitTransaction(); 220 $this->commitTransaction();
221 221
222 // create the document transaction record 222 // create the document transaction record
223 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document metadata updated'), 'ktcore.transactions.update'); 223 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document metadata updated'), 'ktcore.transactions.update');
224 $oDocumentTransaction->create(); 224 $oDocumentTransaction->create();
225 - 225 +
226 redirect(KTBrowseUtil::getUrlForDocument($this->oDocument->getId())); 226 redirect(KTBrowseUtil::getUrlForDocument($this->oDocument->getId()));
227 exit(0); 227 exit(0);
228 - } 228 + }
229 229
230 function form_changetype() { 230 function form_changetype() {
231 $oForm = new KTForm; 231 $oForm = new KTForm;
@@ -238,11 +238,11 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -238,11 +238,11 @@ class KTDocumentEditAction extends KTDocumentAction {
238 'cancel_action' => 'main', 238 'cancel_action' => 'main',
239 'action' => 'trytype', 239 'action' => 'trytype',
240 )); 240 ));
241 - 241 +
242 $type = DocumentType::get($this->oDocument->getDocumentTypeId()); 242 $type = DocumentType::get($this->oDocument->getDocumentTypeId());
243 $current_type_name = $type->getName(); 243 $current_type_name = $type->getName();
244 $oFolder = Folder::get($this->oDocument->getFolderID()); 244 $oFolder = Folder::get($this->oDocument->getFolderID());
245 - 245 +
246 $oForm->setWidgets(array( 246 $oForm->setWidgets(array(
247 array('ktcore.widgets.entityselection',array( 247 array('ktcore.widgets.entityselection',array(
248 'label' => _kt("New Document Type"), 248 'label' => _kt("New Document Type"),
@@ -256,7 +256,7 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -256,7 +256,7 @@ class KTDocumentEditAction extends KTDocumentAction {
256 'name' => 'type' 256 'name' => 'type'
257 )), 257 )),
258 )); 258 ));
259 - 259 +
260 $oForm->setValidators(array( 260 $oForm->setValidators(array(
261 array('ktcore.validators.entity', array( 261 array('ktcore.validators.entity', array(
262 'test' => 'type', 262 'test' => 'type',
@@ -264,31 +264,31 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -264,31 +264,31 @@ class KTDocumentEditAction extends KTDocumentAction {
264 'class' => 'DocumentType', 264 'class' => 'DocumentType',
265 )), 265 )),
266 )); 266 ));
267 - 267 +
268 return $oForm; 268 return $oForm;
269 } 269 }
270 270
271 function do_selecttype() { 271 function do_selecttype() {
272 $oForm = $this->form_changetype(); 272 $oForm = $this->form_changetype();
273 return $oForm->renderPage(_kt("Change Document Type")); 273 return $oForm->renderPage(_kt("Change Document Type"));
274 - }  
275 - 274 + }
  275 +
276 function do_trytype() { 276 function do_trytype() {
277 $oForm = $this->form_changetype(); 277 $oForm = $this->form_changetype();
278 $res = $oForm->validate(); 278 $res = $oForm->validate();
279 $data = $res['results']; 279 $data = $res['results'];
280 $errors = $res['errors']; 280 $errors = $res['errors'];
281 - 281 +
282 if (!empty($errors)) { 282 if (!empty($errors)) {
283 $oForm->handleError(); 283 $oForm->handleError();
284 - }  
285 - 284 + }
  285 +
286 $document_type = $data['type']; 286 $document_type = $data['type'];
287 - 287 +
288 288
289 $doctypeid = $document_type->getId(); 289 $doctypeid = $document_type->getId();
290 290
291 - 291 +
292 DBUtil::startTransaction(); 292 DBUtil::startTransaction();
293 $this->oDocument->setDocumentTypeId($doctypeid); 293 $this->oDocument->setDocumentTypeId($doctypeid);
294 $res = $this->oDocument->update(); 294 $res = $this->oDocument->update();
@@ -302,9 +302,9 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -302,9 +302,9 @@ class KTDocumentEditAction extends KTDocumentAction {
302 DBUtil::commit(); 302 DBUtil::commit();
303 303
304 $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid); 304 $fieldsets = KTMetadataUtil::fieldsetsForDocument($this->oDocument, $doctypeid);
305 - 305 +
306 $fs_ids = array(); 306 $fs_ids = array();
307 - 307 +
308 $doctype_fieldsets = KTFieldSet::getForDocumentType($doctypeid); 308 $doctype_fieldsets = KTFieldSet::getForDocumentType($doctypeid);
309 foreach($doctype_fieldsets as $fieldset) 309 foreach($doctype_fieldsets as $fieldset)
310 { 310 {
@@ -334,11 +334,23 @@ class KTDocumentEditAction extends KTDocumentAction { @@ -334,11 +334,23 @@ class KTDocumentEditAction extends KTDocumentAction {
334 } 334 }
335 335
336 } 336 }
337 - 337 +
338 $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack); 338 $core_res = KTDocumentUtil::saveMetadata($this->oDocument, $MDPack);
339 -  
340 -  
341 - 339 +
  340 + $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
  341 + $aTriggers = $oKTTriggerRegistry->getTriggers('edit', 'postValidate');
  342 +
  343 + foreach ($aTriggers as $aTrigger) {
  344 + $sTrigger = $aTrigger[0];
  345 + $oTrigger = new $sTrigger;
  346 + $aInfo = array(
  347 + "document" => $this->oDocument,
  348 + "aOptions" => $MDPack,
  349 + );
  350 + $oTrigger->setInfo($aInfo);
  351 + $ret = $oTrigger->postValidate();
  352 + }
  353 +
342 $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName())); 354 $this->successRedirectToMain(sprintf(_kt("You have selected a new document type: %s. "), $data['type']->getName()));
343 } 355 }
344 } 356 }