Merge pull request #8869 from turbo124/v5-develop

Fixes for RandomDataSeeder
This commit is contained in:
David Bomba 2023-10-13 21:18:32 +11:00 committed by GitHub
commit 799332409a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 31 deletions

View File

@ -32,7 +32,7 @@ class EmailHistoryController extends BaseController
->orderBy('id', 'DESC')
->cursor()
->map(function ($system_log) {
if($system_log->log['history'] ?? false) {
if(($system_log->log['history'] && $system_log->log['history']['events'] && count($system_log->log['history']['events']) >=1) ?? false) {
return $system_log->log['history'];
}
});
@ -57,7 +57,7 @@ class EmailHistoryController extends BaseController
->orderBy('id', 'DESC')
->cursor()
->map(function ($system_log) {
if($system_log->log['history'] ?? false) {
if(($system_log->log['history'] && $system_log->log['history']['events'] && count($system_log->log['history']['events']) >=1) ?? false) {
return $system_log->log['history'];
}
});

View File

@ -44,6 +44,19 @@ class ClientService
}, 2);
} catch (\Throwable $throwable) {
nlog("DB ERROR " . $throwable->getMessage());
DB::connection(config('database.default'))->rollBack();
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
} catch(\Exception $exception){
nlog("DB ERROR " . $exception->getMessage());
DB::connection(config('database.default'))->rollBack();
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
}
return $this;
@ -60,6 +73,17 @@ class ClientService
}, 2);
} catch (\Throwable $throwable) {
nlog("DB ERROR " . $throwable->getMessage());
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
} catch(\Exception $exception){
nlog("DB ERROR " . $exception->getMessage());
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
}
return $this;
@ -67,11 +91,27 @@ class ClientService
public function updatePaidToDate(float $amount)
{
DB::connection(config('database.default'))->transaction(function () use ($amount) {
$this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
$this->client->paid_to_date += $amount;
$this->client->saveQuietly();
}, 2);
try {
DB::connection(config('database.default'))->transaction(function () use ($amount) {
$this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
$this->client->paid_to_date += $amount;
$this->client->saveQuietly();
}, 2);
}
catch (\Throwable $throwable) {
nlog("DB ERROR " . $throwable->getMessage());
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
} catch(\Exception $exception){
nlog("DB ERROR " . $exception->getMessage());
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
DB::connection(config('database.default'))->rollBack();
}
}
return $this;
}

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');

View File

@ -5179,6 +5179,7 @@ $LANG = array(
'stock_quantity_number' => 'Stock :quantity',
'upcoming' => 'Upcoming',
'client_contact' => 'Client Contact',
'uncategorized' => 'Uncategorized',
);
return $LANG;