1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #6607 from turbo124/v5-develop

Fixes for CheckData
This commit is contained in:
David Bomba 2021-09-08 14:27:53 +10:00 committed by GitHub
commit c04617aad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View File

@ -24,6 +24,8 @@ use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Models\Payment;
use App\Models\Paymentable;
use App\Models\QuoteInvitation;
use App\Models\RecurringInvoiceInvitation;
use App\Utils\Ninja;
use Exception;
use Illuminate\Console\Command;
@ -198,7 +200,7 @@ class CheckData extends Command
->where('id', '=', $contact->id)
->whereNull('contact_key')
->update([
'contact_key' => str_random(config('ninja.key_length')),
'contact_key' => Str::random(config('ninja.key_length')),
]);
}
}
@ -318,6 +320,10 @@ class CheckData extends Command
private function checkEntityInvitations()
{
RecurringInvoiceInvitation::where('deleted_at',"0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
InvoiceInvitation::where('deleted_at',"0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
QuoteInvitation::where('deleted_at',"0000-00-00 00:00:00.000000")->withTrashed()->update(['deleted_at' => null]);
$entities = ['invoice', 'quote', 'credit', 'recurring_invoice'];
@ -328,8 +334,8 @@ class CheckData extends Command
$entities = DB::table($table)
->leftJoin($invitation_table, function ($join) use($invitation_table, $table, $entity){
$join->on("{$invitation_table}.{$entity}_id", '=', "{$table}.id")
->whereNull("{$invitation_table}.deleted_at");
$join->on("{$invitation_table}.{$entity}_id", '=', "{$table}.id");
// ->whereNull("{$invitation_table}.deleted_at");
})
->groupBy("{$table}.id", "{$table}.user_id", "{$table}.company_id", "{$table}.client_id")
->havingRaw("count({$invitation_table}.id) = 0")
@ -359,7 +365,13 @@ class CheckData extends Command
$invitation->{$entity_key} = $entity->id;
$invitation->client_contact_id = ClientContact::whereClientId($entity->client_id)->first()->id;
$invitation->key = Str::random(config('ninja.key_length'));
$invitation->save();
try{
$invitation->save();
}
catch(\Exception $e){
$invitation = null;
}
}

View File

@ -20,7 +20,7 @@ class S3Cleanup extends Command
*
* @var string
*/
protected $description = 'Remove orphan folders';
protected $description = 'Remove orphan folders/files';
/**
* Create a new command instance.
@ -54,7 +54,11 @@ class S3Cleanup extends Command
if(!in_array($dir, $merged))
{
$this->logMessage("Deleting $dir");
Storage::disk(config('filesystems.default'))->deleteDirectory($dir);
/* Ensure we are not deleting the root folder */
if(strlen($dir) > 1)
Storage::disk(config('filesystems.default'))->deleteDirectory($dir);
}
}

View File

@ -71,7 +71,8 @@ class Kernel extends ConsoleKernel
$schedule->job(new AdjustEmailQuota)->dailyAt('23:00')->withoutOverlapping();
$schedule->job(new SendFailedEmails)->daily()->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-02')->daily()->withoutOverlapping();
$schedule->command('ninja:check-data --database=db-ninja-02')->dailyAt('00:15')->withoutOverlapping();
$schedule->command('ninja:s3-cleanup')->dailyAt('23:15')->withoutOverlapping();
}