@@ -12,37 +12,41 @@ Deleting Records
1212Removing Tickets (And Their Articles)
1313-------------------------------------
1414
15+ Delete a ticket (specified by database ID):
16+
1517.. code-block :: ruby
1618
17- # Delete a ticket (specified by database ID)
18- >> Ticket .find(4 ).destroy
19+ Ticket .find(4 ).destroy
1920
20- # Delete all tickets
21- >> Ticket .destroy_all
21+ Delete all tickets:
2222
23- # Keep some tickets (specified by database ID); delete the rest
24- >> tickets_to_keep = [1 , 2 , 3 ]
25- >> Ticket .where.not(id: tickets_to_keep).destroy_all
23+ .. code-block :: ruby
2624
27- Removing Users
28- --------------
25+ Ticket .destroy_all
2926
30- .. warning ::
27+ Keep some tickets (specified by database ID); delete the rest:
28+
29+ .. code-block :: ruby
30+
31+ tickets_to_keep = [1 , 2 , 3 ]
32+
33+ .. code-block :: ruby
3134
32- Customers **may not ** be deleted while they have tickets remaining in the
33- system.
35+ Ticket .where.not(id: tickets_to_keep).destroy_all
3436
35- As such, the examples below will delete not only the specified customers,
36- but **all tickets associated with them **, as well. Below commands remove
37- upon executing without any further warnings.
37+ Removing Users
38+ --------------
3839
3940.. hint ::
4041
41- If you're not sure what to do and need to learn more about what Zammad does
42- upon removing users, please consider using Zammad's UI options in stead .
42+ Console based deletion is not recommended. Instead, use Zammad's
43+ :admin-docs: ` data privacy </system/data-privacy.html> ` feature .
4344
44- Our documentation for the :admin-docs: `data privacy </system/data-privacy.html> `
45- function will help you a lot!
45+ .. warning ::
46+
47+ Customers **can't be ** deleted while they have tickets remaining in the
48+ system. Because of that, the examples below delete **all tickets associated
49+ with them **, as well. The commands don't require a confirmation, be careful.
4650
4751Removing users is possible in 2 ways: A single user and in bulk.
4852
@@ -52,71 +56,87 @@ Removing users is possible in 2 ways: A single user and in bulk.
5256
5357 .. code-block :: ruby
5458
55- >> User .find_by(email: ' <email address>' ).destroy
59+ User .find_by(email: ' <email address>' ).destroy
5660
5761 .. tab :: Remove several users
5862
5963 .. code-block :: ruby
6064
61- >> User .where(
62- email: [' <email address 1>' , ' <email address 2>' ]
63- ).destroy_all
65+ User .where(
66+ email: [' <email address 1>' , ' <email address 2>' ]
67+ ).destroy_all
6468
6569 Removing Organizations
6670----------------------
6771
6872.. note :: Removing an organization does **not** delete associated customers.
6973
7074Step 1: Select organizations
75+ By "active" status:
76+
7177 .. code-block :: ruby
7278
73- # by "active" status
74- >> organizations = Organization .where(active: false )
79+ organizations = Organization .where(active: false )
80+
81+ By name:
82+
83+ .. code-block :: ruby
84+
85+ organizations = Organization .where(name: ' Acme' )
86+
87+ By partial match on notes content:
7588
76- # by name
77- >> organizations = Organization .where(name: ' Acme' )
89+ .. code-block :: ruby
7890
79- # by partial match on notes
80- >> organizations = Organization .where(' note LIKE ?' , ' %foo%' )
91+ organizations = Organization .where(' note LIKE ?' , ' %foo%' )
8192
8293 Step 2: Preview affected organizations
8394 .. code-block :: ruby
8495
85- >> puts organizations.map { |org | " ORGANIZATION #{ org.name } " }.join(" \n " )
96+ puts organizations.map { |org | " ORGANIZATION #{ org.name } " }.join(" \n " )
8697
8798 Step 3: Proceed with deletion
8899 .. code-block :: ruby
89100
90- >> organizations.each do |org |
91- puts %{ Preparing deletion of organization "#{ org.name } "...}
101+ organizations.each do |org |
102+ puts %{ Preparing deletion of organization "#{ org.name } "...}
92103
93- org.members.each do |member |
94- puts " Removing #{ member.fullname } from organization..."
95- member.update!(organization_id: nil )
96- end
104+ org.members.each do |member |
105+ puts " Removing #{ member.fullname } from organization..."
106+ member.update!(organization_id: nil )
107+ end
97108
98- puts " Deleting #{ org.name } ..."
99- org.destroy
100- end
109+ puts " Deleting #{ org.name } ..."
110+ org.destroy
111+ end
101112
102113 Removing System Records
103114-----------------------
104115
116+ Remove all online notifications:
117+
118+ .. code-block :: ruby
119+
120+ OnlineNotification .destroy_all
121+
122+ Remove all entries from the Activity Stream (dashboard):
123+
124+ .. code-block :: ruby
125+
126+ ActivityStream .destroy_all
127+
128+ Remove entries for all recently viewed objects (tickets, users, organizations):
129+
105130.. code-block :: ruby
106131
107- # Remove all online notifications
108- >> OnlineNotification .destroy_all
132+ RecentView .destroy_all
109133
110- # Remove all entries from the Activity Stream (dashboard)
111- >> ActivityStream .destroy_all
134+ Remove all history information from tickets, users and organizations
135+ (dangerous!):
112136
113- # Remove entries for all recently viewed objects
114- # (tickets, users, organizations)
115- >> RecentView .destroy_all
137+ .. code-block :: ruby
116138
117- # Remove all history information from tickets, users and organizations
118- # (dangerous!)
119- >> History .destroy_all
139+ History .destroy_all
120140
121141 .. _dangerzone_reset_zammad :
122142
@@ -133,7 +153,16 @@ Reset Zammad Installation
133153
134154.. code-block :: sh
135155
136- $ rake db:drop
137- $ rake db:create
138- $ rake db:migrate
139- $ rake db:seed
156+ rake db:drop
157+
158+ .. code-block :: sh
159+
160+ rake db:create
161+
162+ .. code-block :: sh
163+
164+ rake db:migrate
165+
166+ .. code-block :: sh
167+
168+ rake db:seed
0 commit comments