mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Debugging migrations (#3570)
* Remove \Log::, fixes for tests, and fixes for migration * Debugging migration
This commit is contained in:
parent
9f563d2fbf
commit
91cf1cc1f2
@ -56,4 +56,4 @@ SELF_UPDATER_USE_BRANCH = v2
|
||||
SELF_UPDATER_MAILTO_ADDRESS = user@example.com
|
||||
SELF_UPDATER_MAILTO_NAME = "John Doe"
|
||||
COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
|
||||
|
||||
SENTRY_LARAVEL_DSN=https://cc7e8e2c678041689e53e409b7dba236@sentry.invoicing.co/5
|
@ -175,7 +175,6 @@ class Designer
|
||||
if (strlen($this->exported_variables['$product_table_body']) == 0) {
|
||||
$this->exported_variables['$product_table_header'] = '';
|
||||
}
|
||||
//\Log::error("Exporting variables took = ".(microtime(true)-$s));
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -92,10 +92,8 @@ class InvoiceController extends Controller
|
||||
*/
|
||||
public function bulk(ProcessInvoicesInBulkRequest $request)
|
||||
{
|
||||
// \Log::error($request->all());
|
||||
$transformed_ids = $this->transformKeys($request->invoices);
|
||||
|
||||
//\Log::error($transformed_ids);
|
||||
$transformed_ids = $this->transformKeys($request->invoices);
|
||||
|
||||
if ($request->input('action') == 'payment') {
|
||||
return $this->makePayment((array)$transformed_ids);
|
||||
@ -112,7 +110,6 @@ class InvoiceController extends Controller
|
||||
$invoices = Invoice::whereIn('id', $ids)
|
||||
->whereClientId(auth()->user()->client->id)
|
||||
->get();
|
||||
//\Log::error($invoices);
|
||||
|
||||
$total = $invoices->sum('balance');
|
||||
|
||||
|
@ -687,7 +687,7 @@ class InvoiceController extends BaseController
|
||||
});
|
||||
|
||||
if ($invoice->invitations->count() > 0) {
|
||||
\Log::error("more than one invitation to send");
|
||||
|
||||
event(new InvoiceWasEmailed($invoice->invitations->first()));
|
||||
}
|
||||
|
||||
|
@ -151,8 +151,6 @@ class PreviewController extends BaseController
|
||||
|
||||
$design_object = json_decode(json_encode(request()->input('design')));
|
||||
|
||||
//\Log::error(print_r($design_object,1));
|
||||
|
||||
if (!is_object($design_object)) {
|
||||
return response()->json(['message' => 'Invalid custom design object'], 400);
|
||||
}
|
||||
|
@ -11,13 +11,16 @@
|
||||
|
||||
namespace App\Http\Requests\Company;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Http\ValidationRules\ValidSettingsRule;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateCompanyRequest extends Request
|
||||
{
|
||||
use MakesHash;
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
@ -53,4 +56,5 @@ class UpdateCompanyRequest extends Request
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,8 +49,6 @@ class PortalComposer
|
||||
$data['client'] = auth()->user()->client;
|
||||
$data['settings'] = auth()->user()->client->getMergedSettings();
|
||||
|
||||
//\Log::error(print_r($data['settings'],1));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,15 @@ class CreateAccount
|
||||
{
|
||||
|
||||
if(config('ninja.environment') == 'selfhost' && Account::all()->count() == 0) {
|
||||
$this->create();
|
||||
return $this->create();
|
||||
}elseif (config('ninja.environment') == 'selfhost' && Account::all()->count() > 1) {
|
||||
return response()->json(array('message' => Ninja::selfHostedMessage()), 400);
|
||||
return response()->json(array('message' => Ninja::selfHostedMessage()), 400);
|
||||
} elseif (!Ninja::boot()) {
|
||||
return response()->json(array('message' => Ninja::parse()), 401);
|
||||
return response()->json(array('message' => Ninja::parse()), 401);
|
||||
}
|
||||
|
||||
return $this->create();
|
||||
|
||||
}
|
||||
|
||||
private function create()
|
||||
@ -48,28 +50,35 @@ class CreateAccount
|
||||
|
||||
$sp794f3f = Account::create($this->request);
|
||||
$sp794f3f->referral_code = Str::random(32);
|
||||
|
||||
|
||||
if(!$sp794f3f->key)
|
||||
$sp794f3f->key = Str::random(32);
|
||||
|
||||
|
||||
$sp794f3f->save();
|
||||
|
||||
|
||||
$sp035a66 = CreateCompany::dispatchNow($this->request, $sp794f3f);
|
||||
$sp035a66->load('account');
|
||||
$sp794f3f->default_company_id = $sp035a66->id;
|
||||
$sp794f3f->save();
|
||||
|
||||
$spaa9f78 = CreateUser::dispatchNow($this->request, $sp794f3f, $sp035a66, true);
|
||||
|
||||
if ($spaa9f78) {
|
||||
auth()->login($spaa9f78, false);
|
||||
}
|
||||
|
||||
$spaa9f78->setCompany($sp035a66);
|
||||
$spafe62e = isset($this->request['token_name']) ? $this->request['token_name'] : request()->server('HTTP_USER_AGENT');
|
||||
$sp2d97e8 = CreateCompanyToken::dispatchNow($sp035a66, $spaa9f78, $spafe62e);
|
||||
|
||||
if ($spaa9f78) {
|
||||
event(new AccountCreated($spaa9f78));
|
||||
}
|
||||
|
||||
$spaa9f78->fresh();
|
||||
|
||||
$sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja();
|
||||
|
||||
return $sp794f3f;
|
||||
|
||||
}
|
||||
|
@ -87,13 +87,10 @@ class CreateCreditPdf implements ShouldQueue
|
||||
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
|
||||
Storage::makeDirectory($path, 0755);
|
||||
|
||||
//\Log::error($html);
|
||||
$pdf = $this->makePdf(null, null, $html);
|
||||
|
||||
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
|
||||
//$instance= Storage::disk($this->disk)->path($file_path);
|
||||
//
|
||||
return $file_path;
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,6 @@ class CreateInvoicePdf implements ShouldQueue
|
||||
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
|
||||
Storage::makeDirectory($path, 0755);
|
||||
|
||||
//\Log::error($html);
|
||||
$pdf = $this->makePdf(null, null, $html);
|
||||
|
||||
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Jobs\Util;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Exceptions\MigrationValidatorFailed;
|
||||
use App\Exceptions\ResourceDependencyMissing;
|
||||
use App\Exceptions\ResourceNotAvailableForMigration;
|
||||
@ -41,6 +42,7 @@ use App\Repositories\ProductRepository;
|
||||
use App\Repositories\QuoteRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use App\Utils\Traits\CompanyGatewayFeesAndLimitsSaver;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@ -54,6 +56,7 @@ class Import implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use CompanyGatewayFeesAndLimitsSaver;
|
||||
use MakesHash;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
@ -129,7 +132,7 @@ class Import implements ShouldQueue
|
||||
public function handle()
|
||||
{
|
||||
foreach ($this->data as $key => $resource) {
|
||||
\Log::error("importing {$key}");
|
||||
|
||||
if (!in_array($key, $this->available_imports)) {
|
||||
throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration.");
|
||||
}
|
||||
@ -138,7 +141,6 @@ class Import implements ShouldQueue
|
||||
|
||||
$this->{$method}($resource);
|
||||
|
||||
info("$key done!!");
|
||||
}
|
||||
|
||||
info('Completed🚀🚀🚀🚀🚀 at ' . now());
|
||||
@ -152,12 +154,14 @@ class Import implements ShouldQueue
|
||||
{
|
||||
Company::unguard();
|
||||
|
||||
$data = $this->transformCompanyData($data);
|
||||
|
||||
$rules = (new UpdateCompanyRequest())->rules();
|
||||
|
||||
$validator = Validator::make($data, $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
// \Log::error($validator->errors());
|
||||
|
||||
throw new MigrationValidatorFailed(json_encode($validator->errors()));
|
||||
}
|
||||
|
||||
@ -171,6 +175,32 @@ class Import implements ShouldQueue
|
||||
Company::reguard();
|
||||
}
|
||||
|
||||
private function transformCompanyData(array $data): array
|
||||
{
|
||||
|
||||
$company_settings = CompanySettings::defaults();
|
||||
|
||||
if (array_key_exists('settings', $data) ) {
|
||||
|
||||
foreach ($data['settings'] as $key => $value) {
|
||||
|
||||
if($key == 'invoice_design_id' || $key == 'quote_design_id' || $key == 'credit_design_id')
|
||||
{
|
||||
$value = $this->encodePrimaryKey($value);
|
||||
}
|
||||
|
||||
$company_settings->{$key} = $value;
|
||||
|
||||
}
|
||||
|
||||
$data['settings'] = $company_settings;
|
||||
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @throws \Exception
|
||||
|
@ -58,7 +58,7 @@ class StartMigration implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
\Log::error("start handle");
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
auth()->login($this->user, false);
|
||||
@ -91,7 +91,6 @@ class StartMigration implements ShouldQueue
|
||||
}
|
||||
}
|
||||
|
||||
\Log::error("stop handle");
|
||||
}
|
||||
|
||||
|
||||
@ -101,7 +100,6 @@ class StartMigration implements ShouldQueue
|
||||
*/
|
||||
public function start(string $filename): void
|
||||
{
|
||||
\Log::error("start start");
|
||||
|
||||
$file = storage_path("migrations/$filename/migration.json");
|
||||
|
||||
@ -116,7 +114,5 @@ class StartMigration implements ShouldQueue
|
||||
$data = json_decode($file, 1);
|
||||
Import::dispatchNow($data, $this->company, $this->user);
|
||||
|
||||
|
||||
\Log::error("start stop");
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +182,6 @@ class MultiDB
|
||||
|
||||
public static function findAndSetDbByDomain($subdomain) :bool
|
||||
{
|
||||
//\Log::error("searching for {$domain}");
|
||||
|
||||
foreach (self::$dbs as $db) {
|
||||
if ($company = Company::on($db)->whereSubdomain($subdomain)->first()) {
|
||||
|
@ -168,11 +168,5 @@ class EventServiceProvider extends ServiceProvider
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
//$events->subscribe('*');
|
||||
// \Event::listen('event.*', function ($eventName, array $data) {
|
||||
// \Log::error("Event Service Provider");
|
||||
// });
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,6 @@ class MultiDBProvider extends ServiceProvider
|
||||
|
||||
if (isset($event->job->payload()['db'])) {
|
||||
|
||||
//\Log::error("Provider Setting DB = ".$event->job->payload()['db']);
|
||||
//\Log::error('Event Job '.$event->connectionName);
|
||||
// \Log::error(print_r($event->job,1));
|
||||
//\Log::error(print_r($event->job->payload(),1));
|
||||
|
||||
MultiDB::setDb($event->job->payload()['db']);
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +209,17 @@ class BaseRepository
|
||||
$data = array_merge($company_defaults, $data);
|
||||
}
|
||||
|
||||
$model->fill($data);
|
||||
$tmp_data = $data;
|
||||
|
||||
if(isset($tmp_data['invitations']))
|
||||
unset($tmp_data['invitations']);
|
||||
|
||||
if(isset($tmp_data['client_contacts']))
|
||||
unset($tmp_data['client_contacts']);
|
||||
|
||||
\Log::error(print_r($tmp_data,1));
|
||||
|
||||
$model->fill($tmp_data);
|
||||
$model->save();
|
||||
|
||||
$invitation_factory_class = sprintf("App\\Factory\\%sInvitationFactory", $resource);
|
||||
@ -234,6 +244,8 @@ class BaseRepository
|
||||
|
||||
foreach ($data['invitations'] as $invitation) {
|
||||
|
||||
\Log::error(print_r($invitation,1));
|
||||
|
||||
//if no invitations are present - create one.
|
||||
if (! $this->getInvitation($invitation, $resource)) {
|
||||
if (isset($invitation['id'])) {
|
||||
@ -242,7 +254,9 @@ class BaseRepository
|
||||
|
||||
//make sure we are creating an invite for a contact who belongs to the client only!
|
||||
$contact = ClientContact::find($invitation['client_contact_id']);
|
||||
|
||||
|
||||
\Log::error(print_r($contact,1));
|
||||
|
||||
if ($model->client_id == $contact->client_id);
|
||||
{
|
||||
$new_invitation = $invitation_factory_class::create($model->company_id, $model->user_id);
|
||||
|
@ -74,8 +74,7 @@ class ClientTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
|
||||
$acc = $response->json();
|
||||
|
||||
|
||||
|
||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
||||
|
||||
$token = $account->default_company->tokens->first()->token;
|
||||
|
Loading…
Reference in New Issue
Block a user