From a7f939c6b93656e6daf20085703bbc4e97d827b7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 1 Dec 2019 09:59:51 +1100 Subject: [PATCH] Fixes for seeder and typo in readme (#3109) * Adjustments for template controller to make entity and entity_id optional * Fixes for seeder * Fix for typo --- README.md | 2 +- database/seeds/RandomDataSeeder.php | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b534db8bf27..66c0890fd6fa 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ We will be using the lessons learnt in Invoice Ninja 4.0 to build a bigger bette ## Quick Start -Curently the client portal and API are of alpha quality, to get started: +Currently the client portal and API are of alpha quality, to get started: ```bash git clone https://github.com/invoiceninja/invoiceninja.git diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 0597cfc3be06..8bfc090ad70b 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -25,6 +25,8 @@ use App\Models\User; use App\Models\UserAccount; use App\Repositories\InvoiceRepository; use Illuminate\Database\Seeder; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Schema; class RandomDataSeeder extends Seeder { @@ -37,6 +39,31 @@ class RandomDataSeeder extends Seeder public function run() { + /* Warm up the cache !*/ + $cached_tables = config('ninja.cached_tables'); + + foreach ($cached_tables as $name => $class) { + if (! Cache::has($name)) { + // check that the table exists in case the migration is pending + if (! Schema::hasTable((new $class())->getTable())) { + continue; + } + if ($name == 'payment_terms') { + $orderBy = 'num_days'; + } elseif ($name == 'fonts') { + $orderBy = 'sort_order'; + } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { + $orderBy = 'name'; + } else { + $orderBy = 'id'; + } + $tableData = $class::orderBy($orderBy)->get(); + if ($tableData->count()) { + Cache::forever($name, $tableData); + } + } + } + $this->command->info('Running RandomDataSeeder');