mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 23:54:12 -08:00
Merge branch 'develop'
This commit is contained in:
commit
ce97faa8d4
|
@ -16,23 +16,14 @@ class NormalizeAssetLastAuditDate extends Migration
|
|||
public function up()
|
||||
{
|
||||
|
||||
if (!Schema::hasColumn('assets', 'last_audit_date')) {
|
||||
Schema::table('assets', function (Blueprint $table) {
|
||||
$table->datetime('last_audit_date')->after('assigned_type')->nullable()->default(null);
|
||||
});
|
||||
|
||||
// Grab the latest info from the Actionlog table where the action is 'audit'
|
||||
$audits = Actionlog::selectRaw('MAX(created_at) AS created_at, item_id')->where('action_type', 'audit')->where('item_type', Asset::class)->groupBy('item_id')->orderBy('created_at', 'desc')->get();
|
||||
|
||||
if ($audits) {
|
||||
foreach ($audits as $audit) {
|
||||
$assets = Asset::where('id', $audit->item_id)->first();
|
||||
$assets->last_audit_date = $audit->created_at;
|
||||
$assets->unsetEventDispatcher();
|
||||
$assets->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,8 +33,10 @@ class NormalizeAssetLastAuditDate extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
if (Schema::hasColumn('assets', 'last_audit_date')) {
|
||||
Schema::table('assets', function (Blueprint $table) {
|
||||
$table->dropColumn('last_audit_date');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class ReNormalizeLastAudit extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
if (Schema::hasColumn('assets', 'last_audit_date')) {
|
||||
// Grab the latest info from the Actionlog table where the action is 'audit'
|
||||
$audits = Actionlog::selectRaw('MAX(created_at) AS created_at, item_id')
|
||||
->where('action_type', 'audit')
|
||||
->where('item_type', Asset::class)
|
||||
->groupBy('item_id')
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
if ($audits) {
|
||||
foreach ($audits as $audit) {
|
||||
$assets = Asset::where('id', $audit->item_id)->first();
|
||||
$assets->last_audit_date = $audit->created_at;
|
||||
$assets->unsetEventDispatcher();
|
||||
$assets->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue