Skip to content

Commit

Permalink
Change Task Sheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
Insa committed Oct 18, 2017
1 parent 11c14d7 commit a933b15
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
30 changes: 16 additions & 14 deletions app/Console/Kernel.php
Expand Up @@ -26,22 +26,24 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$data = DB::table('data')->where('created_at', '<', '(NOW() - INTERVAL 1 DAY)')->value('guid');

if ($data) {
foreach ($data as $e) {
Storage::delete($e);
Storage::delete('public/'.$e.'.mp4');
DB::table('data')->where('guid', '=', $e)->delete();
}
}
})->daily();
$schedule->call(function () {
$date = new DateTime;
$date->modify('-1 day');
$formatted_date = $date->format('Y-m-d H:i:s');
$data = DB::table('data')->where('created_at', '<', $formatted_date)->get(); Storage::delete($e);
if ($data) {
foreach ($data as $e) {
if(file_exists(storage_path().$e->guid))
Storage::delete($e->guid);
if(file_exists(storage_path().'public/'.$e->guid.'.mp4'))
Storage::delete('public/'.$e->guid.'.mp4');
DB::table('data')->where('guid', '=', $e)->delete();
}
}
})->daily();
}

/**
* Register the Closure based commands for the application.
*
* Register the Closure based commands for the application
* @return void
*/
protected function commands()
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/StaticsController.php
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use DateTime;

class StaticsController extends Controller
{
Expand Down

0 comments on commit a933b15

Please sign in to comment.