tethys/app/Console/Commands/DatasetState.php
Arno Kaimbacher 390f6bbef8 artisan cron job for automatically rejecting
approved datasets
2020-06-10 21:09:20 +02:00

67 lines
1.7 KiB
PHP

<?php
//php artisan make:command DatasetState
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class DatasetState extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'state:dataset';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Check dataset state';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// calculate new statistics
// $datasets = DB::table('documents')
// ->select('account_id', DB::raw('count(*) as total_posts'))
// ->groupBy('account_id')
// ->get();
$datasets = DB::table('documents')
->select('id', 'account_id')
->where('server_state', 'approved')
->whereRaw('server_date_modified < DATEADD(day,-14,GETDATE())')
->get();
// update statistics table
foreach ($datasets as $dataset) {
// DB::table('users_statistics')
// ->where('user_id', $dataset->user_id)
// ->update(['total_datasets' => $dataset->total_posts]);
DB::table('documents')
->where('id', $dataset->id)
->update([
'reject_reviewer_note' => 'Dataset was automatically rejected because of the time limit',
'server_state' => 'rejected_reviewer'
]);
}
}
}