1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-24 19:33:07 +01:00

Delete single conversation forever

This commit is contained in:
FreeScout 2020-01-03 01:03:36 -08:00
parent d69a5bfcda
commit b1d0ae9fee
5 changed files with 80 additions and 4 deletions

View File

@ -238,13 +238,33 @@ class Attachment extends Model
} }
$attachments = self::whereIn('id', $attachment_ids)->get(); $attachments = self::whereIn('id', $attachment_ids)->get();
// Delete from disk
self::deleteForever($attachments);
}
/**
* Delete attachments by thread IDs.
*/
public static function deleteByThreadIds($thread_ids)
{
if (!count($thread_ids)) {
return;
}
$attachments = self::whereIn('thread_id', $thread_ids)->get();
// Delete from disk
self::deleteForever($attachments);
}
public static function deleteForever($attachments)
{
// Delete from disk // Delete from disk
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
Storage::delete($attachment->getStorageFilePath()); Storage::delete($attachment->getStorageFilePath());
} }
// Delete from DB // Delete from DB
self::whereIn('id', $attachment_ids)->delete(); self::whereIn('id', $attachments->pluck('id')->toArray())->delete();
} }
/** /**

View File

@ -1343,6 +1343,27 @@ class Conversation extends Model
\Eventy::action('conversation.status_changed', $this, $user, $changed_on_reply = false, $prev_status); \Eventy::action('conversation.status_changed', $this, $user, $changed_on_reply = false, $prev_status);
} }
public function deleteForever()
{
self::deleteConversationsForever([$this->id]);
}
public static function deleteConversationsForever($conversation_ids)
{
\Eventy::action('conversations.before_delete_forever', $conversation_ids);
//$conversation_ids = $conversations->pluck('id')->toArray();
// Delete attachments.
$thread_ids = Thread::whereIn('conversation_id', $conversation_ids)->pluck('id')->toArray();
Attachment::deleteByThreadIds($thread_ids);
// Delete threads.
Thread::whereIn('conversation_id', $conversation_ids)->delete();
// Delete conversations.
Conversation::whereIn('id', $conversation_ids)->delete();
}
// /** // /**
// * Get conversation meta data as array. // * Get conversation meta data as array.
// */ // */

View File

@ -1431,6 +1431,32 @@ class ConversationsController extends Controller
} }
break; break;
// Delete conversation forever
case 'delete_conversation_forever':
$conversation = Conversation::find($request->conversation_id);
if (!$conversation) {
$response['msg'] = __('Conversation not found');
} elseif (!$user->can('delete', $conversation)) {
$response['msg'] = __('Not enough permissions');
}
if (!$response['msg']) {
$folder_id = $conversation->getCurrentFolder();
$mailbox = $conversation->mailbox;
$conversation->deleteForever();
// Recalculate only old and new folders
$mailbox->updateFoldersCounters();
$response['redirect_url'] = route('mailboxes.view.folder', ['id' => $conversation->mailbox_id, 'folder_id' => $folder_id]);
$response['status'] = 'success';
\Session::flash('flash_success_floating', __('Conversation deleted'));
}
break;
// Restore conversation // Restore conversation
case 'restore_conversation': case 'restore_conversation':
$conversation = Conversation::find($request->conversation_id); $conversation = Conversation::find($request->conversation_id);

9
public/js/main.js vendored
View File

@ -955,7 +955,7 @@ function initConversation()
}); });
// Delete conversation // Delete conversation
jQuery(".conv-delete").click(function(e){ jQuery(".conv-delete,.conv-delete-forever").click(function(e){
var confirm_html = '<div>'+ var confirm_html = '<div>'+
'<div class="text-center">'+ '<div class="text-center">'+
'<div class="text-larger margin-top-10">'+Lang.get("messages.confirm_delete_conversation")+'</div>'+ '<div class="text-larger margin-top-10">'+Lang.get("messages.confirm_delete_conversation")+'</div>'+
@ -966,13 +966,18 @@ function initConversation()
'</div>'+ '</div>'+
'</div>'; '</div>';
var action = 'delete_conversation';
if ($(this).hasClass('conv-delete-forever')) {
action = 'delete_conversation_forever';
}
showModalDialog(confirm_html, { showModalDialog(confirm_html, {
on_show: function(modal) { on_show: function(modal) {
modal.children().find('.delete-conversation-ok:first').click(function(e) { modal.children().find('.delete-conversation-ok:first').click(function(e) {
modal.modal('hide'); modal.modal('hide');
fsAjax( fsAjax(
{ {
action: 'delete_conversation', action: action,
conversation_id: getGlobalAttr('conversation_id') conversation_id: getGlobalAttr('conversation_id')
}, },
laroute.route('conversations.ajax'), laroute.route('conversations.ajax'),

View File

@ -31,7 +31,11 @@
<li><a href="{{ route('conversations.ajax_html', ['action' => <li><a href="{{ route('conversations.ajax_html', ['action' =>
'move_conv']) }}?conversation_id={{ $conversation->id }}" data-trigger="modal" data-modal-title="{{ __("Move Conversation") }}" data-modal-no-footer="true" data-modal-on-show="initMoveConv"><i class="glyphicon glyphicon-log-out"></i> {{ __("Move") }}</a></li> 'move_conv']) }}?conversation_id={{ $conversation->id }}" data-trigger="modal" data-modal-title="{{ __("Move Conversation") }}" data-modal-no-footer="true" data-modal-on-show="initMoveConv"><i class="glyphicon glyphicon-log-out"></i> {{ __("Move") }}</a></li>
@endif @endif
@if ($conversation->state != App\Conversation::STATE_DELETED)
<li><a href="#" class="conv-delete"><i class="glyphicon glyphicon-trash"></i> {{ __("Delete") }}</a></li> <li><a href="#" class="conv-delete"><i class="glyphicon glyphicon-trash"></i> {{ __("Delete") }}</a></li>
@else
<li><a href="#" class="conv-delete-forever"><i class="glyphicon glyphicon-trash"></i> {{ __("Delete Forever") }}</a></li>
@endif
@action('conversation.append_action_buttons', $conversation, $mailbox) @action('conversation.append_action_buttons', $conversation, $mailbox)
</ul> </ul>
</div> </div>