mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-21 19:47:48 +00:00
Also delete attachments.
This commit is contained in:
@@ -11,6 +11,7 @@ use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
|||||||
use Input;
|
use Input;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Session;
|
use Session;
|
||||||
|
use URL;
|
||||||
use View;
|
use View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,6 +46,41 @@ class AttachmentController extends Controller
|
|||||||
return view('attachments.edit', compact('attachment', 'subTitleIcon', 'subTitle'));
|
return view('attachments.edit', compact('attachment', 'subTitleIcon', 'subTitle'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Attachment $attachment
|
||||||
|
*
|
||||||
|
* @return \Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function delete(Attachment $attachment)
|
||||||
|
{
|
||||||
|
$subTitle = trans('firefly.delete_attachment', ['name' => $attachment->filename]);
|
||||||
|
|
||||||
|
// put previous url in session
|
||||||
|
Session::put('attachment.delete.url', URL::previous());
|
||||||
|
Session::flash('gaEventCategory', 'attachments');
|
||||||
|
Session::flash('gaEventAction', 'delete-attachment');
|
||||||
|
|
||||||
|
return view('attachments.delete', compact('attachment', 'subTitle'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param AttachmentRepositoryInterface $repository
|
||||||
|
* @param Attachment $attachment
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function destroy(AttachmentRepositoryInterface $repository, Attachment $attachment)
|
||||||
|
{
|
||||||
|
$name = $attachment->filename;
|
||||||
|
|
||||||
|
$repository->destroy($attachment);
|
||||||
|
|
||||||
|
Session::flash('success', trans('firefly.attachment_deleted', ['name' => $name]));
|
||||||
|
Preferences::mark();
|
||||||
|
|
||||||
|
return redirect(Session::get('attachment.delete.url'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Attachment $attachment
|
* @param Attachment $attachment
|
||||||
*/
|
*/
|
||||||
@@ -97,13 +133,13 @@ class AttachmentController extends Controller
|
|||||||
|
|
||||||
if (intval(Input::get('return_to_edit')) === 1) {
|
if (intval(Input::get('return_to_edit')) === 1) {
|
||||||
// set value so edit routine will not overwrite URL:
|
// set value so edit routine will not overwrite URL:
|
||||||
Session::put('accounts.edit.fromUpdate', true);
|
Session::put('attachment.edit.fromUpdate', true);
|
||||||
|
|
||||||
return redirect(route('attachment.edit', [$attachment->id]))->withInput(['return_to_edit' => 1]);
|
return redirect(route('attachment.edit', [$attachment->id]))->withInput(['return_to_edit' => 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// redirect to previous URL.
|
// redirect to previous URL.
|
||||||
return redirect(Session::get('accounts.edit.url'));
|
return redirect(Session::get('attachment.edit.url'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,4 +29,19 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
|||||||
return $attachment;
|
return $attachment;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Attachment $attachment
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function destroy(Attachment $attachment)
|
||||||
|
{
|
||||||
|
/** @var \FireflyIII\Helpers\Attachments\AttachmentHelperInterface $helper */
|
||||||
|
$helper = app('FireflyIII\Helpers\Attachments\AttachmentHelperInterface');
|
||||||
|
|
||||||
|
$file = $helper->getAttachmentLocation($attachment);
|
||||||
|
unlink($file);
|
||||||
|
$attachment->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,4 +19,12 @@ interface AttachmentRepositoryInterface
|
|||||||
* @return Attachment
|
* @return Attachment
|
||||||
*/
|
*/
|
||||||
public function update(Attachment $attachment, array $attachmentData);
|
public function update(Attachment $attachment, array $attachmentData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Attachment $attachment
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function destroy(Attachment $attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,6 +24,8 @@ return [
|
|||||||
'attachments' => 'Attachments',
|
'attachments' => 'Attachments',
|
||||||
'edit_attachment' => 'Edit attachment ":name"',
|
'edit_attachment' => 'Edit attachment ":name"',
|
||||||
'update_attachment' => 'Update attachment',
|
'update_attachment' => 'Update attachment',
|
||||||
|
'delete_attachment' => 'Delete attachment ":name"',
|
||||||
|
'attachment_deleted' => 'Deleted attachment ":name"',
|
||||||
|
|
||||||
// tour:
|
// tour:
|
||||||
'prev' => 'Prev',
|
'prev' => 'Prev',
|
||||||
|
@@ -67,6 +67,7 @@ return [
|
|||||||
'mime' => 'Mime type',
|
'mime' => 'Mime type',
|
||||||
'size' => 'Size',
|
'size' => 'Size',
|
||||||
|
|
||||||
|
|
||||||
'delete_account' => 'Delete account ":name"',
|
'delete_account' => 'Delete account ":name"',
|
||||||
'delete_bill' => 'Delete bill ":name"',
|
'delete_bill' => 'Delete bill ":name"',
|
||||||
'delete_budget' => 'Delete budget ":name"',
|
'delete_budget' => 'Delete budget ":name"',
|
||||||
@@ -74,7 +75,9 @@ return [
|
|||||||
'delete_currency' => 'Delete currency ":name"',
|
'delete_currency' => 'Delete currency ":name"',
|
||||||
'delete_piggyBank' => 'Delete piggy bank ":name"',
|
'delete_piggyBank' => 'Delete piggy bank ":name"',
|
||||||
'delete_journal' => 'Delete transaction with description ":description"',
|
'delete_journal' => 'Delete transaction with description ":description"',
|
||||||
|
'delete_attachment' => 'Delete attachment ":name"',
|
||||||
|
|
||||||
|
'attachment_areYouSure' => 'Are you sure you want to delete the attachment named ":name"?',
|
||||||
'account_areYouSure' => 'Are you sure you want to delete the account named ":name"?',
|
'account_areYouSure' => 'Are you sure you want to delete the account named ":name"?',
|
||||||
'bill_areYouSure' => 'Are you sure you want to delete the bill named ":name"?',
|
'bill_areYouSure' => 'Are you sure you want to delete the bill named ":name"?',
|
||||||
'budget_areYouSure' => 'Are you sure you want to delete the budget named ":name"?',
|
'budget_areYouSure' => 'Are you sure you want to delete the budget named ":name"?',
|
||||||
|
34
resources/twig/attachments/delete.twig
Normal file
34
resources/twig/attachments/delete.twig
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{% extends "./layout/default.twig" %}
|
||||||
|
|
||||||
|
{% block breadcrumbs %}
|
||||||
|
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute().getName(), attachment) }}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{{ Form.open({'class' : 'form-horizontal','id' : 'destroy','url' : route('attachment.destroy',attachment.id)}) }}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-6 col-lg-offset-3 col-md-12 col-sm-12">
|
||||||
|
<div class="box box-danger">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h3 class="box-title">{{ trans('form.delete_attachment', {'name': attachment.filename}) }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body">
|
||||||
|
<p class="text-danger">
|
||||||
|
{{ trans('form.permDeleteWarning') }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{{ trans('form.attachment_areYouSure', {'name': attachment.filename}) }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="box-footer">
|
||||||
|
<input type="submit" name="submit" value="{{ trans('form.deletePermanently') }}" class="btn pull-right btn-danger"/>
|
||||||
|
<a href="{{ URL.previous() }}" class="btn-default btn">{{ trans('form.cancel') }}</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{ Form.close|raw }}
|
||||||
|
{% endblock %}
|
Reference in New Issue
Block a user