Commit 64f498bd34f0567d879c3ad5d49f13af2e6e5ca4
1 parent
1ab451b7
Merged in from STABLE trunk...
KTS-3602 "Tag Cloud creates 2 fieldset entries" Fixed. Added logging. Return a pear error if the check on the existing fieldset fails. Committed by: Megan Watson Reviewed by: Conrad Vermeulen git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/STABLE/branches/3.5.3-Release-Branch@9133 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
69 additions
and
51 deletions
lib/widgets/FieldsetDisplayRegistry.inc.php
| @@ -6,31 +6,31 @@ | @@ -6,31 +6,31 @@ | ||
| 6 | * Document Management Made Simple | 6 | * Document Management Made Simple |
| 7 | * Copyright (C) 2008 KnowledgeTree Inc. | 7 | * Copyright (C) 2008 KnowledgeTree Inc. |
| 8 | * Portions copyright The Jam Warehouse Software (Pty) Limited | 8 | * Portions copyright The Jam Warehouse Software (Pty) Limited |
| 9 | - * | 9 | + * |
| 10 | * This program is free software; you can redistribute it and/or modify it under | 10 | * This program is free software; you can redistribute it and/or modify it under |
| 11 | * the terms of the GNU General Public License version 3 as published by the | 11 | * the terms of the GNU General Public License version 3 as published by the |
| 12 | * Free Software Foundation. | 12 | * Free Software Foundation. |
| 13 | - * | 13 | + * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT | 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 16 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 17 | * details. | 17 | * details. |
| 18 | - * | 18 | + * |
| 19 | * You should have received a copy of the GNU General Public License | 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | - * | ||
| 22 | - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | 21 | + * |
| 22 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | ||
| 23 | * California 94120-7775, or email info@knowledgetree.com. | 23 | * California 94120-7775, or email info@knowledgetree.com. |
| 24 | - * | 24 | + * |
| 25 | * The interactive user interfaces in modified source and object code versions | 25 | * The interactive user interfaces in modified source and object code versions |
| 26 | * of this program must display Appropriate Legal Notices, as required under | 26 | * of this program must display Appropriate Legal Notices, as required under |
| 27 | * Section 5 of the GNU General Public License version 3. | 27 | * Section 5 of the GNU General Public License version 3. |
| 28 | - * | 28 | + * |
| 29 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 29 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 30 | * these Appropriate Legal Notices must retain the display of the "Powered by | 30 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 31 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | 31 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the |
| 32 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 32 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 33 | - * must display the words "Powered by KnowledgeTree" and retain the original | 33 | + * must display the words "Powered by KnowledgeTree" and retain the original |
| 34 | * copyright notice. | 34 | * copyright notice. |
| 35 | * Contributor( s): ______________________________________ | 35 | * Contributor( s): ______________________________________ |
| 36 | * | 36 | * |
| @@ -43,9 +43,9 @@ require_once(KT_LIB_DIR . '/widgets/widgetfactory.inc.php'); | @@ -43,9 +43,9 @@ require_once(KT_LIB_DIR . '/widgets/widgetfactory.inc.php'); | ||
| 43 | require_once(KT_LIB_DIR . '/validation/validatorfactory.inc.php'); | 43 | require_once(KT_LIB_DIR . '/validation/validatorfactory.inc.php'); |
| 44 | 44 | ||
| 45 | class KTFieldsetDisplayRegistry { | 45 | class KTFieldsetDisplayRegistry { |
| 46 | - | 46 | + |
| 47 | var $fieldset_types = array(); | 47 | var $fieldset_types = array(); |
| 48 | - | 48 | + |
| 49 | // {{{ getSingleton | 49 | // {{{ getSingleton |
| 50 | function &getSingleton () { | 50 | function &getSingleton () { |
| 51 | if (!KTUtil::arrayGet($GLOBALS, 'oKTFieldsetDisplayRegistry')) { | 51 | if (!KTUtil::arrayGet($GLOBALS, 'oKTFieldsetDisplayRegistry')) { |
| @@ -63,14 +63,26 @@ class KTFieldsetDisplayRegistry { | @@ -63,14 +63,26 @@ class KTFieldsetDisplayRegistry { | ||
| 63 | function registerFieldsetDisplay($nsname, $className) { | 63 | function registerFieldsetDisplay($nsname, $className) { |
| 64 | $this->fieldset_types[$nsname] = $className; | 64 | $this->fieldset_types[$nsname] = $className; |
| 65 | } | 65 | } |
| 66 | - | 66 | + |
| 67 | function getHandler($nsname) { | 67 | function getHandler($nsname) { |
| 68 | if (!array_key_exists($nsname, $this->fieldset_types)) { | 68 | if (!array_key_exists($nsname, $this->fieldset_types)) { |
| 69 | - // unfortunately, we need to do a bit more spelunking here. | 69 | + // unfortunately, we need to do a bit more spelunking here. |
| 70 | // if its conditional, we use a different item. ns is unsufficient. | 70 | // if its conditional, we use a different item. ns is unsufficient. |
| 71 | - // | 71 | + // |
| 72 | // FIXME this is slightly wasteful from a performance POV, though DB caching should make it OK. | 72 | // FIXME this is slightly wasteful from a performance POV, though DB caching should make it OK. |
| 73 | $oFieldset =& KTFieldset::getByNamespace ($nsname); | 73 | $oFieldset =& KTFieldset::getByNamespace ($nsname); |
| 74 | + if (PEAR::isError($oFieldset)) | ||
| 75 | + { | ||
| 76 | + global $default; | ||
| 77 | + $default->log->error('Could not resolve Fieldset by namespace: ' . $nsname . '. Error: ' . $oFieldset->getMessage()); | ||
| 78 | + return 'SimpleFieldsetDisplay'; | ||
| 79 | + } | ||
| 80 | + if (is_a($oFieldset, 'KTEntityNoObjects')) | ||
| 81 | + { | ||
| 82 | + global $default; | ||
| 83 | + $default->log->error('Could not resolve Fieldset by namespace: ' . $nsname . '. Error: KTEntityNoObjects returned.'); | ||
| 84 | + return 'SimpleFieldsetDisplay'; | ||
| 85 | + } | ||
| 74 | if ($oFieldset->getIsConditional() && KTMetadataUtil::validateCompleteness($oFieldset)) { | 86 | if ($oFieldset->getIsConditional() && KTMetadataUtil::validateCompleteness($oFieldset)) { |
| 75 | return 'ConditionalFieldsetDisplay'; | 87 | return 'ConditionalFieldsetDisplay'; |
| 76 | } else { | 88 | } else { |
| @@ -80,7 +92,7 @@ class KTFieldsetDisplayRegistry { | @@ -80,7 +92,7 @@ class KTFieldsetDisplayRegistry { | ||
| 80 | return $this->fieldset_types[$nsname]; | 92 | return $this->fieldset_types[$nsname]; |
| 81 | } | 93 | } |
| 82 | } | 94 | } |
| 83 | - | 95 | + |
| 84 | // simple function to adapt a fieldset to a form | 96 | // simple function to adapt a fieldset to a form |
| 85 | // passing in $oDocument will set the initial default | 97 | // passing in $oDocument will set the initial default |
| 86 | // values to those attached to the document. | 98 | // values to those attached to the document. |
| @@ -89,10 +101,10 @@ class KTFieldsetDisplayRegistry { | @@ -89,10 +101,10 @@ class KTFieldsetDisplayRegistry { | ||
| 89 | function formAdaptor($oFieldset, $oDocument = null) { | 101 | function formAdaptor($oFieldset, $oDocument = null) { |
| 90 | $widgets = array(); | 102 | $widgets = array(); |
| 91 | $validators = array(); | 103 | $validators = array(); |
| 92 | - | 104 | + |
| 93 | $oVF =& KTValidationFactory::getSingleton(); | 105 | $oVF =& KTValidationFactory::getSingleton(); |
| 94 | - $oWF =& KTWidgetFactory::getSingleton(); | ||
| 95 | - | 106 | + $oWF =& KTWidgetFactory::getSingleton(); |
| 107 | + | ||
| 96 | $fields =& $oFieldset->getFields(); | 108 | $fields =& $oFieldset->getFields(); |
| 97 | foreach ($fields as $oField) { | 109 | foreach ($fields as $oField) { |
| 98 | // FIXME we probably want to use some form of factory here. | 110 | // FIXME we probably want to use some form of factory here. |
| @@ -100,7 +112,7 @@ class KTFieldsetDisplayRegistry { | @@ -100,7 +112,7 @@ class KTFieldsetDisplayRegistry { | ||
| 100 | if ($field->getHasLookup()) { | 112 | if ($field->getHasLookup()) { |
| 101 | // lookups | 113 | // lookups |
| 102 | if ($field->getHasLookupTree()) { | 114 | if ($field->getHasLookupTree()) { |
| 103 | - // tree | 115 | + // tree |
| 104 | // FIXME we don't handle trees yet | 116 | // FIXME we don't handle trees yet |
| 105 | continue; | 117 | continue; |
| 106 | /* | 118 | /* |
| @@ -108,13 +120,13 @@ class KTFieldsetDisplayRegistry { | @@ -108,13 +120,13 @@ class KTFieldsetDisplayRegistry { | ||
| 108 | $fieldTree = new MDTree(); | 120 | $fieldTree = new MDTree(); |
| 109 | $fieldTree->buildForField($field->getId()); | 121 | $fieldTree->buildForField($field->getId()); |
| 110 | $fieldTree->setActiveItem($current_value); | 122 | $fieldTree->setActiveItem($current_value); |
| 111 | - $fieldOptions['tree'] = $fieldTree->_evilTreeRenderer($fieldTree, $fieldName); | ||
| 112 | - $oField = new KTTreeWidget($fieldLabel, $fieldDescription, $fieldName, $fieldValue, $page, $fieldRequired, null, $fieldErrors, $fieldOptions); | ||
| 113 | - | 123 | + $fieldOptions['tree'] = $fieldTree->_evilTreeRenderer($fieldTree, $fieldName); |
| 124 | + $oField = new KTTreeWidget($fieldLabel, $fieldDescription, $fieldName, $fieldValue, $page, $fieldRequired, null, $fieldErrors, $fieldOptions); | ||
| 125 | + | ||
| 114 | */ | 126 | */ |
| 115 | } else { | 127 | } else { |
| 116 | // normal | 128 | // normal |
| 117 | - | 129 | + |
| 118 | $widgets[] = $oWF->get('ktcore.widgets.entityselection', array( | 130 | $widgets[] = $oWF->get('ktcore.widgets.entityselection', array( |
| 119 | 'label' => $oField->getName(), | 131 | 'label' => $oField->getName(), |
| 120 | 'name' => 'metadata_' . $oField->getId(), | 132 | 'name' => 'metadata_' . $oField->getId(), |
| @@ -124,14 +136,14 @@ class KTFieldsetDisplayRegistry { | @@ -124,14 +136,14 @@ class KTFieldsetDisplayRegistry { | ||
| 124 | 'label_method' => 'getName', | 136 | 'label_method' => 'getName', |
| 125 | 'required' => $oField->getIsMandatory(), | 137 | 'required' => $oField->getIsMandatory(), |
| 126 | )); | 138 | )); |
| 127 | - | 139 | + |
| 128 | if ($oField->getIsMandatory()) { | 140 | if ($oField->getIsMandatory()) { |
| 129 | $validators[] = $oVF->get('ktcore.validators.required', array( | 141 | $validators[] = $oVF->get('ktcore.validators.required', array( |
| 130 | 'test' => $field_name, | 142 | 'test' => $field_name, |
| 131 | 'basename' => 'metadata_', | 143 | 'basename' => 'metadata_', |
| 132 | )); | 144 | )); |
| 133 | } | 145 | } |
| 134 | - | 146 | + |
| 135 | $validators[] = $oVF->get('ktcore.validators.membership', array( | 147 | $validators[] = $oVF->get('ktcore.validators.membership', array( |
| 136 | 'test' => $field_name, | 148 | 'test' => $field_name, |
| 137 | 'output' => $field_name, | 149 | 'output' => $field_name, |
| @@ -150,10 +162,10 @@ class KTFieldsetDisplayRegistry { | @@ -150,10 +162,10 @@ class KTFieldsetDisplayRegistry { | ||
| 150 | 'test' => $field_name, | 162 | 'test' => $field_name, |
| 151 | 'basename' => $field_name, | 163 | 'basename' => $field_name, |
| 152 | )); | 164 | )); |
| 153 | - } | ||
| 154 | - } | 165 | + } |
| 166 | + } | ||
| 155 | } | 167 | } |
| 156 | - | 168 | + |
| 157 | return array( | 169 | return array( |
| 158 | 'widgets' => $widgets, | 170 | 'widgets' => $widgets, |
| 159 | 'validators' => $validators, | 171 | 'validators' => $validators, |
plugins/tagcloud/TagCloudPlugin.php
| @@ -7,31 +7,31 @@ | @@ -7,31 +7,31 @@ | ||
| 7 | * Document Management Made Simple | 7 | * Document Management Made Simple |
| 8 | * Copyright (C) 2008 KnowledgeTree Inc. | 8 | * Copyright (C) 2008 KnowledgeTree Inc. |
| 9 | * Portions copyright The Jam Warehouse Software (Pty) Limited | 9 | * Portions copyright The Jam Warehouse Software (Pty) Limited |
| 10 | - * | 10 | + * |
| 11 | * This program is free software; you can redistribute it and/or modify it under | 11 | * This program is free software; you can redistribute it and/or modify it under |
| 12 | * the terms of the GNU General Public License version 3 as published by the | 12 | * the terms of the GNU General Public License version 3 as published by the |
| 13 | * Free Software Foundation. | 13 | * Free Software Foundation. |
| 14 | - * | 14 | + * |
| 15 | * This program is distributed in the hope that it will be useful, but WITHOUT | 15 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | 17 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 18 | * details. | 18 | * details. |
| 19 | - * | 19 | + * |
| 20 | * You should have received a copy of the GNU General Public License | 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | - * | ||
| 23 | - * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | 22 | + * |
| 23 | + * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco, | ||
| 24 | * California 94120-7775, or email info@knowledgetree.com. | 24 | * California 94120-7775, or email info@knowledgetree.com. |
| 25 | - * | 25 | + * |
| 26 | * The interactive user interfaces in modified source and object code versions | 26 | * The interactive user interfaces in modified source and object code versions |
| 27 | * of this program must display Appropriate Legal Notices, as required under | 27 | * of this program must display Appropriate Legal Notices, as required under |
| 28 | * Section 5 of the GNU General Public License version 3. | 28 | * Section 5 of the GNU General Public License version 3. |
| 29 | - * | 29 | + * |
| 30 | * In accordance with Section 7(b) of the GNU General Public License version 3, | 30 | * In accordance with Section 7(b) of the GNU General Public License version 3, |
| 31 | * these Appropriate Legal Notices must retain the display of the "Powered by | 31 | * these Appropriate Legal Notices must retain the display of the "Powered by |
| 32 | - * KnowledgeTree" logo and retain the original copyright notice. If the display of the | 32 | + * KnowledgeTree" logo and retain the original copyright notice. If the display of the |
| 33 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices | 33 | * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices |
| 34 | - * must display the words "Powered by KnowledgeTree" and retain the original | 34 | + * must display the words "Powered by KnowledgeTree" and retain the original |
| 35 | * copyright notice. | 35 | * copyright notice. |
| 36 | * Contributor( s): ______________________________________ | 36 | * Contributor( s): ______________________________________ |
| 37 | * | 37 | * |
| @@ -76,23 +76,27 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | @@ -76,23 +76,27 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | ||
| 76 | 76 | ||
| 77 | 77 | ||
| 78 | // Check if the tagcloud fielset entry exists, if not, create it | 78 | // Check if the tagcloud fielset entry exists, if not, create it |
| 79 | - if(!TagCloudPlugin::tagFieldsetExists()){ | 79 | + $iFieldsetId = TagCloudPlugin::tagFieldsetExists(); |
| 80 | + if(PEAR::isError($iFieldsetId)){ | ||
| 81 | + return false; | ||
| 82 | + } | ||
| 83 | + if($iFieldsetId !== false){ | ||
| 80 | $oFieldset = TagCloudPlugin::createFieldset(); | 84 | $oFieldset = TagCloudPlugin::createFieldset(); |
| 81 | - if (PEAR::isError($oFieldset)) { | 85 | + if (PEAR::isError($oFieldset) || is_null($oFieldset)) { |
| 82 | return false; | 86 | return false; |
| 83 | } | 87 | } |
| 84 | - if($oFieldset){ | ||
| 85 | - // make the fieldset id viewable | ||
| 86 | - $iFieldsetId = $oFieldset->iId; | ||
| 87 | - } | ||
| 88 | - }else{ // if the entry exists, make the fieldset id viewable anyway | ||
| 89 | - $iFieldsetId = TagCloudPlugin::tagFieldsetExists(); | 88 | + // make the fieldset id viewable |
| 89 | + $iFieldsetId = $oFieldset->iId; | ||
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | // Check if the tagcloud document field entry exists, if not, create it | 92 | // Check if the tagcloud document field entry exists, if not, create it |
| 93 | - if(!TagCloudPlugin::tagFieldExists()){ | 93 | + $fExists = TagCloudPlugin::tagFieldExists(); |
| 94 | + if(PEAR::isError($fExists)){ | ||
| 95 | + return false; | ||
| 96 | + } | ||
| 97 | + if($fExists !== false){ | ||
| 94 | $oField = TagCloudPlugin::createDocumentField($iFieldsetId); | 98 | $oField = TagCloudPlugin::createDocumentField($iFieldsetId); |
| 95 | - if (PEAR::isError($oField)) { | 99 | + if (PEAR::isError($oField) || is_null($oField)) { |
| 96 | return false; | 100 | return false; |
| 97 | } | 101 | } |
| 98 | } | 102 | } |
| @@ -156,8 +160,9 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | @@ -156,8 +160,9 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | ||
| 156 | $sTag = DBUtil::getOneResultKey(array($sQuery), 'id'); | 160 | $sTag = DBUtil::getOneResultKey(array($sQuery), 'id'); |
| 157 | 161 | ||
| 158 | if (PEAR::isError($sTag)) { | 162 | if (PEAR::isError($sTag)) { |
| 159 | - // XXX: log error | ||
| 160 | - return false; | 163 | + global $default; |
| 164 | + $default->log->error('Error resolving Tag Cloud field: '. $sTag->getMessage()); | ||
| 165 | + return $sTag; | ||
| 161 | 166 | ||
| 162 | } | 167 | } |
| 163 | if(!is_null($sTag)){ | 168 | if(!is_null($sTag)){ |
| @@ -178,8 +183,9 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | @@ -178,8 +183,9 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); | ||
| 178 | $iFieldset = DBUtil::getOneResultKey(array($sQuery), 'id'); | 183 | $iFieldset = DBUtil::getOneResultKey(array($sQuery), 'id'); |
| 179 | 184 | ||
| 180 | if (PEAR::isError($iFieldset)) { | 185 | if (PEAR::isError($iFieldset)) { |
| 181 | - // XXX: log error | ||
| 182 | - return false; | 186 | + global $default; |
| 187 | + $default->log->error('Error resolving Tag Cloud fieldset: '. $iFieldset->getMessage()); | ||
| 188 | + return $iFieldset; | ||
| 183 | 189 | ||
| 184 | } | 190 | } |
| 185 | if(!is_null($iFieldset)){ | 191 | if(!is_null($iFieldset)){ |