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