Refactor installer.

This commit is contained in:
James Cole 2019-03-30 11:03:39 +01:00
parent 5b1fb5354e
commit c07ef3658b
18 changed files with 230 additions and 327 deletions

View File

@ -26,9 +26,7 @@ namespace FireflyIII\Api\V1\Controllers;
use FireflyIII\Api\V1\Requests\TransactionRequest;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionGroup;
@ -252,7 +250,6 @@ class TransactionController extends Controller
* @param TransactionRequest $request
*
* @param JournalRepositoryInterface $repository
* TODO refactor me.
*
* @throws FireflyException
* @return JsonResponse

View File

@ -1,53 +0,0 @@
<?php
/**
* StoredTransactionJournal.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Events;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Queue\SerializesModels;
/**
* Class StoredTransactionJournal.
* @deprecated
* @codeCoverageIgnore
*/
class StoredTransactionJournal extends Event
{
use SerializesModels;
/** @var TransactionJournal The journal that was stored. */
public $journal;
/**
* Create a new event instance.
*
* @param TransactionJournal $journal
*/
public function __construct(TransactionJournal $journal)
{
throw new FireflyException('The StoredTransactionJournal event is deprecated.');
$this->journal = $journal;
}
}

View File

@ -1,53 +0,0 @@
<?php
/**
* UpdatedTransactionJournal.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Events;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Queue\SerializesModels;
/**
* Class UpdatedTransactionJournal.
* @deprecated
* @codeCoverageIgnore
*
*/
class UpdatedTransactionJournal extends Event
{
use SerializesModels;
/** @var TransactionJournal The journal. */
public $journal;
/**
* Create a new event instance.
*
* @param TransactionJournal $journal
*/
public function __construct(TransactionJournal $journal)
{
throw new FireflyException('The UpdatedTransactionJournal event is deprecated.');
$this->journal = $journal;
}
}

View File

@ -101,10 +101,10 @@ class TransactionJournalFactory
*
* @param array $data
*
* @return Collection
* @return TransactionGroup
* @throws Exception
*/
public function create(array $data): Collection
public function create(array $data): TransactionGroup
{
$data = new NullArrayObject($data);
Log::debug('Start of TransactionJournalFactory::create()');
@ -193,9 +193,9 @@ class TransactionJournalFactory
$collection->push($journal);
}
$this->storeGroup($collection, $data['group_title']);
$group = $this->storeGroup($collection, $data['group_title']);
return $collection;
return $group;
}

View File

