1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Fixes for randomdataseeder

This commit is contained in:
David Bomba 2023-10-13 21:18:03 +11:00
parent 999ead0fec
commit 6e92666400

View File

@ -47,11 +47,12 @@ use App\Repositories\InvoiceRepository;
use Illuminate\Database\Eloquent\Model;
use App\Events\Payment\PaymentWasCreated;
use App\Helpers\Invoice\InvoiceSumInclusive;
use App\Utils\Traits\AppSetup;
class RandomDataSeeder extends Seeder
{
use \App\Utils\Traits\MakesHash;
use AppSetup;
/**
* Run the database seeds.
*
@ -59,30 +60,8 @@ 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->buildCache(true);
$this->command->info('Running RandomDataSeeder');