Complete grouped collaborative editorial queues and native review coverage
tests / ci (push) Waiting to run
tests / ci (push) Waiting to run
This commit is contained in:
@@ -5,9 +5,12 @@ namespace App\Http\Controllers;
|
||||
use App\Models\DevelopmentCorridor;
|
||||
use App\Models\EconomicCluster;
|
||||
use App\Models\InvestmentDossier;
|
||||
use App\Models\InvestmentZone;
|
||||
use App\Models\Opportunity;
|
||||
use App\Models\Project;
|
||||
use App\Services\InvestmentZoneOperationalProfile;
|
||||
use App\Services\InvestmentZones;
|
||||
use App\Services\PortalEditorialSubjects;
|
||||
use App\Services\PortalEditorialWorkflow;
|
||||
use App\Services\PortalProfileAccess;
|
||||
use App\Services\TerritoryGeometry;
|
||||
@@ -92,6 +95,12 @@ class InvestmentTerritoryController extends Controller
|
||||
$working = app(PortalEditorialWorkflow::class)->workingStructure($model::findOrFail($id), $dossier);
|
||||
$record->primary_territory_id = $working->getAttribute('primary_territory_id');
|
||||
$record->territory_version = $working->getAttribute('territory_version');
|
||||
} elseif (in_array($kind, ['projects', 'clusters', 'corridors'], true) && app(PortalEditorialSubjects::class)->available()) {
|
||||
$record = app(PortalEditorialSubjects::class)->working($kind, $record);
|
||||
} elseif ($kind === 'zones' && app(InvestmentZoneOperationalProfile::class)->installed()) {
|
||||
$working = app(InvestmentZoneOperationalProfile::class)->management(InvestmentZone::findOrFail($id));
|
||||
$record->primary_territory_id = $working['primary_territory_id'];
|
||||
$record->territory_version = $working['territory_version'];
|
||||
}
|
||||
$path = [];
|
||||
$current = $record->primary_territory_id;
|
||||
@@ -115,17 +124,26 @@ class InvestmentTerritoryController extends Controller
|
||||
}
|
||||
$data = $request->validate(['version' => ['required', 'integer', 'min:0'], 'path' => ['present', 'array', 'max:4'], 'path.*' => ['required', 'uuid', 'distinct']]);
|
||||
$dossier = app(PortalEditorialWorkflow::class)->structureDossier($kind, $id, true);
|
||||
$version = DB::transaction(function () use ($request, $table, $id, $data, $dossier, $kind) {
|
||||
$structural = ! $dossier && in_array($kind, ['projects', 'clusters', 'corridors'], true) && app(PortalEditorialSubjects::class)->writes($kind, $id);
|
||||
$version = DB::transaction(function () use ($request, $table, $id, $data, $dossier, $kind, $structural) {
|
||||
if ($dossier) {
|
||||
$dossier = InvestmentDossier::whereKey($dossier->id)->lockForUpdate()->firstOrFail();
|
||||
}
|
||||
DB::select('SELECT pg_advisory_xact_lock(280926, 150000)');
|
||||
if ($structural) {
|
||||
app(PortalEditorialSubjects::class)->lock($kind, $id, ['primary_territory_id' => $data['path'] === [] ? null : $data['path'][array_key_last($data['path'])]]);
|
||||
}
|
||||
$record = DB::table($table)->where('id', $id)->whereNull('deleted_at')->lockForUpdate()->first();
|
||||
abort_unless($record !== null, 404);
|
||||
$effectiveVersion = (int) $record->territory_version;
|
||||
if ($dossier) {
|
||||
$model = ['projects' => Project::class, 'clusters' => EconomicCluster::class, 'corridors' => DevelopmentCorridor::class][$kind] ?? abort(404);
|
||||
$effectiveVersion = (int) app(PortalEditorialWorkflow::class)->workingStructure($model::findOrFail($id), $dossier)->getAttribute('territory_version');
|
||||
} elseif ($structural) {
|
||||
$effectiveVersion = (int) app(PortalEditorialSubjects::class)->working($kind, $record)->territory_version;
|
||||
} elseif ($kind === 'zones' && app(InvestmentZoneOperationalProfile::class)->installed()) {
|
||||
$working = app(InvestmentZoneOperationalProfile::class)->management(InvestmentZone::findOrFail($id));
|
||||
$effectiveVersion = (int) $working['territory_version'];
|
||||
}
|
||||
abort_unless($effectiveVersion === $data['version'], 409, 'Localização alterada. Recarregue a ficha.');
|
||||
$parent = null;
|
||||
@@ -145,13 +163,20 @@ class InvestmentTerritoryController extends Controller
|
||||
|
||||
return $version;
|
||||
}
|
||||
if ($structural) {
|
||||
$workflow = app(PortalEditorialWorkflow::class);
|
||||
$workflow->saveSubject($request->user(), $kind, $id, $workflow->subjectVersion($kind, $id), ['primary_territory_id' => $parent, 'territory_version' => $version]);
|
||||
|
||||
return $version;
|
||||
}
|
||||
$changes = ['primary_territory_id' => $parent, 'territory_version' => $version, 'updated_at' => now()];
|
||||
if (in_array($table, ['opportunities', 'investment_zones'], true)) {
|
||||
$changes['province'] = $names[0] ?? null;
|
||||
$changes['district'] = $names[1] ?? null;
|
||||
}
|
||||
if ($table === 'investment_zones') {
|
||||
app(InvestmentZones::class)->save($id, [...$changes, 'version_no' => $record->version_no], $request->user()->id);
|
||||
$workingVersion = app(InvestmentZoneOperationalProfile::class)->workingVersion(InvestmentZone::findOrFail($id));
|
||||
app(InvestmentZones::class)->save($id, [...$changes, 'version_no' => $workingVersion], $request->user()->id);
|
||||
} else {
|
||||
DB::table($table)->where('id', $id)->update($changes);
|
||||
}
|
||||
@@ -162,6 +187,8 @@ class InvestmentTerritoryController extends Controller
|
||||
return $version;
|
||||
});
|
||||
|
||||
return response()->json(['version' => $version, 'pending_publication' => $dossier !== null]);
|
||||
$zoneDraft = $kind === 'zones' && (app(InvestmentZoneOperationalProfile::class)->editorialEnabled() || DB::table('investment_zones')->where('id', $id)->value('category') === 'industrial_park');
|
||||
|
||||
return response()->json(['version' => $version, 'pending_publication' => $dossier !== null || $structural || $zoneDraft]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user