예제 #1
0
파일: Task.php 프로젝트: verchielxy/eform
 public static function bannerImgClear($clearNum = 5, $clearTimeDiff = 5)
 {
     $res = 0;
     Img::orderBy('created_at', 'ASC')->where('img_block', '=', 'banner')->where('img_active', '=', '0')->where('created_at', '<=', date("Y-m-d H:i:s", strtotime("-{$clearTimeDiff} minute", strtotime(date("Y-m-d H:i:s")))))->take($clearNum)->delete();
     $imgs = Img::onlyTrashed()->take($clearNum)->get();
     foreach ($imgs as $img) {
         if (file_exists(public_path() . $img->img_hd)) {
             unlink(public_path() . $img->img_hd);
         }
         if (file_exists(public_path() . $img->img_big)) {
             unlink(public_path() . $img->img_big);
         }
         if (file_exists(public_path() . $img->img_small)) {
             unlink(public_path() . $img->img_small);
         }
         if (file_exists(public_path() . $img->img_tiny)) {
             unlink(public_path() . $img->img_tiny);
         }
         if (file_exists(public_path() . $img->img_square)) {
             unlink(public_path() . $img->img_square);
         }
         if (!file_exists(public_path() . $img->img_hd) && !file_exists(public_path() . $img->img_big) && !file_exists(public_path() . $img->img_small) && !file_exists(public_path() . $img->img_tiny)) {
             $img->forceDelete();
             $res = 1;
         }
     }
     return $res;
 }
예제 #2
0
 public function anyGet(Request $request, $img_block = 'all')
 {
     $res = ['response' => 'YES', 'status' => 1, 'imgs' => []];
     $perpage = 20;
     $imgs = Img::orderBy('created_at', 'DESC');
     if ($img_block != 'all') {
         $imgs = $imgs->where('img_block', '=', $img_block);
     }
     $imgs = $imgs->paginate($perpage);
     if (count($imgs) > 0) {
         $res['imgs'] = $imgs->toJson();
     }
     return response()->json($res);
 }
예제 #3
0
파일: Kernel.php 프로젝트: verchielxy/eform
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     // $schedule->command('inspire')
     //          ->hourly();
     // $schedule->call(function (){
     //     Task::bannerImgClear();
     //     Task::activityImgClear();
     // })->everyMinute()->before(function () {
     // });
     $schedule->call(function () {
         $clearTimeDiff = 1;
         $clearNum = 5;
         $imgs = Img::orderBy('created_at', 'ASC')->where('img_block', 'open-form')->where('created_at', '<=', date("Y-m-d H:i:s", strtotime("-{$clearTimeDiff} minute", strtotime(date("Y-m-d H:i:s")))))->take($clearNum)->get();
         foreach ($imgs as $img) {
             if (!$img->FieldChildren) {
                 if (file_exists(public_path() . $img->img_uri)) {
                     unlink(public_path() . $img->img_uri);
                 }
                 if (file_exists(public_path() . $img->img_hd)) {
                     unlink(public_path() . $img->img_hd);
                 }
                 if (file_exists(public_path() . $img->img_big)) {
                     unlink(public_path() . $img->img_big);
                 }
                 if (file_exists(public_path() . $img->img_small)) {
                     unlink(public_path() . $img->img_small);
                 }
                 if (file_exists(public_path() . $img->img_tiny)) {
                     unlink(public_path() . $img->img_tiny);
                 }
                 if (file_exists(public_path() . $img->img_square)) {
                     unlink(public_path() . $img->img_square);
                 }
                 if (!file_exists(public_path() . $img->img_hd) && !file_exists(public_path() . $img->img_big) && !file_exists(public_path() . $img->img_small) && !file_exists(public_path() . $img->img_tiny)) {
                     $img->forceDelete();
                 }
             }
         }
     });
 }