Fixes for migration

This commit is contained in:
David Bomba 2020-11-23 12:46:16 +11:00
parent 388c0e8467
commit 4b1aabbac7
4 changed files with 12 additions and 13 deletions

View File

@ -51,7 +51,7 @@ class InvoiceItem
public $custom_value4 = '';
public $type_id = 1; //1 = product, 2 = service, 3 unpaid gateway fee, 4 paid gateway fee, 5 late fee
public $type_id = '1'; //1 = product, 2 = service, 3 unpaid gateway fee, 4 paid gateway fee, 5 late fee
public static $casts = [
'type_id' => 'string',

View File

@ -219,6 +219,7 @@ class MigrationController extends BaseController
*/
public function startMigration(Request $request)
{
$companies = json_decode($request->companies);
if (app()->environment() === 'local') {
@ -226,21 +227,21 @@ class MigrationController extends BaseController
}
foreach ($companies as $company) {
$is_valid = $request->file($company->company_key)->isValid();
$is_valid = $request->file($company->company_index)->isValid();
if (!$is_valid) {
// We might want to send user something's wrong with migration or nope?
continue;
}
$user = auth()->user();
// Look for possible existing company (based on company keys).
$existing_company = Company::where('company_key', $request->company_key)->first();
$existing_company = Company::whereRaw('BINARY `company_key` = ?', [$company->company_key])->first();
$checks = [
'existing_company' => (bool) $existing_company,
'existing_company' => $existing_company ? (bool)1 : false,
'force' => property_exists($company, 'force') ? (bool) $company->force : false,
];
@ -259,6 +260,7 @@ class MigrationController extends BaseController
// If there's existing company and force ** is provided ** - purge the company and migrate again.
if ($checks['existing_company'] == true && $checks['force'] == true) {
info("purging the existing company here");
$this->purgeCompanyWithForceFlag($existing_company);
$account = auth()->user()->account;
@ -318,10 +320,10 @@ class MigrationController extends BaseController
]);
}
$migration_file = $request->file($company->company_key)
$migration_file = $request->file($company->company_index)
->storeAs(
'migrations',
$request->file($company->company_key)->getClientOriginalName()
$request->file($company->company_index)->getClientOriginalName()
);
if (app()->environment() == 'testing') {
@ -329,7 +331,7 @@ class MigrationController extends BaseController
}
try {
StartMigration::dispatch(base_path("storage/app/public/$migration_file"), $user, $fresh_company)->delay(now()->addSeconds(60));
StartMigration::dispatch(base_path("storage/app/public/$migration_file"), $user, $fresh_company)->delay(now()->addSeconds(5));
} catch (\Exception $e) {
info($e->getMessage());
}

View File

@ -164,7 +164,7 @@ class PaymentMigrationRepository extends BaseRepository
*/
private function processExchangeRates($data, $payment)
{
$client = Client::find($data['client_id'])->withTrashed();
$client = Client::where('id', $data['client_id'])->withTrashed()->first();
$client_currency = $client->getSetting('currency_id');
$company_currency = $client->company->settings->currency_id;

View File

@ -29,9 +29,6 @@ trait CleanLineItems
foreach ($items as $item) {
if(is_array($item))
continue;
$cleaned_items[] = $this->cleanLineItem($item);
}