mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for created_at dates in migration
This commit is contained in:
parent
2109b8be52
commit
7808b4c30d
@ -21,6 +21,7 @@ use App\Mail\ExistingMigration;
|
|||||||
use App\Mail\Migration\MaxCompanies;
|
use App\Mail\Migration\MaxCompanies;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\CompanyToken;
|
use App\Models\CompanyToken;
|
||||||
|
use App\Utils\Ninja;
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -378,14 +379,15 @@ class MigrationController extends BaseController
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try {
|
|
||||||
// StartMigration::dispatch(base_path("storage/app/public/$migration_file"), $user, $fresh_company)->delay(now()->addSeconds(5));
|
|
||||||
nlog("starting migration job");
|
nlog("starting migration job");
|
||||||
nlog($migration_file);
|
nlog($migration_file);
|
||||||
StartMigration::dispatch($migration_file, $user, $fresh_company)->onQueue('migration');
|
|
||||||
// } catch (\Exception $e) {
|
if(Ninja::isHosted())
|
||||||
// nlog($e->getMessage());
|
StartMigration::dispatch($migration_file, $user, $fresh_company)->onQueue('migration');
|
||||||
// }
|
else
|
||||||
|
StartMigration::dispatch($migration_file, $user, $fresh_company);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,6 @@ class SelfUpdateController extends BaseController
|
|||||||
if (file_exists($cacheServices)) { unlink ($cacheServices); }
|
if (file_exists($cacheServices)) { unlink ($cacheServices); }
|
||||||
|
|
||||||
Artisan::call('clear-compiled');
|
Artisan::call('clear-compiled');
|
||||||
Artisan::call('cache:clear');
|
|
||||||
Artisan::call('route:clear');
|
Artisan::call('route:clear');
|
||||||
Artisan::call('view:clear');
|
Artisan::call('view:clear');
|
||||||
Artisan::call('config:clear');
|
Artisan::call('config:clear');
|
||||||
|
@ -83,6 +83,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
|||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
@ -461,6 +462,8 @@ class Import implements ShouldQueue
|
|||||||
|
|
||||||
private function checkUniqueConstraint($model, $column, $value)
|
private function checkUniqueConstraint($model, $column, $value)
|
||||||
{
|
{
|
||||||
|
$value = trim($value);
|
||||||
|
|
||||||
$model_query = (new $model())
|
$model_query = (new $model())
|
||||||
->query()
|
->query()
|
||||||
->where($column, $value)
|
->where($column, $value)
|
||||||
@ -503,10 +506,10 @@ class Import implements ShouldQueue
|
|||||||
);
|
);
|
||||||
|
|
||||||
if(array_key_exists('created_at', $modified))
|
if(array_key_exists('created_at', $modified))
|
||||||
$client->created_at = $modified['created_at'];
|
$client->created_at = Carbon::parse($modified['created_at']);
|
||||||
|
|
||||||
if(array_key_exists('updated_at', $modified))
|
if(array_key_exists('updated_at', $modified))
|
||||||
$client->updated_at = $modified['updated_at'];
|
$client->updated_at = Carbon::parse($modified['updated_at']);
|
||||||
|
|
||||||
$client->save(['timestamps' => false]);
|
$client->save(['timestamps' => false]);
|
||||||
|
|
||||||
@ -583,6 +586,12 @@ class Import implements ShouldQueue
|
|||||||
unset($modified['id']);
|
unset($modified['id']);
|
||||||
unset($modified['contacts']);
|
unset($modified['contacts']);
|
||||||
|
|
||||||
|
if(array_key_exists('created_at', $modified))
|
||||||
|
$modified['created_at'] = Carbon::parse($modified['created_at']);
|
||||||
|
|
||||||
|
if(array_key_exists('updated_at', $modified))
|
||||||
|
$modified['updated_at'] = Carbon::parse($modified['updated_at']);
|
||||||
|
|
||||||
$vendor = $vendor_repository->save(
|
$vendor = $vendor_repository->save(
|
||||||
$modified,
|
$modified,
|
||||||
VendorFactory::create(
|
VendorFactory::create(
|
||||||
@ -650,6 +659,12 @@ class Import implements ShouldQueue
|
|||||||
$modified['company_id'] = $this->company->id;
|
$modified['company_id'] = $this->company->id;
|
||||||
$modified['user_id'] = $this->processUserId($resource);
|
$modified['user_id'] = $this->processUserId($resource);
|
||||||
|
|
||||||
|
if(array_key_exists('created_at', $modified))
|
||||||
|
$modified['created_at'] = Carbon::parse($modified['created_at']);
|
||||||
|
|
||||||
|
if(array_key_exists('updated_at', $modified))
|
||||||
|
$modified['updated_at'] = Carbon::parse($modified['updated_at']);
|
||||||
|
|
||||||
unset($modified['id']);
|
unset($modified['id']);
|
||||||
|
|
||||||
$product_repository->save(
|
$product_repository->save(
|
||||||
@ -696,6 +711,12 @@ class Import implements ShouldQueue
|
|||||||
$modified['company_id'] = $this->company->id;
|
$modified['company_id'] = $this->company->id;
|
||||||
$modified['line_items'] = $this->cleanItems($modified['line_items']);
|
$modified['line_items'] = $this->cleanItems($modified['line_items']);
|
||||||
|
|
||||||
|
if(array_key_exists('created_at', $modified))
|
||||||
|
$modified['created_at'] = Carbon::parse($modified['created_at']);
|
||||||
|
|
||||||
|
if(array_key_exists('updated_at', $modified))
|
||||||
|
$modified['updated_at'] = Carbon::parse($modified['updated_at']);
|
||||||
|
|
||||||
unset($modified['id']);
|
unset($modified['id']);
|
||||||
|
|
||||||
if (array_key_exists('invitations', $resource)) {
|
if (array_key_exists('invitations', $resource)) {
|
||||||
@ -832,6 +853,12 @@ class Import implements ShouldQueue
|
|||||||
$modified['user_id'] = $this->processUserId($resource);
|
$modified['user_id'] = $this->processUserId($resource);
|
||||||
$modified['company_id'] = $this->company->id;
|
$modified['company_id'] = $this->company->id;
|
||||||
|
|
||||||
|
if(array_key_exists('created_at', $modified))
|
||||||
|
$modified['created_at'] = Carbon::parse($modified['created_at']);
|
||||||
|
|
||||||
|
if(array_key_exists('updated_at', $modified))
|
||||||
|
$modified['updated_at'] = Carbon::parse($modified['updated_at']);
|
||||||
|
|
||||||
unset($modified['id']);
|
unset($modified['id']);
|
||||||
|
|
||||||
$credit = $credit_repository->save(
|
$credit = $credit_repository->save(
|
||||||
@ -891,6 +918,18 @@ class Import implements ShouldQueue
|
|||||||
|
|
||||||
$modified['company_id'] = $this->company->id;
|
$modified['company_id'] = $this->company->id;
|
||||||
|
|
||||||
|
if(array_key_exists('created_at', $modified))
|
||||||
|
$modified['created_at'] = Carbon::parse($modified['created_at']);
|
||||||
|
|
||||||
|
if(array_key_exists('updated_at', $modified))
|
||||||
|
$modified['updated_at'] = Carbon::parse($modified['updated_at']);
|
||||||
|
|
||||||
|
if(array_key_exists('tax_rate1', $modified) && is_null($modified['tax_rate1']))
|
||||||
|
$modified['tax_rate1'] = 0;
|
||||||
|
|
||||||
|
if(array_key_exists('tax_rate2', $modified) && is_null($modified['tax_rate2']))
|
||||||
|
$modified['tax_rate2'] = 0;
|
||||||
|
|
||||||
unset($modified['id']);
|
unset($modified['id']);
|
||||||
|
|
||||||
|
|
||||||
@ -988,10 +1027,10 @@ class Import implements ShouldQueue
|
|||||||
);
|
);
|
||||||
|
|
||||||
if(array_key_exists('created_at', $modified))
|
if(array_key_exists('created_at', $modified))
|
||||||
$payment->created_at = $modified['created_at'];
|
$payment->created_at = Carbon::parse($modified['created_at']);
|
||||||
|
|
||||||
if(array_key_exists('updated_at', $modified))
|
if(array_key_exists('updated_at', $modified))
|
||||||
$payment->updated_at = $modified['updated_at'];
|
$payment->updated_at = Carbon::parse($modified['updated_at']);
|
||||||
|
|
||||||
$payment->save(['timestamps' => false]);
|
$payment->save(['timestamps' => false]);
|
||||||
|
|
||||||
@ -1358,10 +1397,12 @@ class Import implements ShouldQueue
|
|||||||
$task = Task::Create($modified);
|
$task = Task::Create($modified);
|
||||||
|
|
||||||
if(array_key_exists('created_at', $modified))
|
if(array_key_exists('created_at', $modified))
|
||||||
$task->created_at = $modified['created_at'];
|
$task->created_at = Carbon::parse($modified['created_at']);
|
||||||
|
|
||||||
if(array_key_exists('updated_at', $modified))
|
if(array_key_exists('updated_at', $modified))
|
||||||
$task->updated_at = $modified['updated_at'];
|
$task->updated_at = Carbon::parse($modified['updated_at']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$task->save(['timestamps' => false]);
|
$task->save(['timestamps' => false]);
|
||||||
|
|
||||||
@ -1446,10 +1487,12 @@ class Import implements ShouldQueue
|
|||||||
$expense = Expense::Create($modified);
|
$expense = Expense::Create($modified);
|
||||||
|
|
||||||
if(array_key_exists('created_at', $modified))
|
if(array_key_exists('created_at', $modified))
|
||||||
$expense->created_at = $modified['created_at'];
|
$expense->created_at = Carbon::parse($modified['created_at']);
|
||||||
|
|
||||||
if(array_key_exists('updated_at', $modified))
|
if(array_key_exists('updated_at', $modified))
|
||||||
$expense->updated_at = $modified['updated_at'];
|
$expense->updated_at = Carbon::parse($modified['updated_at']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$expense->save(['timestamps' => false]);
|
$expense->save(['timestamps' => false]);
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ class SchedulerCheck implements ShouldQueue
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Artisan::call('clear-compiled');
|
Artisan::call('clear-compiled');
|
||||||
Artisan::call('cache:clear');
|
|
||||||
Artisan::call('route:clear');
|
Artisan::call('route:clear');
|
||||||
Artisan::call('config:cache');
|
Artisan::call('config:cache');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -91,6 +91,21 @@ class StartMigration implements ShouldQueue
|
|||||||
$archive = $zip->open(public_path("storage/{$this->filepath}"));
|
$archive = $zip->open(public_path("storage/{$this->filepath}"));
|
||||||
$filename = pathinfo($this->filepath, PATHINFO_FILENAME);
|
$filename = pathinfo($this->filepath, PATHINFO_FILENAME);
|
||||||
|
|
||||||
|
if($this->company->id == $this->company->account->default_company_id)
|
||||||
|
{
|
||||||
|
$new_default_company = $this->company->account->companies->first();
|
||||||
|
|
||||||
|
if ($new_default_company) {
|
||||||
|
$this->company->account->default_company_id = $new_default_company->id;
|
||||||
|
$this->company->account->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$update_product_flag = $this->company->update_products;
|
||||||
|
|
||||||
|
$this->company->update_products = false;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (! $archive) {
|
if (! $archive) {
|
||||||
throw new ProcessingMigrationArchiveFailed('Processing migration archive failed. Migration file is possibly corrupted.');
|
throw new ProcessingMigrationArchiveFailed('Processing migration archive failed. Migration file is possibly corrupted.');
|
||||||
@ -113,7 +128,16 @@ class StartMigration implements ShouldQueue
|
|||||||
|
|
||||||
Storage::deleteDirectory(public_path("storage/migrations/{$filename}"));
|
Storage::deleteDirectory(public_path("storage/migrations/{$filename}"));
|
||||||
|
|
||||||
} catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) {
|
$this->company->account->default_company_id = $this->company->id;
|
||||||
|
$this->company->account->save();
|
||||||
|
|
||||||
|
$this->company->update_products = $update_product_flag;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
|
} catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing | \Exception $e) {
|
||||||
|
|
||||||
|
$this->company->update_products = $update_product_flag;
|
||||||
|
$this->company->save();
|
||||||
|
|
||||||
Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage()));
|
Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage()));
|
||||||
|
|
||||||
|
@ -302,11 +302,6 @@ class BaseRepository
|
|||||||
/* Perform model specific tasks */
|
/* Perform model specific tasks */
|
||||||
if ($model instanceof Invoice) {
|
if ($model instanceof Invoice) {
|
||||||
|
|
||||||
nlog("in base");
|
|
||||||
nlog($state['finished_amount']);
|
|
||||||
nlog($state['starting_amount']);
|
|
||||||
nlog($model->status_id);
|
|
||||||
|
|
||||||
if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {
|
if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {
|
||||||
|
|
||||||
$model->service()->updateStatus()->save();
|
$model->service()->updateStatus()->save();
|
||||||
|
@ -23,6 +23,7 @@ use App\Models\RecurringInvoiceInvitation;
|
|||||||
use App\Repositories\BaseRepository;
|
use App\Repositories\BaseRepository;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\SavesDocuments;
|
use App\Utils\Traits\SavesDocuments;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,6 +60,12 @@ class InvoiceMigrationRepository extends BaseRepository
|
|||||||
|
|
||||||
$tmp_data = $data;
|
$tmp_data = $data;
|
||||||
|
|
||||||
|
if(array_key_exists('tax_rate1', $tmp_data) && is_null($tmp_data['tax_rate1']))
|
||||||
|
$tmp_data['tax_rate1'] = 0;
|
||||||
|
|
||||||
|
if(array_key_exists('tax_rate2', $tmp_data) && is_null($tmp_data['tax_rate2']))
|
||||||
|
$tmp_data['tax_rate2'] = 0;
|
||||||
|
|
||||||
/* We need to unset some variable as we sometimes unguard the model */
|
/* We need to unset some variable as we sometimes unguard the model */
|
||||||
|
|
||||||
if (isset($tmp_data['invitations'])) {
|
if (isset($tmp_data['invitations'])) {
|
||||||
@ -71,7 +78,15 @@ class InvoiceMigrationRepository extends BaseRepository
|
|||||||
|
|
||||||
$model->fill($tmp_data);
|
$model->fill($tmp_data);
|
||||||
$model->status_id = $tmp_data['status_id'];
|
$model->status_id = $tmp_data['status_id'];
|
||||||
$model->save();
|
|
||||||
|
if($tmp_data['created_at'])
|
||||||
|
$model->created_at = Carbon::parse($tmp_data['created_at']);
|
||||||
|
|
||||||
|
if($tmp_data['updated_at'])
|
||||||
|
$model->updated_at = Carbon::parse($tmp_data['updated_at']);
|
||||||
|
|
||||||
|
$model->save(['timestamps' => false]);
|
||||||
|
|
||||||
|
|
||||||
if (array_key_exists('documents', $data)) {
|
if (array_key_exists('documents', $data)) {
|
||||||
$this->saveDocuments($data['documents'], $model);
|
$this->saveDocuments($data['documents'], $model);
|
||||||
@ -130,10 +145,6 @@ class InvoiceMigrationRepository extends BaseRepository
|
|||||||
$model->design_id = $this->decodePrimaryKey($client->getSetting('invoice_design_id'));
|
$model->design_id = $this->decodePrimaryKey($client->getSetting('invoice_design_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($model->company->update_products) {
|
|
||||||
//UpdateOrCreateProduct::dispatchNow($model->line_items, $model, $model->company);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($class->name == Credit::class) {
|
if ($class->name == Credit::class) {
|
||||||
|
@ -54,7 +54,7 @@ trait AppSetup
|
|||||||
$orderBy = 'id';
|
$orderBy = 'id';
|
||||||
}
|
}
|
||||||
$tableData = $class::orderBy($orderBy)->get();
|
$tableData = $class::orderBy($orderBy)->get();
|
||||||
if ($tableData->count()) {
|
if ($tableData->count() > 1) {
|
||||||
Cache::forever($name, $tableData);
|
Cache::forever($name, $tableData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user