Author: david
Date: Tue Sep 1 15:39:57 2009
New Revision: 3141
Log:
Cascade delete child terms and delete linked QubitRelation and
QubitObjectTermRelation rows when deleting a term. Fixes issue #880.
Modified:
trunk/apps/qubit/modules/term/actions/showAction.class.php
trunk/apps/qubit/modules/term/templates/showSuccess.php
trunk/lib/model/QubitTerm.php
Modified: trunk/apps/qubit/modules/term/actions/showAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/term/actions/showAction.class.php Tue Sep 1
13:20:25 2009 (r3140)
+++ trunk/apps/qubit/modules/term/actions/showAction.class.php Tue Sep 1
15:39:57 2009 (r3141)
@@ -37,12 +37,13 @@
$this->useFors = QubitRelation::getRelationsBySubjectId($this->term->id,
array('typeId' => QubitTerm::TERM_RELATION_EQUIVALENCE_ID));
$this->associateRelations =
QubitRelation::getRelationsBySubjectOrObjectId($this->term->id, array('typeId'
=> QubitTerm::TERM_RELATION_ASSOCIATIVE_ID));
+ $this->descendantCount = count($this->term->getDescendants());
+
//determine if user has edit priviliges
$this->editCredentials = false;
if (SecurityPriviliges::editCredentials($this->getUser(), 'term'))
{
$this->editCredentials = true;
}
-
}
}
Modified: trunk/apps/qubit/modules/term/templates/showSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/term/templates/showSuccess.php Tue Sep 1
13:20:25 2009 (r3140)
+++ trunk/apps/qubit/modules/term/templates/showSuccess.php Tue Sep 1
15:39:57 2009 (r3141)
@@ -145,11 +145,13 @@
</tbody>
</table>
+<?php $deleteConfirm = format_number_choice('[0]Are you sure?|[1,+Inf]Deleting
this term will also delete %1% descendants. Are you sure you want to
proceed?', array('%1%' => $descendantCount), $descendantCount) ?>
+
<ul class="actions">
<?php if (SecurityPriviliges::editCredentials($sf_user, 'term')): ?>
<li><?php echo link_to(__('Add New'), array('module' => 'term', 'action'
=> 'create', 'taxonomyId' => $term->getTaxonomy()->id)) ?></li>
<li><?php echo link_to (__('Edit'), array('module' => 'term', 'action' =>
'edit', 'id' => $term->id)) ?></li>
- <li><?php echo link_to (__('Delete'), array('module' => 'term', 'action'
=> 'delete', 'id' => $term->id), array('post' => true, 'confirm' => __('Are you
sure?'))) ?></li>
+ <li><?php echo link_to (__('Delete'), array('module' => 'term', 'action'
=> 'delete', 'id' => $term->id), array('post' => true, 'confirm' =>
$deleteConfirm)) ?></li>
<?php endif; ?>
<li><?php echo link_to(__('List'), array('module' => 'term', 'action' =>
'list', 'taxonomyId' => $term->taxonomyId)) ?></li>
</ul>
Modified: trunk/lib/model/QubitTerm.php
==============================================================================
--- trunk/lib/model/QubitTerm.php Tue Sep 1 13:20:25 2009 (r3140)
+++ trunk/lib/model/QubitTerm.php Tue Sep 1 15:39:57 2009 (r3141)
@@ -155,6 +155,47 @@
return (string) $this->getName();
}
+ public function delete($connection = null)
+ {
+ // Cascade delete descendants
+ if (0 < count($children = $this->getChildren()))
+ {
+ foreach ($children as $child)
+ {
+ $child->delete($connection);
+ }
+ }
+
+ // Delete relations
+ $criteria = new Criteria;
+ $cton1 = $criteria->getNewCriterion(QubitRelation::OBJECT_ID, $this->id,
Criteria::EQUAL);
+ $cton2 = $criteria->getNewCriterion(QubitRelation::SUBJECT_ID, $this->id,
Criteria::EQUAL);
+ $cton1->addOr($cton2);
+ $criteria->add($cton1);
+
+ if (0 < count($relations = QubitRelation::get($criteria)))
+ {
+ foreach ($relations as $relation)
+ {
+ $relation->delete($connection);
+ }
+ }
+
+ // Delete relation to objects
+ $criteria = new Criteria;
+ $criteria->add(QubitObjectTermRelation::TERM_ID, $this->id,
Criteria::EQUAL);
+
+ if (0 < count($otRelations = QubitObjectTermRelation::get($criteria)))
+ {
+ foreach ($otRelations as $otRelation)
+ {
+ $otRelation->delete($connection);
+ }
+ }
+
+ parent::delete($connection);
+ }
+
public function setNote($userId, $note, $noteTypeId)
{
$newNote = new QubitNote;
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---