Deleting a User from the Database

Description

This SQL will delete/repoint references to a user.  This SQL needs to be run in the DB and once complete, you will need to flush the cache for the user to be removed from the system

Code

USERID_TO_DELETE  = dotcms.org.2804
ADMIN_USER_TO_CHANGE_TO = dotcms.org.1

update inode set owner = 'dotcms.org.1' where owner = 'dotcms.org.2804';
update contentlet set mod_user =  'dotcms.org.1' where mod_user  = 'dotcms.org.2804';
update file_asset set mod_user =  'dotcms.org.1' where mod_user  = 'dotcms.org.2804';
update containers set mod_user =  'dotcms.org.1' where mod_user  = 'dotcms.org.2804';
update template set mod_user =  'dotcms.org.1' where mod_user  = 'dotcms.org.2804';
update htmlpage set mod_user =  'dotcms.org.1' where mod_user  = 'dotcms.org.2804';
update links set mod_user =  'dotcms.org.1' where mod_user  = 'dotcms.org.2804';

update contentlet_version_info set locked_by='dotcms.org.1' where locked_by  = 'dotcms.org.2804';
update htmlpage_version_info set locked_by='dotcms.org.1' where locked_by  = 'dotcms.org.2804';
update container_version_info set locked_by='dotcms.org.1' where locked_by  = 'dotcms.org.2804';
update fileasset_version_info set locked_by='dotcms.org.1' where locked_by  = 'dotcms.org.2804';
update template_version_info set locked_by='dotcms.org.1' where locked_by  = 'dotcms.org.2804';
update link_version_info set locked_by='dotcms.org.1' where locked_by  = 'dotcms.org.2804';

update workflow_task set created_by='dotcms.org.1' where created_by  = 'dotcms.org.2804';
update workflow_task set assigned_to='dotcms.org.1' where assigned_to  = 'dotcms.org.2804';
update workflow_comment set posted_by='dotcms.org.1' where posted_by  = 'dotcms.org.2804';


delete from permission where roleid in (select id from cms_role where role_key='dotcms.org.2804');
delete from users_cms_roles where user_id= 'dotcms.org.2804';
delete from cms_role where role_key='dotcms.org.2804';
delete from user_ where userid = 'dotcms.org.2804';