Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Also delete attachments.
James Colef5fb6c063b71
diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.phpindex 5b74fbb140..ebeda10cb0 100644--- a/app/Http/Controllers/AttachmentController.php+++ b/app/Http/Controllers/AttachmentController.php@@ -11,6 +11,7 @@ use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;use Input;use Preferences;use Session;+use URL;use View;/**@@ -45,6 +46,41 @@ class AttachmentController extends Controllerreturn 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*/@@ -97,13 +133,13 @@ class AttachmentController extends Controllerif (intval(Input::get('return_to_edit')) === 1) {// 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]);}// redirect to previous URL.- return redirect(Session::get('accounts.edit.url'));+ return redirect(Session::get('attachment.edit.url'));}diff --git a/app/Repositories/Attachment/AttachmentRepository.php b/app/Repositories/Attachment/AttachmentRepository.phpindex d8a86a45b6..5ae2b899fb 100644--- a/app/Repositories/Attachment/AttachmentRepository.php+++ b/app/Repositories/Attachment/AttachmentRepository.php@@ -29,4 +29,19 @@ class AttachmentRepository implements AttachmentRepositoryInterfacereturn $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();+ }}diff --git a/app/Repositories/Attachment/AttachmentRepositoryInterface.php b/app/Repositories/Attachment/AttachmentRepositoryInterface.phpindex 59a1777cb4..9998ce9d8f 100644--- a/app/Repositories/Attachment/AttachmentRepositoryInterface.php+++ b/app/Repositories/Attachment/AttachmentRepositoryInterface.php@@ -19,4 +19,12 @@ interface AttachmentRepositoryInterface* @return Attachment*/public function update(Attachment $attachment, array $attachmentData);++ /**+ * @param Attachment $attachment+ *+ * @return bool+ */+ public function destroy(Attachment $attachment);}+diff --git a/resources/lang/en/firefly.php b/resources/lang/en/firefly.phpindex bfd130b1ab..69b5fa0190 100644--- a/resources/lang/en/firefly.php+++ b/resources/lang/en/firefly.php@@ -24,6 +24,8 @@ return ['attachments' => 'Attachments','edit_attachment' => 'Edit attachment ":name"','update_attachment' => 'Update attachment',+ 'delete_attachment' => 'Delete attachment ":name"',+ 'attachment_deleted' => 'Deleted attachment ":name"',// tour:'prev' => 'Prev',diff --git a/resources/lang/en/form.php b/resources/lang/en/form.phpindex 1822182400..9b2275cd9f 100644--- a/resources/lang/en/form.php+++ b/resources/lang/en/form.php@@ -67,6 +67,7 @@ return ['mime' => 'Mime type','size' => 'Size',+'delete_account' => 'Delete account ":name"','delete_bill' => 'Delete bill ":name"','delete_budget' => 'Delete budget ":name"',@@ -74,7 +75,9 @@ return ['delete_currency' => 'Delete currency ":name"','delete_piggyBank' => 'Delete piggy bank ":name"','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"?','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"?',diff --git a/resources/twig/attachments/delete.twig b/resources/twig/attachments/delete.twignew file mode 100644index 0000000000..3f8a7bb077--- /dev/null+++ b/resources/twig/attachments/delete.twig@@ -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 %}