Commit 9ee46a76f92b4e05f139c6a3d776302b27a9fae5
1 parent
485c112b
Fixed TagCloudPlugin bug: document tags are lost when a document is copied
Showing
2 changed files
with
55 additions
and
12 deletions
plugins/tagcloud/TagCloudPlugin.php
| ... | ... | @@ -68,12 +68,13 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); |
| 68 | 68 | * |
| 69 | 69 | */ |
| 70 | 70 | function setup() { |
| 71 | - // Register plugin components | |
| 72 | - $this->registerCriterion('TagCloudCriterion', 'ktcore.criteria.tagcloud', KT_LIB_DIR . '/browse/Criteria.inc'); | |
| 73 | - $this->registerDashlet('TagCloudDashlet', 'ktcore.tagcloud.feed.dashlet', 'TagCloudDashlet.php'); | |
| 74 | - $this->registerPage('TagCloudRedirection', 'TagCloudRedirectPage', __FILE__); | |
| 75 | - $this->registerPortlet(array(), 'TagCloudPortlet', 'tagcloud.portlet', 'TagCloudPortlet.php'); | |
| 71 | + // Register plugin components | |
| 72 | + $this->registerCriterion('TagCloudCriterion', 'ktcore.criteria.tagcloud', KT_LIB_DIR . '/browse/Criteria.inc'); | |
| 73 | + $this->registerDashlet('TagCloudDashlet', 'ktcore.tagcloud.feed.dashlet', 'TagCloudDashlet.php'); | |
| 74 | + $this->registerPage('TagCloudRedirection', 'TagCloudRedirectPage', __FILE__); | |
| 75 | + $this->registerPortlet(array(), 'TagCloudPortlet', 'tagcloud.portlet', 'TagCloudPortlet.php'); | |
| 76 | 76 | |
| 77 | + $this->registerTrigger('copyDocument', 'postValidate', 'KTCopyDocumentTrigger', 'ktcore.triggers.tagcloud.copyDocument', KT_DIR.'/plugins/tagcloud/TagCloudTriggers.php'); | |
| 77 | 78 | |
| 78 | 79 | // Check if the tagcloud fielset entry exists, if not, create it |
| 79 | 80 | $iFieldsetId = TagCloudPlugin::tagFieldsetExists(); |
| ... | ... | @@ -108,10 +109,10 @@ require_once(KT_LIB_DIR . '/templating/templating.inc.php'); |
| 108 | 109 | // create the fieldsets entry |
| 109 | 110 | $oFieldset = KTFieldset::createFromArray(array( |
| 110 | 111 | 'name' => _kt('Tag Cloud'), |
| 111 | - 'description' => _kt('The following tags are associated with your document'), | |
| 112 | + 'description' => _kt('The following tags are associated with your document'), | |
| 112 | 113 | 'namespace' => 'tagcloud', |
| 113 | 114 | 'mandatory' => false, |
| 114 | - 'isConditional' => false, | |
| 115 | + 'isConditional' => false, | |
| 115 | 116 | 'isGeneric' => true, |
| 116 | 117 | 'isComplete' => false, |
| 117 | 118 | 'isComplex' => false, | ... | ... |
plugins/tagcloud/TagCloudTriggers.php
| ... | ... | @@ -63,8 +63,8 @@ class KTAddDocumentTrigger { |
| 63 | 63 | $iDocId = $oDocument->getID(); |
| 64 | 64 | |
| 65 | 65 | // get tag id from document_fields table where name = Tag |
| 66 | - $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' . | |
| 67 | - 'WHERE df.name = \'Tag\''; | |
| 66 | + $sQuery = 'SELECT df.id AS id FROM document_fields AS df ' . | |
| 67 | + 'WHERE df.name = \'Tag\''; | |
| 68 | 68 | |
| 69 | 69 | $sTags = DBUtil::getOneResultKey(array($sQuery), 'id'); |
| 70 | 70 | if (PEAR::isError($sTags)) { |
| ... | ... | @@ -132,7 +132,50 @@ class KTAddDocumentTrigger { |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | +/** | |
| 136 | + * Trigger for document Copy (post-validate) | |
| 137 | + */ | |
| 138 | + class KTCopyDocumentTrigger { | |
| 139 | + var $aInfo = null; | |
| 140 | + /** | |
| 141 | + * function to set the info for the trigger | |
| 142 | + * | |
| 143 | + * @param array $aInfo | |
| 144 | + */ | |
| 145 | + function setInfo(&$aInfo) { | |
| 146 | + $this->aInfo =& $aInfo; | |
| 147 | + } | |
| 148 | + /** | |
| 149 | + * postValidate method for trigger | |
| 150 | + * | |
| 151 | + * @return unknown | |
| 152 | + */ | |
| 153 | + function postValidate() { | |
| 154 | + $oDocument =& $this->aInfo['document']; | |
| 155 | + $oSDocument =& $this->aInfo['source_document']; | |
| 135 | 156 | |
| 157 | + $newDocID = $oDocument->getID(); | |
| 158 | + $origDocID = $oSDocument->getID(); | |
| 159 | + | |
| 160 | + $docTagsTable = KTUtil::getTableName('document_tags'); | |
| 161 | + | |
| 162 | + $query = "SELECT tag_id FROM $docTagsTable WHERE document_id = $origDocID"; | |
| 163 | + $res = DBUtil::getResultArrayKey($query, 'tag_id'); | |
| 164 | + | |
| 165 | + if (PEAR::isError($res)) { | |
| 166 | + return $res; | |
| 167 | + } | |
| 168 | + else { | |
| 169 | + foreach($res as $tagid) { | |
| 170 | + DBUtil::autoInsert($docTagsTable, array( | |
| 171 | + 'document_id'=>$newDocID, | |
| 172 | + 'tag_id'=>$tagid), | |
| 173 | + array('noid'=>true)); | |
| 174 | + } | |
| 175 | + } | |
| 176 | + } | |
| 177 | + | |
| 178 | + } | |
| 136 | 179 | /** |
| 137 | 180 | * Trigger for document edit (postValidate) |
| 138 | 181 | * |
| ... | ... | @@ -200,12 +243,11 @@ class KTEditDocumentTrigger { |
| 200 | 243 | foreach($aMeta as $aMetaData) |
| 201 | 244 | { |
| 202 | 245 | $oProxy = $aMetaData[0]; |
| 203 | - if($oProxy->iId == $sTags) | |
| 204 | - { | |
| 246 | + if($oProxy->iId == $sTags) { | |
| 205 | 247 | $tagString = $aMetaData[1]; |
| 206 | 248 | break; |
| 207 | 249 | } |
| 208 | - } | |
| 250 | + } | |
| 209 | 251 | } |
| 210 | 252 | if($tagString != ''){ |
| 211 | 253 | $words_table = KTUtil::getTableName('tag_words'); | ... | ... |