mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Some small updates.
This commit is contained in:
225
app/Console/Commands/VerifyDatabase.php
Normal file
225
app/Console/Commands/VerifyDatabase.php
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Console\Commands;
|
||||||
|
|
||||||
|
use Crypt;
|
||||||
|
use DB;
|
||||||
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\Category;
|
||||||
|
use FireflyIII\Models\Tag;
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class VerifyDatabase
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Console\Commands
|
||||||
|
*/
|
||||||
|
class VerifyDatabase extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Will verify your database.';
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'firefly:verify';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
// accounts with no transactions.
|
||||||
|
$this->reportAccounts();
|
||||||
|
// budgets with no limits
|
||||||
|
$this->reportBudgetLimits();
|
||||||
|
// budgets with no transactions
|
||||||
|
$this->reportBudgets();
|
||||||
|
// categories with no transactions
|
||||||
|
$this->reportCategories();
|
||||||
|
// tags with no transactions
|
||||||
|
$this->reportTags();
|
||||||
|
// sum of transactions is not zero.
|
||||||
|
$this->reportSum();
|
||||||
|
// any deleted transaction journals that have transactions that are NOT deleted:
|
||||||
|
$this->reportJournals();
|
||||||
|
// deleted transactions that are connected to a not deleted journal.
|
||||||
|
$this->reportTransactions();
|
||||||
|
// deleted accounts that still have not deleted transactions or journals attached to them.
|
||||||
|
$this->reportDeletedAccounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports on accounts with no transactions.
|
||||||
|
*/
|
||||||
|
private function reportAccounts()
|
||||||
|
{
|
||||||
|
$set = Account
|
||||||
|
::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id')
|
||||||
|
->leftJoin('users', 'accounts.user_id', '=', 'users.id')
|
||||||
|
->groupBy('accounts.id')
|
||||||
|
->having('transaction_count', '=', 0)
|
||||||
|
->get(['accounts.id', 'accounts.name', 'accounts.user_id', 'users.email', DB::raw('COUNT(`transactions`.`id`) AS `transaction_count`')]);
|
||||||
|
|
||||||
|
/** @var stdClass $entry */
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$line = 'User #' . $entry->user_id . ' (' . $entry->email . ') has account #' . $entry->id . ' ("' . Crypt::decrypt($entry->name)
|
||||||
|
. '") which has no transactions.';
|
||||||
|
$this->line($line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports on budgets with no budget limits (which makes them pointless).
|
||||||
|
*/
|
||||||
|
private function reportBudgetLimits()
|
||||||
|
{
|
||||||
|
$set = Budget
|
||||||
|
::leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budgets.id')
|
||||||
|
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
|
||||||
|
->groupBy('budgets.id')
|
||||||
|
->having('budget_limit_count', '=', 0)
|
||||||
|
->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email', DB::raw('COUNT(`budget_limits`.`id`) AS `budget_limit_count`')]);
|
||||||
|
|
||||||
|
/** @var stdClass $entry */
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$line = 'User #' . $entry->user_id . ' (' . $entry->email . ') has budget #' . $entry->id . ' ("' . Crypt::decrypt($entry->name)
|
||||||
|
. '") which has no budget limits.';
|
||||||
|
$this->line($line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports on budgets without any transactions.
|
||||||
|
*/
|
||||||
|
private function reportBudgets()
|
||||||
|
{
|
||||||
|
$set = Budget
|
||||||
|
::leftJoin('budget_transaction_journal', 'budgets.id', '=', 'budget_transaction_journal.budget_id')
|
||||||
|
->leftJoin('users', 'budgets.user_id', '=', 'users.id')
|
||||||
|
->distinct()
|
||||||
|
->get(['budgets.id', 'budgets.name', 'budget_transaction_journal.budget_id', 'budgets.user_id', 'users.email']);
|
||||||
|
|
||||||
|
/** @var stdClass $entry */
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$line = 'User #' . $entry->user_id . ' (' . $entry->email . ') has budget #' . $entry->id . ' ("' . Crypt::decrypt($entry->name)
|
||||||
|
. '") which has no transactions.';
|
||||||
|
$this->line($line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports on categories without any transactions.
|
||||||
|
*/
|
||||||
|
private function reportCategories()
|
||||||
|
{
|
||||||
|
$set = Category
|
||||||
|
::leftJoin('category_transaction_journal', 'categories.id', '=', 'category_transaction_journal.category_id')
|
||||||
|
->leftJoin('users', 'categories.user_id', '=', 'users.id')
|
||||||
|
->distinct()
|
||||||
|
->get(['categories.id', 'categories.name', 'category_transaction_journal.category_id', 'categories.user_id', 'users.email']);
|
||||||
|
|
||||||
|
/** @var stdClass $entry */
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$line = 'User #' . $entry->user_id . ' (' . $entry->email . ') has category #' . $entry->id . ' ("' . Crypt::decrypt($entry->name)
|
||||||
|
. '") which has no transactions.';
|
||||||
|
$this->line($line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function reportDeletedAccounts()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Any deleted transaction journals that have transactions that are NOT deleted:
|
||||||
|
*/
|
||||||
|
private function reportJournals()
|
||||||
|
{
|
||||||
|
$set = TransactionJournal
|
||||||
|
::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
|
->whereNotNull('transaction_journals.deleted_at')// USE THIS
|
||||||
|
->whereNull('transactions.deleted_at')
|
||||||
|
->whereNotNull('transactions.id')
|
||||||
|
->get(
|
||||||
|
[
|
||||||
|
'transaction_journals.id as journal_id',
|
||||||
|
'transaction_journals.description',
|
||||||
|
'transaction_journals.deleted_at as journal_deleted',
|
||||||
|
'transactions.id as transaction_id',
|
||||||
|
'transactions.deleted_at as transaction_deleted_at']
|
||||||
|
);
|
||||||
|
/** @var stdClass $entry */
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$this->error(
|
||||||
|
'Transaction #' . $entry->transaction_id . ' should have been deleted, but has not.' .
|
||||||
|
' Find it in the table called `transactions` and change the `deleted_at` field to: "' . $entry->journal_deleted. '"'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports for each user when the sum of their transactions is not zero.
|
||||||
|
*/
|
||||||
|
private function reportSum()
|
||||||
|
{
|
||||||
|
/** @var UserRepositoryInterface $userRepository */
|
||||||
|
$userRepository = app('FireflyIII\Repositories\User\UserRepositoryInterface');
|
||||||
|
|
||||||
|
/** @var User $user */
|
||||||
|
foreach ($userRepository->all() as $user) {
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface', [$user]);
|
||||||
|
$sum = $repository->sumOfEverything();
|
||||||
|
if (bccomp($sum, '0') !== 0) {
|
||||||
|
$this->error('Transactions for user #' . $user->id . ' (' . $user->email . ') are off by ' . $sum . '!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reports on tags without any transactions.
|
||||||
|
*/
|
||||||
|
private function reportTags()
|
||||||
|
{
|
||||||
|
$set = Tag
|
||||||
|
::leftJoin('tag_transaction_journal', 'tags.id', '=', 'tag_transaction_journal.tag_id')
|
||||||
|
->leftJoin('users', 'tags.user_id', '=', 'users.id')
|
||||||
|
->distinct()
|
||||||
|
->get(['tags.id', 'tags.tag', 'tag_transaction_journal.tag_id', 'tags.user_id', 'users.email']);
|
||||||
|
|
||||||
|
/** @var stdClass $entry */
|
||||||
|
foreach ($set as $entry) {
|
||||||
|
$line = 'User #' . $entry->user_id . ' (' . $entry->email . ') has tag #' . $entry->id . ' ("' . $entry->tag
|
||||||
|
. '") which has no transactions.';
|
||||||
|
$this->line($line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function reportTransactions()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@@ -12,6 +12,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Console;
|
namespace FireflyIII\Console;
|
||||||
|
|
||||||
use FireflyIII\Console\Commands\UpgradeFireflyInstructions;
|
use FireflyIII\Console\Commands\UpgradeFireflyInstructions;
|
||||||
|
use FireflyIII\Console\Commands\VerifyDatabase;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
@@ -30,16 +31,17 @@ class Kernel extends ConsoleKernel
|
|||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $bootstrappers = [
|
protected $bootstrappers
|
||||||
'Illuminate\Foundation\Bootstrap\DetectEnvironment',
|
= [
|
||||||
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
|
'Illuminate\Foundation\Bootstrap\DetectEnvironment',
|
||||||
'FireflyIII\Bootstrap\ConfigureLogging',
|
'Illuminate\Foundation\Bootstrap\LoadConfiguration',
|
||||||
'Illuminate\Foundation\Bootstrap\HandleExceptions',
|
'FireflyIII\Bootstrap\ConfigureLogging',
|
||||||
'Illuminate\Foundation\Bootstrap\RegisterFacades',
|
'Illuminate\Foundation\Bootstrap\HandleExceptions',
|
||||||
'Illuminate\Foundation\Bootstrap\SetRequestForConsole',
|
'Illuminate\Foundation\Bootstrap\RegisterFacades',
|
||||||
'Illuminate\Foundation\Bootstrap\RegisterProviders',
|
'Illuminate\Foundation\Bootstrap\SetRequestForConsole',
|
||||||
'Illuminate\Foundation\Bootstrap\BootProviders',
|
'Illuminate\Foundation\Bootstrap\RegisterProviders',
|
||||||
];
|
'Illuminate\Foundation\Bootstrap\BootProviders',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Artisan commands provided by your application.
|
* The Artisan commands provided by your application.
|
||||||
@@ -49,6 +51,7 @@ class Kernel extends ConsoleKernel
|
|||||||
protected $commands
|
protected $commands
|
||||||
= [
|
= [
|
||||||
UpgradeFireflyInstructions::class,
|
UpgradeFireflyInstructions::class,
|
||||||
|
VerifyDatabase::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -121,7 +121,7 @@ class HomeController extends Controller
|
|||||||
$sum = $repository->sumOfEverything();
|
$sum = $repository->sumOfEverything();
|
||||||
|
|
||||||
if (bccomp($sum, '0') !== 0) {
|
if (bccomp($sum, '0') !== 0) {
|
||||||
Session::flash('error', strval(trans('firefly.unbalanced_error', ['amount' => Amount::format($sum,false)])));
|
Session::flash('error', strval(trans('firefly.unbalanced_error', ['amount' => Amount::format($sum, false)])));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
|
@@ -1,7 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "grumpydictator/firefly-iii",
|
"name": "grumpydictator/firefly-iii",
|
||||||
"description": "Firefly III: a personal finances manager.",
|
"description": "Firefly III: a personal finances manager.",
|
||||||
"keywords": ["finance", "finances", "manager", "euro", "laravel", "money", "financials", "budgets", "transactions", "transfers", "management"],
|
"keywords": [
|
||||||
|
"finance",
|
||||||
|
"finances",
|
||||||
|
"manager",
|
||||||
|
"euro",
|
||||||
|
"laravel",
|
||||||
|
"money",
|
||||||
|
"financials",
|
||||||
|
"budgets",
|
||||||
|
"transactions",
|
||||||
|
"transfers",
|
||||||
|
"management"
|
||||||
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://github.com/JC5/firefly-iii",
|
"homepage": "https://github.com/JC5/firefly-iii",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
@@ -11,8 +23,8 @@
|
|||||||
"email": "thegrumpydictator@gmail.com",
|
"email": "thegrumpydictator@gmail.com",
|
||||||
"homepage": "https://github.com/JC5",
|
"homepage": "https://github.com/JC5",
|
||||||
"role": "Developer"
|
"role": "Developer"
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"laravel/framework": "5.2.*",
|
"laravel/framework": "5.2.*",
|
||||||
"davejamesmiller/laravel-breadcrumbs": "~3.0",
|
"davejamesmiller/laravel-breadcrumbs": "~3.0",
|
||||||
@@ -68,7 +80,8 @@
|
|||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
"php artisan cache:clear",
|
"php artisan cache:clear",
|
||||||
"php artisan optimize",
|
"php artisan optimize",
|
||||||
"php artisan firefly:upgrade-instructions"
|
"php artisan firefly:upgrade-instructions",
|
||||||
|
"php artisan firefly:verify"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
1568
composer.lock
generated
1568
composer.lock
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user