diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index da7261308716..feaabd5830a6 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -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; + } } diff --git a/app/Console/Commands/S3Cleanup.php b/app/Console/Commands/S3Cleanup.php index f7409764b3a5..6aa4d2d3b1d4 100644 --- a/app/Console/Commands/S3Cleanup.php +++ b/app/Console/Commands/S3Cleanup.php @@ -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); + } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 10cb1bb3f95c..30833128eb7f 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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(); }