mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Null pointer in verify routine.
This commit is contained in:
parent
5d9e547d05
commit
d1c8e54798
@ -164,13 +164,16 @@ class VerifyDatabase extends Command
|
|||||||
}
|
}
|
||||||
foreach ($errored as $journalId) {
|
foreach ($errored as $journalId) {
|
||||||
// select and update:
|
// select and update:
|
||||||
$res = Transaction::where('transaction_journal_id', $journalId)->groupBy('amount')->get([DB::raw('MIN(id) as first_id')]);
|
$res = Transaction::whereNull('deleted_at')->where('transaction_journal_id', $journalId)->groupBy('amount')->get([DB::raw('MIN(id) as first_id')]);
|
||||||
$ids = $res->pluck('first_id')->toArray();
|
$ids = $res->pluck('first_id')->toArray();
|
||||||
DB::table('transactions')->whereIn('id', $ids)->update(['amount' => DB::raw('amount * -1')]);
|
DB::table('transactions')->whereIn('id', $ids)->update(['amount' => DB::raw('amount * -1')]);
|
||||||
$count++;
|
$count++;
|
||||||
// report about it
|
// report about it
|
||||||
/** @var TransactionJournal $journal */
|
/** @var TransactionJournal $journal */
|
||||||
$journal = TransactionJournal::find($journalId);
|
$journal = TransactionJournal::find($journalId);
|
||||||
|
if (is_null($journal)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($journal->transactionType->type === TransactionType::OPENING_BALANCE) {
|
if ($journal->transactionType->type === TransactionType::OPENING_BALANCE) {
|
||||||
$this->error(
|
$this->error(
|
||||||
sprintf(
|
sprintf(
|
||||||
@ -200,7 +203,7 @@ class VerifyDatabase extends Command
|
|||||||
*/
|
*/
|
||||||
private function repairPiggyBanks(): void
|
private function repairPiggyBanks(): void
|
||||||
{
|
{
|
||||||
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get();
|
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get();
|
||||||
$set->each(
|
$set->each(
|
||||||
function (PiggyBankEvent $event) {
|
function (PiggyBankEvent $event) {
|
||||||
if (null === $event->transaction_journal_id) {
|
if (null === $event->transaction_journal_id) {
|
||||||
@ -350,18 +353,18 @@ class VerifyDatabase extends Command
|
|||||||
private function reportJournals()
|
private function reportJournals()
|
||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->whereNotNull('transaction_journals.deleted_at')// USE THIS
|
->whereNotNull('transaction_journals.deleted_at')// USE THIS
|
||||||
->whereNull('transactions.deleted_at')
|
->whereNull('transactions.deleted_at')
|
||||||
->whereNotNull('transactions.id')
|
->whereNotNull('transactions.id')
|
||||||
->get(
|
->get(
|
||||||
[
|
[
|
||||||
'transaction_journals.id as journal_id',
|
'transaction_journals.id as journal_id',
|
||||||
'transaction_journals.description',
|
'transaction_journals.description',
|
||||||
'transaction_journals.deleted_at as journal_deleted',
|
'transaction_journals.deleted_at as journal_deleted',
|
||||||
'transactions.id as transaction_id',
|
'transactions.id as transaction_id',
|
||||||
'transactions.deleted_at as transaction_deleted_at',]
|
'transactions.deleted_at as transaction_deleted_at',]
|
||||||
);
|
);
|
||||||
/** @var stdClass $entry */
|
/** @var stdClass $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$this->error(
|
$this->error(
|
||||||
@ -370,7 +373,7 @@ class VerifyDatabase extends Command
|
|||||||
);
|
);
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
if($count === 0) {
|
if ($count === 0) {
|
||||||
$this->info('No orphaned transactions!');
|
$this->info('No orphaned transactions!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -381,10 +384,10 @@ class VerifyDatabase extends Command
|
|||||||
private function reportNoTransactions()
|
private function reportNoTransactions()
|
||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->groupBy('transaction_journals.id')
|
->groupBy('transaction_journals.id')
|
||||||
->whereNull('transactions.transaction_journal_id')
|
->whereNull('transactions.transaction_journal_id')
|
||||||
->get(['transaction_journals.id']);
|
->get(['transaction_journals.id']);
|
||||||
|
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$this->error(
|
$this->error(
|
||||||
@ -392,7 +395,7 @@ class VerifyDatabase extends Command
|
|||||||
);
|
);
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
if($count === 0) {
|
if ($count === 0) {
|
||||||
$this->info('No orphaned journals!');
|
$this->info('No orphaned journals!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user