Checks for missing props

This commit is contained in:
David Bomba 2023-09-18 11:20:01 +10:00
parent f5dfb69776
commit 4e77b1072c
2 changed files with 29 additions and 6 deletions

View File

@ -11,13 +11,14 @@
namespace App\Http\Controllers;
use App\Exceptions\FilePermissionsFailure;
use App\Utils\Ninja;
use App\Models\Company;
use App\Utils\Traits\AppSetup;
use App\Utils\Traits\ClientGroupSettingsSaver;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
use App\Exceptions\FilePermissionsFailure;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Utils\Traits\ClientGroupSettingsSaver;
class SelfUpdateController extends BaseController
{
@ -109,11 +110,33 @@ class SelfUpdateController extends BaseController
$this->buildCache(true);
$this->runModelChecks();
nlog('Called Artisan commands');
return response()->json(['message' => 'Update completed'], 200);
}
private function runModelChecks()
{
Company::query()
->cursor()
->each(function ($company){
$settings = $company->settings;
if(property_exists($settings->pdf_variables, 'purchase_order_details'))
return;
$pdf_variables = $settings->pdf_variables;
$pdf_variables->purchase_order_details = [];
$settings->pdf_variables = $pdf_variables;
$company->settings = $settings;
$company->save();
});
}
private function clearCacheDir()
{
$directoryIterator = new \RecursiveDirectoryIterator(base_path('bootstrap/cache'), \RecursiveDirectoryIterator::SKIP_DOTS);

View File

@ -195,15 +195,15 @@ class PdfSlot extends Component
}
elseif($this->entity_type == 'quote'){
foreach($this->settings->pdf_variables->quote_details as $variable)
foreach($this->settings->pdf_variables->quote_details ?? [] as $variable)
$entity_details .= "<div class='flex px-5 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-5 w-36 block entity-field'>{$variable}</p></div>";
}
elseif($this->entity_type == 'credit') {
foreach($this->settings->pdf_variables->credit_details as $variable)
foreach($this->settings->pdf_variables->credit_details ?? [] as $variable)
$entity_details .= "<div class='flex px-5 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-5 w-36 block entity-field'>{$variable}</p></div>";
}
elseif($this->entity_type == 'purchase_order'){
foreach($this->settings->pdf_variables->purchase_order_details as $variable)
foreach($this->settings->pdf_variables->purchase_order_details ?? [] as $variable)
$entity_details .= "<div class='flex px-5 block'><p class= w-36 block'>{$variable}_label</p><p class='pl-5 w-36 block entity-field'>{$variable}</p></div>";
}