mercredi 12 septembre 2018

Why does Cron scheduler not working in laravel ?

Note: i'm using laravel 5.0

I have executed this commond "* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1" like mentioned in documentation of laravel but cron still not working this my kernel file:

<?php namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel {

/**
 * The Artisan commands provided by your application.
 *
 * @var array
 */
protected $commands = [
    'App\Console\Commands\InstagramAutopost',
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('instagramautopost')
             ->everyFiveMinutes()
             ->withoutOverlapping();
}
}

and this is my InstagramAutopost.php file in Commands:

use App\Export;
use App\Insta;
use Auth;
use Response;
use App\Vehicle;
use View;
use Instagram;
use App\Libraries\UserPreferences;
use App\Libraries\Info;

class InstagramController extends Controller {

public function postInstagram(){

    $vehicles_id = Vehicle::where(['user_id' => Auth::id()])->get();
    $numVehicles = count($vehicles_id);

    for ($i=0; $i < $numVehicles ; $i++) {
        $vExport = Export::where(['v_id' => $vehicles_id[$i]['id']])->first();

        if (!$vExport || ($vehicles_id[$i]['last_modified'] > $vExport['instagram_date'])) {
            $settings = \App\Insta::where(['user_id' => Auth::id()])->first();
            if($settings){
                $vInfo = Vehicle::where(['id' => $vehicles_id[$i]['id']])->first();

                $img = $this->get_main_photo($vInfo['photos'], 400, 300, V12_IMAGES_URL . '/' . Auth::user()->photos_directory . '/' . $vInfo['id'] . "/");
                if($img && getimagesize($img) ){

                    $price = ($vInfo['internet_specials']=='yes' and $vInfo['featured_price']!=0)?$vInfo['featured_price']:$vInfo['price'];
                    $msg = $vInfo['year'].' '.$vInfo['make_name'].' '.$vInfo['model'].' $'.$price;

                    /////// CONFIG ///////
                    $username = $settings->username;
                    $password = $settings->password;

                    $debug = false;
                    $photo = $img ;
                    $info  = new Info(Auth::id(), $vehicles_id[$i]['id']);
                    $caption = $msg.' '.$info->getDomain() . "/inventory/view/" . $vehicles_id[$i]['id'];    

                    $instagrame = new Instagram($username, $password, $debug);

                    //Login
                    try {
                        $instagrame->login();

                    } catch (InstagramException $e) {
                        exit();
                    }

                    //Upload photo
                    try {

                        $instagrame->uploadPhoto($img, $caption);

                        //update exports
                        $exp = Export::where(['v_id' => $vehicles_id[$i]['id']])->first();
                        if(!$exp){
                            $exp = new Export;
                            $exp->v_id = $vehicles_id[$i]['id'];
                        }
                        $exp->instagram = 'yes';
                        $exp->instagram_date = date('Y-m-d H:i:s');
                        $exp->save();


                    } catch (Exception $e) {

                    }   
                }

            }
        }
    }

   }

  /**
  * Get the main photo of a vehicle
  *
  * @return Response
  */

  public function get_main_photo($photos, $width, $height, $path = '') {
    if ($photos != '') {
        $ar_photos = unserialize($photos);
        for ($i = 0; $i < count($ar_photos); $i++) {
            if ($ar_photos[$i]['main'] == 'yes') {
                return (empty($width) ? $path . $ar_photos[$i]['photo'] : $path . str_ireplace('.jpg', '_' . $width . $height . '.jpg', $ar_photos[$i]['photo']));
            }
        }
    }
    return '';
   } 

  }

I want if it's there something wrong.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Mr7SHf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire