mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 06:04:08 -08:00
transaction
This commit is contained in:
parent
a2773aa895
commit
99d409c0a5
|
@ -4,6 +4,7 @@ use App\Models\Asset;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
@ -22,6 +23,8 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
|
||||||
|
|
||||||
|
|
||||||
// Update the eol_explicit column with the value from asset_eol_date if it exists and is different from the calculated value
|
// Update the eol_explicit column with the value from asset_eol_date if it exists and is different from the calculated value
|
||||||
|
$assetsToUpdateEolExplicit = [];
|
||||||
|
DB::transaction(function() {
|
||||||
Asset::whereNotNull('asset_eol_date')->with('model')->chunkById(500, function ($assetsWithEolDates) {
|
Asset::whereNotNull('asset_eol_date')->with('model')->chunkById(500, function ($assetsWithEolDates) {
|
||||||
foreach ($assetsWithEolDates as $asset) {
|
foreach ($assetsWithEolDates as $asset) {
|
||||||
if ($asset->asset_eol_date && $asset->purchase_date) {
|
if ($asset->asset_eol_date && $asset->purchase_date) {
|
||||||
|
@ -32,7 +35,8 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
|
||||||
}
|
}
|
||||||
if ($asset->model->eol) {
|
if ($asset->model->eol) {
|
||||||
if ($months != $asset->model->eol) {
|
if ($months != $asset->model->eol) {
|
||||||
$asset->update(['eol_explicit' => true]);
|
$assetToUpdateEolExplicit = $asset->id;
|
||||||
|
//$asset->update(['eol_explicit' => true]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$asset->update(['eol_explicit' => true]);
|
$asset->update(['eol_explicit' => true]);
|
||||||
|
@ -40,8 +44,11 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
//Asset::whereIn('id', $assetToUpdateEolExplicit)->update(['eol_explicit' => true]);
|
||||||
|
|
||||||
// Update the asset_eol_date column with the calculated value if it doesn't exist
|
// Update the asset_eol_date column with the calculated value if it doesn't exist
|
||||||
|
DB::transaction(function () {
|
||||||
Asset::whereNull('asset_eol_date')->with('model')->chunkById(500, function ($assets) {
|
Asset::whereNull('asset_eol_date')->with('model')->chunkById(500, function ($assets) {
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
if ($asset->model->eol && $asset->purchase_date) {
|
if ($asset->model->eol && $asset->purchase_date) {
|
||||||
|
@ -54,6 +61,7 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue