2020-03-07 23:15:11 +01:00
|
|
|
<?php
|
2020-04-30 13:45:47 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-04-30 13:45:47 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-04-30 13:45:47 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-04-30 13:45:47 +02:00
|
|
|
*/
|
2020-03-07 23:15:11 +01:00
|
|
|
|
|
|
|
namespace App\Jobs\Util;
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Factory\ClientContactFactory;
|
|
|
|
use App\Factory\VendorContactFactory;
|
2023-10-30 04:00:23 +01:00
|
|
|
use App\Models\Account;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Models\Client;
|
2023-10-30 04:00:23 +01:00
|
|
|
use App\Models\ClientContact;
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\Models\Vendor;
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
use Carbon\Carbon;
|
2020-03-07 23:15:11 +01:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2023-11-26 08:41:42 +01:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Support\Str;
|
2020-03-07 23:15:11 +01:00
|
|
|
|
|
|
|
class VersionCheck implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2022-07-25 00:00:52 +02:00
|
|
|
$version_file = trim(@file_get_contents(config('ninja.version_url')));
|
2020-03-07 23:15:11 +01:00
|
|
|
|
2022-07-10 02:56:37 +02:00
|
|
|
if (Ninja::isSelfHost() && $version_file) {
|
2023-08-07 07:33:40 +02:00
|
|
|
Account::query()->whereNotNull('id')->update(['latest_version' => $version_file]);
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2021-04-20 14:45:35 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (Ninja::isSelfHost()) {
|
2022-11-26 01:09:48 +01:00
|
|
|
nlog("latest version = {$version_file}");
|
|
|
|
|
2023-08-07 07:33:40 +02:00
|
|
|
/** @var \App\Models\Account $account **/
|
2021-04-20 14:45:35 +02:00
|
|
|
$account = Account::first();
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $account) {
|
2021-05-01 02:48:36 +02:00
|
|
|
return;
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-05-01 02:48:36 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($account->plan == 'white_label' && $account->plan_expires && Carbon::parse($account->plan_expires)->lt(now())) {
|
2021-04-20 14:45:35 +02:00
|
|
|
$account->plan = null;
|
|
|
|
$account->plan_expires = null;
|
2023-10-30 04:00:23 +01:00
|
|
|
$account->saveQuietly();
|
2021-04-20 14:45:35 +02:00
|
|
|
}
|
2023-10-30 04:00:23 +01:00
|
|
|
|
|
|
|
Client::query()->whereNull('country_id')->cursor()->each(function ($client) {
|
|
|
|
$client->country_id = $client->company->settings->country_id;
|
|
|
|
$client->saveQuietly();
|
|
|
|
});
|
|
|
|
|
|
|
|
Vendor::query()->whereNull('currency_id')->orWhere('currency_id', '')->cursor()->each(function ($vendor) {
|
|
|
|
$vendor->currency_id = $vendor->company->settings->currency_id;
|
|
|
|
$vendor->saveQuietly();
|
|
|
|
});
|
|
|
|
|
|
|
|
ClientContact::whereNull('email')
|
|
|
|
->where('send_email', true)
|
|
|
|
->cursor()
|
|
|
|
->each(function ($c) {
|
|
|
|
|
|
|
|
$c->send_email = false;
|
|
|
|
$c->saveQuietly();
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
});
|
2023-10-30 04:00:23 +01:00
|
|
|
|
|
|
|
ClientContact::query()
|
|
|
|
->whereNull('contact_key')
|
|
|
|
->update([
|
|
|
|
'contact_key' => Str::random(config('ninja.key_length')),
|
|
|
|
]);
|
|
|
|
|
|
|
|
Client::doesntHave('contacts')
|
|
|
|
->cursor()
|
2023-11-26 08:41:42 +01:00
|
|
|
->each(function ($client) {
|
2023-10-30 04:00:23 +01:00
|
|
|
|
|
|
|
$new_contact = ClientContactFactory::create($client->company_id, $client->user_id);
|
|
|
|
$new_contact->client_id = $client->id;
|
|
|
|
$new_contact->contact_key = Str::random(40);
|
|
|
|
$new_contact->is_primary = true;
|
|
|
|
$new_contact->save();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Vendor::doesntHave('contacts')
|
|
|
|
->cursor()
|
2023-11-26 08:41:42 +01:00
|
|
|
->each(function ($vendor) {
|
2023-10-30 04:00:23 +01:00
|
|
|
|
|
|
|
$new_contact = VendorContactFactory::create($vendor->company_id, $vendor->user_id);
|
|
|
|
$new_contact->vendor_id = $vendor->id;
|
|
|
|
$new_contact->contact_key = Str::random(40);
|
|
|
|
$new_contact->is_primary = true;
|
|
|
|
$new_contact->save();
|
2023-11-26 08:41:42 +01:00
|
|
|
});
|
2023-10-30 04:00:23 +01:00
|
|
|
|
|
|
|
|
2021-04-20 14:45:35 +02:00
|
|
|
}
|
2020-03-07 23:15:11 +01:00
|
|
|
}
|
|
|
|
}
|