diff --git a/app/Console/Commands/VerifyDatabase.php b/app/Console/Commands/VerifyDatabase.php index 5fed76218f..c14a9187f1 100644 --- a/app/Console/Commands/VerifyDatabase.php +++ b/app/Console/Commands/VerifyDatabase.php @@ -12,13 +12,13 @@ declare(strict_types = 1); 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\Transaction; use FireflyIII\Models\TransactionJournal; +use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\User; use Illuminate\Console\Command; @@ -79,6 +79,9 @@ class VerifyDatabase extends Command // report on journals with no transactions at all. $this->reportNoTransactions(); + + // transfers with budgets. + $this->reportTransfersBudgets(); } /** @@ -89,11 +92,10 @@ class VerifyDatabase extends Command $set = Account ::leftJoin('transactions', 'transactions.account_id', '=', 'accounts.id') ->leftJoin('users', 'accounts.user_id', '=', 'users.id') - ->groupBy('accounts.id') - ->having('transaction_count', '=', 0) + ->groupBy(['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email']) + ->whereNull('transactions.account_id') ->get( - ['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email', - DB::raw('COUNT(`transactions`.`id`) AS `transaction_count`')] + ['accounts.id', 'accounts.encrypted', 'accounts.name', 'accounts.user_id', 'users.email'] ); /** @var stdClass $entry */ @@ -113,9 +115,9 @@ class VerifyDatabase extends Command $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`')]); + ->groupBy(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email']) + ->whereNull('budget_limits.id') + ->get(['budgets.id', 'budgets.name', 'budgets.user_id', 'users.email']); /** @var stdClass $entry */ foreach ($set as $entry) { @@ -225,19 +227,16 @@ class VerifyDatabase extends Command } } + /** + * + */ private function reportNoTransactions() { - /* - * select transaction_journals.id, count(transactions.id) as transaction_count from transaction_journals -left join transactions ON transaction_journals.id = transactions.transaction_journal_id -group by transaction_journals.id -having transaction_count = 0 - */ $set = TransactionJournal ::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->groupBy('transaction_journals.id') - ->having('transaction_count', '=', 0) - ->get(['transaction_journals.id', DB::raw('COUNT(`transactions`.`id`) as `transaction_count`')]); + ->whereNull('transactions.transaction_journal_id') + ->get(['transaction_journals.id']); foreach ($set as $entry) { $this->error( @@ -306,4 +305,29 @@ having transaction_count = 0 ); } } + + /** + * + */ + private function reportTransfersBudgets() + { + $set = TransactionJournal + ::distinct() + ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') + ->leftJoin('budget_transaction_journal', 'transaction_journals.id', '=', 'budget_transaction_journal.transaction_journal_id') + ->where('transaction_types.type', TransactionType::TRANSFER) + ->whereNotNull('budget_transaction_journal.budget_id')->get(['transaction_journals.id']); + + /** @var TransactionJournal $entry */ + foreach ($set as $entry) { + $this->error( + sprintf( + 'Error: Transaction journal #%d is a transfer, but has a budget. Edit it without changing anything, so the budget will be removed.', + $entry->id + ) + ); + } + + + } } diff --git a/composer.json b/composer.json index ea12d75a2d..65cc711cd8 100755 --- a/composer.json +++ b/composer.json @@ -38,7 +38,8 @@ "rmccue/requests": "^1.6", "pragmarx/google2fa": "^1.0", "barryvdh/laravel-debugbar": "^2.2", - "barryvdh/laravel-ide-helper": "^2.2" + "barryvdh/laravel-ide-helper": "^2.2", + "bacon/bacon-qr-code": "^1.0" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index f893c9a415..23f1d10302 100644 --- a/composer.lock +++ b/composer.lock @@ -4,33 +4,75 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e85564217ea6463d7035a0f53a50f221", - "content-hash": "927d3ed3073f45b9e9de6dd6f28dde88", + "hash": "f48992f1aad4a7b781ae1d6c43bddcf3", + "content-hash": "8a35f78c306f3ddd1080d7c1b687f77d", "packages": [ { - "name": "barryvdh/laravel-debugbar", - "version": "V2.2.3", + "name": "bacon/bacon-qr-code", + "version": "1.0.1", "source": { "type": "git", - "url": "https://github.com/barryvdh/laravel-debugbar.git", - "reference": "ecd1ce5c4a827e2f6a8fb41bcf67713beb1c1cbd" + "url": "https://github.com/Bacon/BaconQrCode.git", + "reference": "031a2ce68c5794064b49d11775b2daf45c96e21c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/ecd1ce5c4a827e2f6a8fb41bcf67713beb1c1cbd", - "reference": "ecd1ce5c4a827e2f6a8fb41bcf67713beb1c1cbd", + "url": "https://api.github.com/repos/Bacon/BaconQrCode/zipball/031a2ce68c5794064b49d11775b2daf45c96e21c", + "reference": "031a2ce68c5794064b49d11775b2daf45c96e21c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-gd": "to generate QR code images" + }, + "type": "library", + "autoload": { + "psr-0": { + "BaconQrCode": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Ben Scholzen 'DASPRiD'", + "email": "mail@dasprids.de", + "homepage": "http://www.dasprids.de", + "role": "Developer" + } + ], + "description": "BaconQrCode is a QR code generator for PHP.", + "homepage": "https://github.com/Bacon/BaconQrCode", + "time": "2016-01-09 22:55:35" + }, + { + "name": "barryvdh/laravel-debugbar", + "version": "v2.3.0", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-debugbar.git", + "reference": "0c87981df959c7c1943abe227baf607c92f204f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/0c87981df959c7c1943abe227baf607c92f204f9", + "reference": "0c87981df959c7c1943abe227baf607c92f204f9", "shasum": "" }, "require": { "illuminate/support": "5.1.*|5.2.*|5.3.*", - "maximebf/debugbar": "~1.11.0|~1.12.0", + "maximebf/debugbar": "~1.13.0", "php": ">=5.5.9", "symfony/finder": "~2.7|~3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-master": "2.3-dev" } }, "autoload": { @@ -59,7 +101,7 @@ "profiler", "webprofiler" ], - "time": "2016-07-29 15:00:36" + "time": "2016-09-15 14:05:56" }, { "name": "barryvdh/laravel-ide-helper", @@ -982,16 +1024,16 @@ }, { "name": "laravel/framework", - "version": "v5.3.9", + "version": "v5.3.10", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "f6fbb481672f8dc4bc6882d5d654bbfa3588c8ec" + "reference": "6febb0ee61999cde3bc7b2963c8903032bb22691" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/f6fbb481672f8dc4bc6882d5d654bbfa3588c8ec", - "reference": "f6fbb481672f8dc4bc6882d5d654bbfa3588c8ec", + "url": "https://api.github.com/repos/laravel/framework/zipball/6febb0ee61999cde3bc7b2963c8903032bb22691", + "reference": "6febb0ee61999cde3bc7b2963c8903032bb22691", "shasum": "" }, "require": { @@ -1039,6 +1081,7 @@ "illuminate/http": "self.version", "illuminate/log": "self.version", "illuminate/mail": "self.version", + "illuminate/notifications": "self.version", "illuminate/pagination": "self.version", "illuminate/pipeline": "self.version", "illuminate/queue": "self.version", @@ -1105,7 +1148,7 @@ "framework", "laravel" ], - "time": "2016-09-12 14:08:29" + "time": "2016-09-20 13:46:16" }, { "name": "laravelcollective/html", @@ -1372,16 +1415,16 @@ }, { "name": "maximebf/debugbar", - "version": "v1.12.0", + "version": "v1.13.0", "source": { "type": "git", "url": "https://github.com/maximebf/php-debugbar.git", - "reference": "e634fbd32cd6bc3fa0e8c972b52d4bf49bab3988" + "reference": "5f49a5ed6cfde81d31d89378806670d77462526e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/e634fbd32cd6bc3fa0e8c972b52d4bf49bab3988", - "reference": "e634fbd32cd6bc3fa0e8c972b52d4bf49bab3988", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/5f49a5ed6cfde81d31d89378806670d77462526e", + "reference": "5f49a5ed6cfde81d31d89378806670d77462526e", "shasum": "" }, "require": { @@ -1400,7 +1443,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.12-dev" + "dev-master": "1.13-dev" } }, "autoload": { @@ -1429,7 +1472,7 @@ "debug", "debugbar" ], - "time": "2016-05-15 13:11:34" + "time": "2016-09-15 14:01:59" }, { "name": "monolog/monolog", @@ -1762,22 +1805,30 @@ }, { "name": "psr/log", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + "reference": "5277094ed527a1c4477177d102fe4c53551953e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "url": "https://api.github.com/repos/php-fig/log/zipball/5277094ed527a1c4477177d102fe4c53551953e0", + "reference": "5277094ed527a1c4477177d102fe4c53551953e0", "shasum": "" }, + "require": { + "php": ">=5.3.0" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { - "psr-0": { - "Psr\\Log\\": "" + "psr-4": { + "Psr\\Log\\": "Psr/Log/" } }, "notification-url": "https://packagist.org/downloads/", @@ -1791,12 +1842,13 @@ } ], "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", "keywords": [ "log", "psr", "psr-3" ], - "time": "2012-12-21 11:40:51" + "time": "2016-09-19 16:02:08" }, { "name": "psy/psysh", @@ -2953,16 +3005,16 @@ }, { "name": "twig/twig", - "version": "v1.24.2", + "version": "v1.25.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "33093f6e310e6976baeac7b14f3a6ec02f2d79b7" + "reference": "f16a634ab08d87e520da5671ec52153d627f10f6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/33093f6e310e6976baeac7b14f3a6ec02f2d79b7", - "reference": "33093f6e310e6976baeac7b14f3a6ec02f2d79b7", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/f16a634ab08d87e520da5671ec52153d627f10f6", + "reference": "f16a634ab08d87e520da5671ec52153d627f10f6", "shasum": "" }, "require": { @@ -2975,7 +3027,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.24-dev" + "dev-master": "1.25-dev" } }, "autoload": { @@ -3010,7 +3062,7 @@ "keywords": [ "templating" ], - "time": "2016-09-01 17:50:53" + "time": "2016-09-21 23:05:12" }, { "name": "vlucas/phpdotenv", @@ -3827,24 +3879,24 @@ }, { "name": "phpunit/phpunit", - "version": "5.5.4", + "version": "5.5.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5" + "reference": "a57126dc681b08289fef6ac96a48e30656f84350" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3e6e88e56c912133de6e99b87728cca7ed70c5f5", - "reference": "3e6e88e56c912133de6e99b87728cca7ed70c5f5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a57126dc681b08289fef6ac96a48e30656f84350", + "reference": "a57126dc681b08289fef6ac96a48e30656f84350", "shasum": "" }, "require": { "ext-dom": "*", "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", "myclabs/deep-copy": "~1.3", "php": "^5.6 || ^7.0", "phpspec/prophecy": "^1.3.1", @@ -3866,7 +3918,12 @@ "conflict": { "phpdocumentor/reflection-docblock": "3.0.2" }, + "require-dev": { + "ext-pdo": "*" + }, "suggest": { + "ext-tidy": "*", + "ext-xdebug": "*", "phpunit/php-invoker": "~1.1" }, "bin": [ @@ -3901,7 +3958,7 @@ "testing", "xunit" ], - "time": "2016-08-26 07:11:44" + "time": "2016-09-21 14:40:13" }, { "name": "phpunit/phpunit-mock-objects",