@ -1,6 +1,6 @@
<?php
/**
* StoredJournalEventHandler.php
* StoredGroupEventHandler.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
@ -22,47 +22,52 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\TransactionRules\Processor;
/**
* Class StoredJournalEventHandler
* Class StoredGroupEventHandler
*/
class StoredJournalEventHandler
class StoredGroupEventHandler
{
/**
* This method grabs all the users rules and processes them.
*
* @param StoredTransactionJournal $storedJournalEvent
* @param StoredTransactionGroup $storedJournalEvent
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function processRules(StoredTransactionJournal $storedJournalEvent): bool
public function processRules(StoredTransactionGroup $storedJournalEvent): bool
{
$journal = $storedJournalEvent->journal;
$journals = $storedJournalEvent->transactionGroup->transactionJournals;
// create objects:
/** @var RuleGroupRepositoryInterface $ruleGroupRepos */
$ruleGroupRepos = app(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->setUser($journal->user);
$groups = $ruleGroupRepos->getActiveGroups($journal->user);
/** @var RuleGroup $group */
foreach ($groups as $group) {
$rules = $ruleGroupRepos->getActiveStoreRules($group);
/** @var Rule $rule */
foreach ($rules as $rule) {
/** @var Processor $processor */
$processor = app(Processor::class);
$processor->make($rule);
$processor->handleTransactionJournal($journal);
foreach ($journals as $journal) {
$ruleGroupRepos->setUser($journal->user);
$groups = $ruleGroupRepos->getActiveGroups($journal->user);
if ($rule->stop_processing) {
break;
/** @var RuleGroup $group */
foreach ($groups as $group) {
$rules = $ruleGroupRepos->getActiveStoreRules($group);
/** @var Rule $rule */
foreach ($rules as $rule) {
/** @var Processor $processor */
$processor = app(Processor::class);
$processor->make($rule);
$processor->handleTransactionJournal($journal);
// TODO refactor the stop_processing logic.
// TODO verify that rule execution happens in one place only, including the journal + rule loop (if any)
if ($rule->stop_processing) {
break;
}
}
}
}

View File

@ -1,6 +1,6 @@
<?php
/**
* UpdatedJournalEventHandler.php
* UpdatedGroupEventHandler.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
@ -22,48 +22,51 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\TransactionRules\Processor;
/**
* Class UpdatedJournalEventHandler
* Class UpdatedGroupEventHandler
*/
class UpdatedJournalEventHandler
class UpdatedGroupEventHandler
{
/**
* This method will check all the rules when a journal is updated.
*
* @param UpdatedTransactionJournal $updatedJournalEvent
* @param UpdatedTransactionGroup $updatedJournalEvent
*
* @return bool
* @throws \FireflyIII\Exceptions\FireflyException
*/
public function processRules(UpdatedTransactionJournal $updatedJournalEvent): bool
public function processRules(UpdatedTransactionGroup $updatedJournalEvent): bool
{
// get all the user's rule groups, with the rules, order by 'order'.
$journal = $updatedJournalEvent->journal;
$journals = $updatedJournalEvent->transactionGroup;
/** @var RuleGroupRepositoryInterface $ruleGroupRepos */
$ruleGroupRepos = app(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->setUser($journal->user);
$groups = $ruleGroupRepos->getActiveGroups($journal->user);
foreach ($journals as $journal) {
$ruleGroupRepos->setUser($journal->user);
/** @var RuleGroup $group */
foreach ($groups as $group) {
$rules = $ruleGroupRepos->getActiveUpdateRules($group);
/** @var Rule $rule */
foreach ($rules as $rule) {
/** @var Processor $processor */
$processor = app(Processor::class);
$processor->make($rule);
$processor->handleTransactionJournal($journal);
$groups = $ruleGroupRepos->getActiveGroups($journal->user);
if ($rule->stop_processing) {
break;
/** @var RuleGroup $group */
foreach ($groups as $group) {
$rules = $ruleGroupRepos->getActiveUpdateRules($group);
/** @var Rule $rule */
foreach ($rules as $rule) {
/** @var Processor $processor */
$processor = app(Processor::class);
$processor->make($rule);
$processor->handleTransactionJournal($journal);
if ($rule->stop_processing) {
break;
}
}
}
}

View File

@ -31,6 +31,7 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Support\Facades\Preferences;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Laravel\Passport\Passport;
use Log;
@ -50,6 +51,11 @@ class InstallController extends Controller
public const BASEDIR_ERROR = 'Firefly III cannot execute the upgrade commands. It is not allowed to because of an open_basedir restriction.';
/** @var string Other errors */
public const OTHER_ERROR = 'An unknown error prevented Firefly III from executing the upgrade commands. Sorry.';
/** @var array All upgrade commands. */
private $upgradeCommands;
/** @noinspection MagicMethodsValidityInspection */
/** @noinspection PhpMissingParentConstructorInspection */
/**
@ -58,41 +64,39 @@ class InstallController extends Controller
public function __construct()
{
// empty on purpose.
$this->upgradeCommands = [
// there are x initial commands
'migrate' => ['--seed' => true, '--force' => true],
'firefly:decrypt-all' => [],
'generate-keys' => [], // an exception :(
// there are 10 upgrade commands.
'firefly-iii:transaction-identifiers' => [],
'firefly-iii:account-currencies' => [],
'firefly-iii:journal-currencies' => [],
'firefly-iii:migrate-notes' => [],
'firefly-iii:migrate-attachments' => [],
'firefly-iii:bills-to-rules' => [],
'firefly-iii:bl-currency' => [],
'firefly-iii:cc-liabilities' => [],
'firefly-iii:migrate-to-groups' => [],
'firefly-iii:back-to-journals' => [],
// there are 12 verify commands.
'firefly-iii:fix-piggies' => [],
'firefly-iii:create-link-types' => [],
'firefly-iii:create-access-tokens' => [],
'firefly-iii:remove-bills' => [],
'firefly-iii:enable-currencies' => [],
'firefly-iii:fix-transfer-budgets' => [],
'firefly-iii:fix-uneven-amount' => [],
'firefly-iii:delete-zero-amount' => [],
'firefly-iii:delete-orphaned-transactions' => [],
'firefly-iii:delete-empty-journals' => [],
'firefly-iii:delete-empty-groups' => [],
'firefly-iii:fix-account-types' => [],
];
}
/**
* Do database decrypt.
*
* @return \Illuminate\Http\JsonResponse
*/
public function decrypt(): JsonResponse
{
if ($this->hasForbiddenFunctions()) {
return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]);
}
try {
Log::debug('Am now calling decrypt database routine...');
Artisan::call('firefly:decrypt-all');
Log::debug(Artisan::output());
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
Cache::clear();
return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]);
}
return response()->json(['error' => true, 'message' => self::OTHER_ERROR . ' ' . $e->getMessage()]);
}
// clear cache as well.
Cache::clear();
Preferences::mark();
return response()->json(['error' => false, 'message' => 'OK']);
}
/**
* Show index.
*
@ -108,16 +112,9 @@ class InstallController extends Controller
/**
* Create specific RSA keys.
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function keys()
public function keys(): void
{
if ($this->hasForbiddenFunctions()) {
return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]);
}
// create keys manually because for some reason the passport namespace
// does not exist
$rsa = new RSA();
$keys = $rsa->createKey(4096);
@ -127,113 +124,77 @@ class InstallController extends Controller
];
if (file_exists($publicKey) || file_exists($privateKey)) {
return response()->json(['error' => false, 'message' => 'OK']);
return;
}
file_put_contents($publicKey, Arr::get($keys, 'publickey'));
file_put_contents($privateKey, Arr::get($keys, 'privatekey'));
// clear cache as well.
Cache::clear();
Preferences::mark();
return response()->json(['error' => false, 'message' => 'OK']);
}
/**
* Run migration commands.
* @param Request $request
*
* @return JsonResponse
*/
public function migrate(): JsonResponse
public function runCommand(Request $request): JsonResponse
{
if ($this->hasForbiddenFunctions()) {
return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]);
}
$requestIndex = (int)$request->get('index');
$response = [
'hasNextCommand' => false,
'done' => true,
'next' => 0,
'previous' => null,
'error' => false,
'errorMessage' => null,
];
try {
Log::debug('Am now calling migrate routine...');
Artisan::call('migrate', ['--seed' => true, '--force' => true]);
Log::debug(Artisan::output());
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]);
Log::debug(sprintf('Will now run commands. Request index is %d', $requestIndex));
$index = 0;
foreach ($this->upgradeCommands as $command => $args) {
Log::debug(sprintf('Current command is "%s", index is %d', $command, $index));
if ($index < $requestIndex) {
Log::debug('Will not execute.');
$index++;
continue;
}
if ($index >= $requestIndex) {
Log::debug(sprintf('%d >= %d, will execute the command.', $index, $requestIndex));
Log::debug(sprintf('Will now call command %s with args.', $command), $args);
try {
if ('generate-keys' === $command) {
$this->keys();
}
if ('generate-keys' !== $command) {
Artisan::call($command, $args);
Log::debug(Artisan::output());
}
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
$response['error'] = true;
$response['errorMessage'] = self::BASEDIR_ERROR;
return response()->json(['error' => true, 'message' => self::OTHER_ERROR]);
}
// clear cache as well.
Cache::clear();
Preferences::mark();
return response()->json($response);
}
$response['error'] = true;
$response['errorMessage'] = self::OTHER_ERROR . ' ' . $e->getMessage();
return response()->json(['error' => false, 'message' => 'OK']);
}
return response()->json($response);
}
// clear cache as well.
Cache::clear();
Preferences::mark();
/**
* Do database upgrade.
*
* @return \Illuminate\Http\JsonResponse
*/
public function upgrade(): JsonResponse
{
if ($this->hasForbiddenFunctions()) {
return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]);
}
try {
Log::debug('Am now calling upgrade database routine...');
Artisan::call('firefly:upgrade-database');
Log::debug(Artisan::output());
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]);
$index++;
$response['hasNextCommand'] = true;
$response['previous'] = $command;
break;
}
return response()->json(['error' => true, 'message' => self::OTHER_ERROR . ' ' . $e->getMessage()]);
}
// clear cache as well.
Cache::clear();
Preferences::mark();
$response['next'] = $index;
return response()->json(['error' => false, 'message' => 'OK']);
return response()->json($response);
}
/**
* Do database verification.
*
* @return \Illuminate\Http\JsonResponse
*/
public function verify(): JsonResponse
{
if ($this->hasForbiddenFunctions()) {
return response()->json(['error' => true, 'message' => self::FORBIDDEN_ERROR]);
}
try {
Log::debug('Am now calling verify database routine...');
Artisan::call('firefly:verify');
Log::debug(Artisan::output());
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
if (strpos($e->getMessage(), 'open_basedir restriction in effect')) {
return response()->json(['error' => true, 'message' => self::BASEDIR_ERROR]);
}
return response()->json(['error' => true, 'message' => self::OTHER_ERROR . ' ' . $e->getMessage()]);
}
// clear cache as well.
Cache::clear();
Preferences::mark();
return response()->json(['error' => false, 'message' => 'OK']);
}
}

View File

@ -22,7 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionJournal;
@ -128,6 +128,7 @@ class ConvertController extends Controller
*/
public function postIndex(Request $request, TransactionType $destinationType, TransactionJournal $journal)
{
throw new FireflyException('Needs refactor');
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($journal)) {
Log::debug('Journal is opening balance, return to account.');
@ -166,7 +167,7 @@ class ConvertController extends Controller
}
// Success? Fire rules!
event(new UpdatedTransactionJournal($journal));
event(new UpdatedTransactionGroup($group));
session()->flash('success', (string)trans('firefly.converted_to_' . $destinationType->type));

View File

@ -23,7 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use Carbon\Carbon;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\TransactionViewFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
@ -128,6 +129,7 @@ class MassController extends Controller
*/
public function edit(Collection $journals): IlluminateView
{
throw new FireflyException('Needs refactor');
/** @var User $user */
$user = auth()->user();
$subTitle = (string)trans('firefly.mass_edit_journals');
@ -182,6 +184,7 @@ class MassController extends Controller
*/
public function update(MassEditJournalRequest $request, JournalRepositoryInterface $repository)
{
throw new FireflyException('Needs refactor');
$journalIds = $request->get('journals');
$count = 0;
if (\is_array($journalIds)) {
@ -242,7 +245,7 @@ class MassController extends Controller
$repository->update($journal, $data);
// trigger rules
event(new UpdatedTransactionJournal($journal));
event(new UpdatedTransactionGroup($group));
++$count;
}

View File

@ -23,8 +23,9 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use Carbon\Carbon;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\JournalFormRequest;
@ -373,9 +374,9 @@ class SingleController extends Controller
$doSplit = 1 === (int)$request->get('split_journal');
$createAnother = 1 === (int)$request->get('create_another');
$data = $request->getJournalData();
$journal = $repository->store($data);
$group = $repository->store($data);
throw new FireflyException('Needs refactor');
if (null === $journal->id) {
// error!
Log::error('Could not store transaction journal.');
@ -398,7 +399,7 @@ class SingleController extends Controller
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
}
event(new StoredTransactionJournal($journal));
event(new StoredTransactionGroup($group));
session()->flash('success_uri', route('transactions.show', [$journal->id]));
session()->flash('success', (string)trans('firefly.stored_journal', ['description' => $journal->description]));
@ -449,7 +450,7 @@ class SingleController extends Controller
if (!$request->boolean('keep_bill_id')) {
$data['bill_id'] = null;
}
throw new FireflyException('Needs refactor');
$journal = $repository->update($journal, $data);
/** @var array $files */
@ -465,7 +466,7 @@ class SingleController extends Controller
}
// @codeCoverageIgnoreEnd
event(new UpdatedTransactionJournal($journal));
event(new UpdatedTransactionGroup($group));
// update, get events by date and sort DESC
$type = strtolower($this->repository->getTransactionType($journal));

View File

@ -22,7 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
@ -89,6 +89,7 @@ class SplitController extends Controller
*/
public function edit(Request $request, TransactionJournal $journal)
{
throw new FireflyException('Needs refactoring');
if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal); // @codeCoverageIgnore
}
@ -132,6 +133,7 @@ class SplitController extends Controller
*/
public function update(SplitJournalFormRequest $request, TransactionJournal $journal)
{
throw new FireflyException('Needs refactoring.');
if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal); // @codeCoverageIgnore
}
@ -145,7 +147,7 @@ class SplitController extends Controller
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
// save attachments:
$this->attachments->saveAttachmentsForModel($journal, $files);
event(new UpdatedTransactionJournal($journal));
event(new UpdatedTransactionGroup($group));
// flash messages
// @codeCoverageIgnoreStart

