Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Generating reports ...');
     $generators = Generator::where('is_active', 1)->get();
     foreach ($generators as $generator) {
         $activation_hours = explode(',', $generator['activation_hours']);
         $activation_days = explode(',', $generator['activation_days']);
         $this->info('Testing ' . $generator['name'] . ' ...');
         $is_day = false;
         $is_hour = false;
         $actual_time = time() + 3600;
         // UTC+1 = 3600 secondes
         $actual_day = date("w", $actual_time);
         foreach ($activation_days as $day) {
             if ($day == $actual_day) {
                 $is_day = true;
             }
         }
         if ($is_day) {
             $this->info('It is today !');
         }
         $actual_hour = date("H", $actual_time);
         foreach ($activation_hours as $hour) {
             if ($hour == $actual_hour) {
                 $is_hour = true;
             }
         }
         if ($is_hour) {
             $this->info('It is hour !');
         }
         if ($is_day == true && $is_hour == true) {
             $this->info('Publishing to slack ...');
             $data = Generator::createReport($generator);
             $settings = ['username' => 'Slackreport', 'link_names' => true];
             $client = new \Maknz\Slack\Client($data['generator']['slack_service']['var2'], $settings);
             $client->send($data['message']);
         }
     }
 }
Пример #2
0
 public function test($id)
 {
     $generator = Generator::where('user_id', Auth::user()->id)->where('id', (int) $id)->first();
     if ($generator['is_active'] == 1) {
         $data = Generator::createReport($generator);
         $settings = ['username' => 'Slackreport', 'link_names' => true];
         $client = new \Maknz\Slack\Client($data['generator']['slack_service']['var2'], $settings);
         $client->send($data['message']);
         return redirect()->back()->with('message', 'A test report was sent to your slack channel');
     } else {
         return redirect()->back()->with('message', 'Error, you have to activate this generator to be enable to test it.');
     }
 }