Manually Uncheck All Email Notifications from Users using SQL Queries
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
The content on this page includes steps to customize or extend Atlassian software (adding/changing CSS rules, HTML, JavaScript, etc.). Per the Atlassian Support Offerings, support does not include customizations made to Atlassian products. Be aware that this material is provided for your information only and using it is done so at your risk.
If you have any questions about this or any customization, please ask the community at Atlassian Answers or consider working with an Atlassian Solution Partner.
IMPORTANT: As with all recommendations made by Support, it is expected that you will follow best practices for Change Management and will test and validate these settings in a Test/Development and Staging environment prior to rolling any changes into a Production environment. You must test and validate these changes to insure that they will function will within your infrastructure prior to placing these changes in production.
IMPORTANT: Before you run this action in a production environment, you are strongly advised to backup your production database using native database backup tools to create a snapshot prior to running this action.
Pre-requisites
You will need to have Python 2.7 or later installed on the workstation you will use with this solution.
Purpose
Some organizations wish to disable all email preferences for users manually through the use of SQL queries without disabling the email server in their Confluence instance. This means that users must manually alter their email preferences in order to receive mail from Confluence. Note: This solution is only effective for users that exist when the instance is altered. New users that are added after the implementation of this solution will not be effected by this change and will have the default user email preferences checked. This solution is meant as a one-time only solution and carries the risk of added complexity in your instance. It is far easier to simply disable the email server, but this solution is provided to those that wish to ensure that your user's email profiles will have no boxes checked by default:
Solution
Step One: Identify your users
In order to gather the users to be modified, you will need to run the following query against your database and then export the output file as a comma separated values (CSV) file. You should name this file: input.csv.
Query One
SELECT
um.user_key
FROM
user_mapping um
WHERE
um.user_key NOT IN
(
SELECT
concat('USERPROPS-', um.user_key) AS userKey
FROM
os_propertyentry
WHERE
entity_key IN ('confluence.prefs.notify.for.my.own.actions',
'confluence.prefs.watch.my.own.content',
'confluence.prefs.email.show.diff',
'confluence.prefs.email.mimetype',
'confluence.prefs.notify.on.new.followers',
'confluence.prefs.daily.summary.receive.updates.set',
'confluence.prefs.daily.summary.receive.updates'));
This will output a list of all userKey values for every user present in Confluence when run.
Save the file as input.csv as previously stated.
Create a new text file
The following file should be created in your text editor of choice:
INSERT INTO os_propertyentry (entity_name, entity_id, entity_key, key_type, boolean_val, double_val, string_val, text_val, long_val, int_val, date_val) VALUES ('USERPROPS-{0}', 0, 'confluence.prefs.notify.for.my.own.actions', 1, false, 0, '', '', 0, 0, NULL);
INSERT INTO os_propertyentry (entity_name, entity_id, entity_key, key_type, boolean_val, double_val, string_val, text_val, long_val, int_val, date_val) VALUES ('USERPROPS-{0}', 0, 'confluence.prefs.watch.my.own.content', 1, false, 0, '', '', 0, 0, NULL);
INSERT INTO os_propertyentry (entity_name, entity_id, entity_key, key_type, boolean_val, double_val, string_val, text_val, long_val, int_val, date_val) VALUES ('USERPROPS-{0}', 0, 'confluence.prefs.email.show.diff', 1, false, 0 , '', '', 0, 0, NULL);
INSERT INTO os_propertyentry (entity_name, entity_id, entity_key, key_type, boolean_val, double_val, string_val, text_val, long_val, int_val, date_val) VALUES ('USERPROPS-{0}', 0, 'confluence.prefs.email.mimetype', 5, false, 0, 'text/html', '', 0, 0, NULL);
INSERT INTO os_propertyentry (entity_name, entity_id, entity_key, key_type, boolean_val, double_val, string_val, text_val, long_val, int_val, date_val) VALUES ('USERPROPS-{0}', 0, 'confluence.prefs.notify.on.new.followers', 1, false, 0, '', '', 0, 0, NULL);
INSERT INTO os_propertyentry (entity_name, entity_id, entity_key, key_type, boolean_val, double_val, string_val, text_val, long_val, int_val, date_val) VALUES ('USERPROPS-{0}', 0, 'confluence.prefs.daily.summary.receive.updates.set', 1, true, 0, '', '', 0, 0, NULL);
INSERT INTO os_propertyentry (entity_name, entity_id, entity_key, key_type, boolean_val, double_val, string_val, text_val, long_val, int_val, date_val) VALUES ('USERPROPS-{0}', 0, 'confluence.prefs.daily.summary.receive.updates', 1, false, 0, '', '', 0, 0, NULL);
Save this file as template.sql locally.
Gather Support SQL Generator, a python script, that will take a CSV file and an SQL template as its input. For each row in the CSV file, the columns are swapped into the template. If you've ever needed to write SQL for large scale fixes, this excellent tool will help you automate the SQL queries that you will need to write.
Steps to utilize the SQL Generator script:
- Download the files in the SQL Generator zip file.
- Extract this into a folder of your choice.
- Copy your files input.csv and template.sql into this extracted folder
- Ensure that you have Python 2.7 or later installed on the workstation you will perform the query on
- Run the command python generate.py and then save the file output.sql once this has finished.
- This will create several rows to modify in the OS_PROPERTYENTRY table for each user in the system.
- Using your Database tools, run the file output.sql against the database to insert the rows for your users.
Be patient, this may take some time to complete at scale. - Start your Confluence instance
- Spot check user profiles to ensure that that options are unchecked as desired.
This solution will not address new users as they are added to your instance, and does not set a default setting for email preferences when new users are added. This is a known limitation of the solution herein.
This solution was tested in Confluence 6.x. Future versions may change this solution.