View File

@ -47,7 +47,8 @@ namespace FireflyIII\Jobs;
use Carbon\Carbon;
use FireflyIII\Events\RequestedReportOnJournals;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\PiggyBankEventFactory;
use FireflyIII\Factory\PiggyBankFactory;
use FireflyIII\Models\Recurrence;
@ -317,6 +318,7 @@ class CreateRecurringTransactions implements ShouldQueue
*/
private function handleOccurrences(Recurrence $recurrence, array $occurrences): Collection
{
throw new FireflyException('Needs refactor');
$collection = new Collection;
/** @var Carbon $date */
foreach ($occurrences as $date) {
@ -360,7 +362,7 @@ class CreateRecurringTransactions implements ShouldQueue
Log::debug(sprintf('Piggy bank ID for recurrence #%d is #%d', $recurrence->id, $piggyBankId));
// trigger event:
event(new StoredTransactionJournal($journal));
event(new StoredTransactionGroup($journal));
// link to piggy bank:
/** @var PiggyBankFactory $factory */

View File

@ -28,8 +28,8 @@ use FireflyIII\Events\RegisteredUser;
use FireflyIII\Events\RequestedNewPassword;
use FireflyIII\Events\RequestedReportOnJournals;
use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Events\UserChangedEmail;
use FireflyIII\Mail\OAuthTokenCreatedMail;
use FireflyIII\Models\PiggyBank;
@ -89,12 +89,12 @@ class EventServiceProvider extends ServiceProvider
'FireflyIII\Handlers\Events\AdminEventHandler@sendTestMessage',
],
// is a Transaction Journal related event.
StoredTransactionJournal::class => [
'FireflyIII\Handlers\Events\StoredJournalEventHandler@processRules',
StoredTransactionGroup::class => [
'FireflyIII\Handlers\Events\StoredGroupEventHandler@processRules',
],
// is a Transaction Journal related event.
UpdatedTransactionJournal::class => [
'FireflyIII\Handlers\Events\UpdatedJournalEventHandler@processRules',
UpdatedTransactionGroup::class => [
'FireflyIII\Handlers\Events\UpdatedGroupEventHandler@processRules',
],
// API related events:
AccessTokenCreated::class => [

View File

@ -776,11 +776,11 @@ class JournalRepository implements JournalRepositoryInterface
/**
* @param array $data
*
* @return TransactionJournal
* @return TransactionGroup
*
* @throws FireflyException
*/
public function store(array $data): TransactionJournal
public function store(array $data): TransactionGroup
{
/** @var TransactionJournalFactory $factory */
$factory = app(TransactionJournalFactory::class);
@ -790,15 +790,15 @@ class JournalRepository implements JournalRepositoryInterface
}
/**
* @param TransactionJournal $journal
* @param TransactionGroup $journal
* @param array $data
*
* @return TransactionJournal
* @return TransactionGroup
*
* @throws FireflyException
* @throws FireflyException
*/
public function update(TransactionJournal $journal, array $data): TransactionJournal
public function update(TransactionGroup $journal, array $data): TransactionGroup
{
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);

View File

@ -23,13 +23,45 @@ $(function () {
"use strict";
//var status = $('#status-box');
// set HTML to "migrating...":
startMigration();
startRunningCommands();
});
function startRunningCommands() {
if (0 === index) {
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Running first command...');
}
runCommand(index);
}
function runCommand(index) {
$.post(runCommandUri, {_token: token, index: index}).done(function (data) {
if (data.error === false) {
// increase index
index++;
if(data.hasNextCommand) {
// inform user
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Just executed ' + data.previous + '...');
console.log('Will call next command.');
runCommand(index);
} else {
completeDone();
console.log('Finished!');
}
} else {
displaySoftFail(data.errorMessage);
console.error(data);
}
}).fail(function () {
$('#status-box').html('<i class="fa fa-warning"></i> Command failed! See log files :(');
});
}
function startMigration() {
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Setting up DB...');
$.post(migrateUri, {_token: token}).done(function (data) {
if(data.error === false) {
if (data.error === false) {
// move to decrypt routine.
startDecryption();
} else {
@ -44,7 +76,7 @@ function startMigration() {
function startDecryption() {
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Setting up DB #2...');
$.post(decryptUri, {_token: token}).done(function (data) {
if(data.error === false) {
if (data.error === false) {
// move to decrypt routine.
startPassport();
} else {
@ -62,7 +94,7 @@ function startDecryption() {
function startPassport() {
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Setting up OAuth2...');
$.post(keysUri, {_token: token}).done(function (data) {
if(data.error === false) {
if (data.error === false) {
startUpgrade();
} else {
displaySoftFail(data.message);
@ -79,7 +111,7 @@ function startPassport() {
function startUpgrade() {
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Upgrading database...');
$.post(upgradeUri, {_token: token}).done(function (data) {
if(data.error === false) {
if (data.error === false) {
startVerify();
} else {
displaySoftFail(data.message);
@ -95,7 +127,7 @@ function startUpgrade() {
function startVerify() {
$('#status-box').html('<i class="fa fa-spin fa-spinner"></i> Verify database integrity...');
$.post(verifyUri, {_token: token}).done(function (data) {
if(data.error === false) {
if (data.error === false) {
completeDone();
} else {
displaySoftFail(data.message);

View File

@ -15,11 +15,8 @@
{% block scripts %}
<script type="text/javascript">
var token = '{{ csrf_token() }}';
var migrateUri = '{{ route('installer.migrate') }}';
var keysUri = '{{ route('installer.keys') }}';
var upgradeUri = '{{ route('installer.upgrade') }}';
var verifyUri = '{{ route('installer.verify') }}';
var decryptUri = '{{ route('installer.decrypt') }}';
var index = 0;
var runCommandUri = '{{ route('installer.runCommand') }}';
var homeUri = '{{ route('flush') }}';
</script>
<script type="text/javascript" src="v1/js/ff/install/index.js"></script>

View File

@ -9,7 +9,11 @@
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<meta name="apple-mobile-web-app-capable" content="yes">
<link href="v1/css/app.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css"/>
{# libraries #}
<link href="v1/lib/bs/css/bootstrap.min.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css"/>
<link href="v1/lib/fa/css/font-awesome.min.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css"/>
<link href="v1/lib/adminlte/css/AdminLTE.min.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css"/>
<link href="v1/css/firefly.css?v={{ FF_VERSION }}" rel="stylesheet" type="text/css"/>

View File

@ -26,11 +26,12 @@ Route::group(
['namespace' => 'FireflyIII\Http\Controllers\System',
'as' => 'installer.', 'prefix' => 'install'], function () {
Route::get('', ['uses' => 'InstallController@index', 'as' => 'index']);
Route::post('migrate', ['uses' => 'InstallController@migrate', 'as' => 'migrate']);
Route::post('keys', ['uses' => 'InstallController@keys', 'as' => 'keys']);
Route::post('upgrade', ['uses' => 'InstallController@upgrade', 'as' => 'upgrade']);
Route::post('verify', ['uses' => 'InstallController@verify', 'as' => 'verify']);
Route::post('decrypt', ['uses' => 'InstallController@decrypt', 'as' => 'decrypt']);
Route::post('runCommand', ['uses' => 'InstallController@runCommand', 'as' => 'runCommand']);
// Route::post('migrate', ['uses' => 'InstallController@migrate', 'as' => 'migrate']);
// Route::post('keys', ['uses' => 'InstallController@keys', 'as' => 'keys']);
// Route::post('upgrade', ['uses' => 'InstallController@upgrade', 'as' => 'upgrade']);
// Route::post('verify', ['uses' => 'InstallController@verify', 'as' => 'verify']);
// Route::post('decrypt', ['uses' => 'InstallController@decrypt', 'as' => 'decrypt']);
}
);