mirror of
https://github.com/freescout-helpdesk/freescout.git
synced 2024-11-24 11:22:42 +01:00
Delete single conversation forever
This commit is contained in:
parent
d69a5bfcda
commit
b1d0ae9fee
@ -238,13 +238,33 @@ class Attachment extends Model
|
||||
}
|
||||
$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
|
||||
foreach ($attachments as $attachment) {
|
||||
Storage::delete($attachment->getStorageFilePath());
|
||||
}
|
||||
|
||||
// Delete from DB
|
||||
self::whereIn('id', $attachment_ids)->delete();
|
||||
self::whereIn('id', $attachments->pluck('id')->toArray())->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1343,6 +1343,27 @@ class Conversation extends Model
|
||||
\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.
|
||||
// */
|
||||
|
@ -1431,6 +1431,32 @@ class ConversationsController extends Controller
|
||||
}
|
||||
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
|
||||
case 'restore_conversation':
|
||||
$conversation = Conversation::find($request->conversation_id);
|
||||
|
9
public/js/main.js
vendored
9
public/js/main.js
vendored
@ -955,7 +955,7 @@ function initConversation()
|
||||
});
|
||||
|
||||
// Delete conversation
|
||||
jQuery(".conv-delete").click(function(e){
|
||||
jQuery(".conv-delete,.conv-delete-forever").click(function(e){
|
||||
var confirm_html = '<div>'+
|
||||
'<div class="text-center">'+
|
||||
'<div class="text-larger margin-top-10">'+Lang.get("messages.confirm_delete_conversation")+'</div>'+
|
||||
@ -966,13 +966,18 @@ function initConversation()
|
||||
'</div>'+
|
||||
'</div>';
|
||||
|
||||
var action = 'delete_conversation';
|
||||
if ($(this).hasClass('conv-delete-forever')) {
|
||||
action = 'delete_conversation_forever';
|
||||
}
|
||||
|
||||
showModalDialog(confirm_html, {
|
||||
on_show: function(modal) {
|
||||
modal.children().find('.delete-conversation-ok:first').click(function(e) {
|
||||
modal.modal('hide');
|
||||
fsAjax(
|
||||
{
|
||||
action: 'delete_conversation',
|
||||
action: action,
|
||||
conversation_id: getGlobalAttr('conversation_id')
|
||||
},
|
||||
laroute.route('conversations.ajax'),
|
||||
|
@ -31,7 +31,11 @@
|
||||
<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>
|
||||
@endif
|
||||
@if ($conversation->state != App\Conversation::STATE_DELETED)
|
||||
<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)
|
||||
</ul>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user