diff --git a/app/Http/Controllers/Account/CreateController.php b/app/Http/Controllers/Account/CreateController.php index 0aa93172d6..928f656b69 100644 --- a/app/Http/Controllers/Account/CreateController.php +++ b/app/Http/Controllers/Account/CreateController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Account; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\AccountFormRequest; use FireflyIII\Models\AccountType; @@ -42,6 +43,10 @@ use Log; class CreateController extends Controller { use ModelInformation; + + /** @var AttachmentHelperInterface Helper for attachments. */ + private $attachments; + /** @var AccountRepositoryInterface The account repository */ private $repository; @@ -60,7 +65,8 @@ class CreateController extends Controller app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('title', (string) trans('firefly.accounts')); - $this->repository = app(AccountRepositoryInterface::class); + $this->repository = app(AccountRepositoryInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); return $next($request); } @@ -141,6 +147,16 @@ class CreateController extends Controller $frontPage[] = $account->id; app('preferences')->set('frontPageAccounts', $frontPage); } + + // store attachment(s): + /** @var array $files */ + $files = $request->hasFile('attachments') ? $request->file('attachments') : null; + $this->attachments->saveAttachmentsForModel($account, $files); + + if (count($this->attachments->getMessages()->get('attachments')) > 0) { + $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore + } + // redirect to previous URL. $redirect = redirect($this->getPreviousUri('accounts.create.uri')); if (1 === (int) $request->get('create_another')) { diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php index cce2a91275..66d0620f55 100644 --- a/app/Http/Controllers/Account/EditController.php +++ b/app/Http/Controllers/Account/EditController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Account; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\AccountFormRequest; use FireflyIII\Models\Account; @@ -48,6 +49,9 @@ class EditController extends Controller /** @var AccountRepositoryInterface The account repository */ private $repository; + /** @var AttachmentHelperInterface Helper for attachments. */ + private $attachments; + /** * EditController constructor. */ @@ -63,6 +67,7 @@ class EditController extends Controller $this->repository = app(AccountRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); return $next($request); } @@ -185,6 +190,17 @@ class EditController extends Controller $request->session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name])); app('preferences')->mark(); + // store new attachments + // store attachment(s): + /** @var array $files */ + $files = $request->hasFile('attachments') ? $request->file('attachments') : null; + $this->attachments->saveAttachmentsForModel($account, $files); + + if (count($this->attachments->getMessages()->get('attachments')) > 0) { + $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore + } + + // redirect $redirect = redirect($this->getPreviousUri('accounts.edit.uri')); if (1 === (int) $request->get('return_to_edit')) { // set value so edit routine will not overwrite URL: diff --git a/app/Http/Controllers/Budget/CreateController.php b/app/Http/Controllers/Budget/CreateController.php index 607e3ea84e..111491c5e7 100644 --- a/app/Http/Controllers/Budget/CreateController.php +++ b/app/Http/Controllers/Budget/CreateController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Budget; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\BudgetFormStoreRequest; use FireflyIII\Models\AutoBudget; @@ -41,6 +42,9 @@ class CreateController extends Controller /** @var BudgetRepositoryInterface The budget repository */ private $repository; + /** @var AttachmentHelperInterface Helper for attachments. */ + private $attachments; + /** * CreateController constructor. * @@ -56,6 +60,7 @@ class CreateController extends Controller app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-tasks'); $this->repository = app(BudgetRepositoryInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); return $next($request); } diff --git a/app/Http/Controllers/Budget/EditController.php b/app/Http/Controllers/Budget/EditController.php index ad79b1cced..f0b06e83b1 100644 --- a/app/Http/Controllers/Budget/EditController.php +++ b/app/Http/Controllers/Budget/EditController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Budget; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\BudgetFormUpdateRequest; use FireflyIII\Models\AutoBudget; @@ -43,6 +44,9 @@ class EditController extends Controller /** @var BudgetRepositoryInterface The budget repository */ private $repository; + /** @var AttachmentHelperInterface Helper for attachments. */ + private $attachments; + /** * EditController constructor. * @@ -57,6 +61,7 @@ class EditController extends Controller app('view')->share('title', (string) trans('firefly.budgets')); app('view')->share('mainTitleIcon', 'fa-tasks'); $this->repository = app(BudgetRepositoryInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); return $next($request); } diff --git a/app/Http/Controllers/Category/CreateController.php b/app/Http/Controllers/Category/CreateController.php index b9990df11c..a8da02a46c 100644 --- a/app/Http/Controllers/Category/CreateController.php +++ b/app/Http/Controllers/Category/CreateController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Category; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\CategoryFormRequest; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; @@ -41,6 +42,9 @@ class CreateController extends Controller /** @var CategoryRepositoryInterface The category repository */ private $repository; + /** @var AttachmentHelperInterface Helper for attachments. */ + private $attachments; + /** * CategoryController constructor. * @@ -55,6 +59,7 @@ class CreateController extends Controller app('view')->share('title', (string) trans('firefly.categories')); app('view')->share('mainTitleIcon', 'fa-bar-chart'); $this->repository = app(CategoryRepositoryInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); return $next($request); } diff --git a/app/Http/Controllers/Category/EditController.php b/app/Http/Controllers/Category/EditController.php index 3a37863f4b..ffb8efe65b 100644 --- a/app/Http/Controllers/Category/EditController.php +++ b/app/Http/Controllers/Category/EditController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Category; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\CategoryFormRequest; use FireflyIII\Models\Category; @@ -43,6 +44,9 @@ class EditController extends Controller /** @var CategoryRepositoryInterface The category repository */ private $repository; + /** @var AttachmentHelperInterface Helper for attachments. */ + private $attachments; + /** * CategoryController constructor. * @@ -57,6 +61,7 @@ class EditController extends Controller app('view')->share('title', (string) trans('firefly.categories')); app('view')->share('mainTitleIcon', 'fa-bar-chart'); $this->repository = app(CategoryRepositoryInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); return $next($request); } diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index c2a14d6e04..59f05f36cd 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; use Carbon\Carbon; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Requests\PiggyBankFormRequest; use FireflyIII\Models\PiggyBank; use FireflyIII\Repositories\Account\AccountRepositoryInterface; @@ -55,6 +56,9 @@ class PiggyBankController extends Controller /** @var PiggyBankRepositoryInterface Piggy bank repository. */ private $piggyRepos; + /** @var AttachmentHelperInterface Helper for attachments. */ + private $attachments; + /** * PiggyBankController constructor. * @@ -69,6 +73,7 @@ class PiggyBankController extends Controller app('view')->share('title', (string) trans('firefly.piggyBanks')); app('view')->share('mainTitleIcon', 'fa-sort-amount-asc'); + $this->attachments = app(AttachmentHelperInterface::class); $this->piggyRepos = app(PiggyBankRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->accountRepos = app(AccountRepositoryInterface::class); diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 36a4f4f4a5..6ebd1c6499 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers; use Carbon\Carbon; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Http\Requests\TagFormRequest; use FireflyIII\Models\Tag; @@ -45,6 +46,9 @@ class TagController extends Controller /** @var TagRepositoryInterface The tag repository. */ protected $repository; + /** @var AttachmentHelperInterface Helper for attachments. */ + private $attachments; + /** * TagController constructor. */ @@ -55,10 +59,12 @@ class TagController extends Controller $this->middleware( function ($request, $next) { - $this->repository = app(TagRepositoryInterface::class); app('view')->share('title', (string) trans('firefly.tags')); app('view')->share('mainTitleIcon', 'fa-tags'); + $this->attachments = app(AttachmentHelperInterface::class); + $this->repository = app(TagRepositoryInterface::class); + return $next($request); } );