Index: openacs-4/packages/contacts/tcl/contacts-init.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-init.tcl,v
diff -u -r1.13 -r1.14
--- openacs-4/packages/contacts/tcl/contacts-init.tcl 3 Dec 2006 16:14:09 -0000 1.13
+++ openacs-4/packages/contacts/tcl/contacts-init.tcl 24 Jun 2007 08:20:54 -0000 1.14
@@ -11,6 +11,8 @@
# accounts for themselves) content_items and content_revisions
# are automatically create. This is needed for contacts
# searches to work correctly.
+
+nsv_set contacts sweeper_p 0
ad_schedule_proc -thread t 300 contacts::sweeper
if {[empty_string_p [info procs callback]]} {
Index: openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql,v
diff -u -r1.26 -r1.27
--- openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql 21 Jun 2007 20:06:42 -0000 1.26
+++ openacs-4/packages/contacts/tcl/contacts-procs-postgresql.xql 24 Jun 2007 08:20:54 -0000 1.27
@@ -26,15 +26,32 @@
+
+
+ select count(*) from persons left join (select item_id from cr_items where content_type = 'contact_party_revision') items on item_id = person_id
+ where person_id > 0
+ and item_id is null
+
+
+
- select person_id, first_names,last_name,email from persons, parties
- where person_id not in (select item_id from cr_items where content_type = 'contact_party_revision')
- and person_id > 0
+ select person_id, first_names,last_name,email
+ from persons left join (select item_id from cr_items where content_type = 'contact_party_revision') items on item_id = person_id, parties
+ where person_id > 0
and person_id = party_id
+ and item_id is null
+
+
+ select member_state
+ from cc_users
+ where user_id = :person_id
+
+
+
select organization_id
@@ -53,6 +70,27 @@
+
+
+ delete
+ from group_element_index
+ where group_id = :group_id
+ and element_id in (select member_id from membership_rels m, group_member_map g where g.rel_id = m.rel_id and member_state = 'deleted' and group_id = -2)
+
+
+
+
+
+ select item_id
+ from cr_items, membership_rels m, group_member_map g
+ where g.rel_id = m.rel_id
+ and member_state = 'deleted'
+ and group_id = -2
+ and item_id = member_id
+
+
+
+
select attribute_id
Index: openacs-4/packages/contacts/tcl/contacts-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-procs.tcl,v
diff -u -r1.111 -r1.112
--- openacs-4/packages/contacts/tcl/contacts-procs.tcl 21 Jun 2007 20:06:42 -0000 1.111
+++ openacs-4/packages/contacts/tcl/contacts-procs.tcl 24 Jun 2007 08:20:54 -0000 1.112
@@ -125,66 +125,94 @@
by contacts (ones created by contacts automatically get
associated item_id and live_revisions.
} {
- if {$contacts_package_ids eq ""} {
- set contacts_package_ids [apm_package_ids_from_key -package_key "contacts" -mounted]
+
+ # Make sure that only one thread is processing the queue at a
+ # time.
+ if {[nsv_incr contacts sweeper_p] > 1} {
+ nsv_incr contacts sweeper_p -1
+ return
}
- foreach contact_package_id $contacts_package_ids {
- set default_group_id [contacts::default_group -package_id $contact_package_id]
- set contact_package($default_group_id) $contact_package_id
- lappend default_groups $default_group_id
- }
- # Try to insert the persons into the package_id of the first group found
- db_foreach get_persons_without_items {} {
+ with_finally -code {
+ if {$contacts_package_ids eq ""} {
+ set contacts_package_ids [apm_package_ids_from_key -package_key "contacts" -mounted]
+ }
- foreach group_id $default_groups {
- if {[group::party_member_p -party_id $person_id -group_id $group_id]} {
- set contact_revision_id [contact::revision::new -party_id $person_id -package_id $contact_package($group_id)]
- break
- }
+ foreach contact_package_id $contacts_package_ids {
+ set default_group_id [contacts::default_group -package_id $contact_package_id]
+ set contact_package($default_group_id) $contact_package_id
+ lappend default_groups $default_group_id
}
- if {![exists_and_not_null contact_revision_id]} {
- # We did not found a group, so just use the first contacts instance.
- if {[ad_conn isconnected]} {
- set user_id [ad_conn user_id]
- set peeraddr [ad_conn peeraddr]
- } else {
- set user_id $person_id
- set peeraddr 127.0.0.1
+ # Count number of persons without items
+ set person_num [db_string get_persons_num {}]
+ set counter 0
+
+ # Try to insert the persons into the package_id of the first group found
+ db_foreach get_persons_without_items {} {
+
+ # Check if the person is a deleted user
+ set member_state [db_string member_state "select member_state from cc_users where user_id = :person_id" -default ""]
+ if {$member_state ne "deleted"} {
+ foreach group_id $default_groups {
+ if {[group::party_member_p -party_id $person_id -group_id $group_id]} {
+ set contact_revision_id [contact::revision::new -party_id $person_id -package_id $contact_package($group_id)]
+ break
+ }
+ }
+
+ if {![exists_and_not_null contact_revision_id]} {
+ # We did not found a group, so just use the first contacts instance.
+ if {[ad_conn isconnected]} {
+ set user_id [ad_conn user_id]
+ set peeraddr [ad_conn peeraddr]
+ } else {
+ set user_id $person_id
+ set peeraddr 127.0.0.1
+ }
+ set contact_revision_id [contact::revision::new -party_id $person_id -package_id $contact_package_id -creation_user $user_id -creation_ip $peeraddr]
}
- set contact_revision_id [contact::revision::new -party_id $person_id -package_id $contact_package_id -creation_user $user_id -creation_ip $peeraddr]
- }
-
- # Add the default ams attributes
- foreach attribute {first_names last_name email} {
- if {[exists_and_not_null $attribute]} {
- ams::attribute::save::text -object_type "person" -object_id $contact_revision_id -attribute_name "$attribute" -value [set $attribute]
+
+ # Add the default ams attributes
+ foreach attribute {first_names last_name email} {
+ if {[exists_and_not_null $attribute]} {
+ ams::attribute::save::text -object_type "person" -object_id $contact_revision_id -attribute_name "$attribute" -value [set $attribute]
+ }
}
+
+ # And insert into the default group for this package.
+ group::add_member -user_id $person_id -group_id $default_group_id -no_perm_check
+ incr counter
+ ns_log notice "contacts::sweeper ($counter / $person_num) creating content_item and content_revision $contact_revision_id for party_id: $person_id in $default_group_id"
+ }
}
-
- # And insert into the default group for this package.
- group::add_member -user_id $person_id -group_id $default_group_id -no_perm_check
- ns_log notice "contacts::sweeper creating content_item and content_revision for party_id: $person_id in $default_group_id"
- }
-
- db_foreach get_organizations_without_items {} {
- foreach group_id $default_groups {
- if {[group::party_member_p -party_id $organization_id -group_id $group_id]} {
- contact::revision::new -party_id $organization_id -package_id $contact_package($group_id) -creation_user 0
- break
+
+ db_foreach get_organizations_without_items {} {
+ foreach group_id $default_groups {
+ if {[group::party_member_p -party_id $organization_id -group_id $group_id]} {
+ contact::revision::new -party_id $organization_id -package_id $contact_package($group_id) -creation_user 0
+ break
+ }
}
+ ns_log notice "contacts::sweeper creating content_item and content_revision for organization_id: $organization_id"
+ contact::revision::new -party_id $organization_id -package_id $contact_package_id
}
- ns_log notice "contacts::sweeper creating content_item and content_revision for organization_id: $organization_id"
- contact::revision::new -party_id $organization_id -package_id $contact_package_id
+
+ if { ![info exists person_id] && ![info exists organization_id] } {
+ ns_log Debug "contacts::create_revisions_sweeper no person or organization objects exist that do not have associated content_items"
+ }
+ db_dml insert_privacy_records {}
+ # Delete records where the user_id has been deleted. After all, deleted users should not show up in contacts either
+ foreach group_id $default_groups {
+ db_dml delete_deleted_users {}
}
-
- if { ![info exists person_id] && ![info exists organization_id] } {
- ns_log Debug "contacts::create_revisions_sweeper no person or organization objects exist that do not have associated content_items"
+
+ } -finally {
+ nsv_incr contacts sweeper_p -1
}
- db_dml insert_privacy_records {}
+
}
-
+
ad_proc -public contacts::multirow {
{-extend ""}
{-multirow}
@@ -926,7 +954,11 @@
} {
Get the group name for contacts (this might be a dotlrn community name or a group title)
} {
- set dotlrn_community_name [dotlrn_community::get_community_name $group_id]
+ if {[info procs dotlrn_community::get_community_name] eq ""} {
+ set dotlrn_community_name ""
+ } else {
+ set dotlrn_community_name [dotlrn_community::get_community_name $group_id]
+ }
if { $dotlrn_community_name ne "" } {
return $dotlrn_community_name
} else {