vendredi 26 octobre 2018

Laravel class not found on production but works on local env

I've got this weird problem.

I've installed a package via composer (https://packagist.org/packages/evert/sitemap-php) in my laravel 5.7 application and called the composer dump-autoload command

The package is found in my vendor directory (on local and prod env) but the Job I run only works in local.

here is the stack trace of the error (catch via the failed_jobs table)

Symfony\Component\Debug\Exception\FatalThrowableError: Class 'SitemapPHP\Sitemap' not found in /home/forge/u-corsu.com/app/Jobs/CreateSitemap.php:60 Stack trace:

Here my code:

<?php

namespace App\Jobs;

use Storage;
use SitemapPHP\Sitemap;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class CreateSitemap implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected $path;
protected $ping;
protected $sitemapIndex;

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($ping)
{
    $this->sitemapIndex = env('APP_URL').'/storage/sitemap-index.xml';
    $this->path = storage_path().'/app/public/';
    $this->ping = $ping;
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    $this->cleanFiles();

    $this->generateSitemap();
}

private function cleanFiles()
{
    $files = Storage::files('public');
    foreach ($files as $file) {
        if (str_contains($file, 'sitemap')) {
            Storage::delete($file);
        }
    }
}

private function generateSitemap()
{
    $sitemap = new Sitemap(env('APP_URL'));

/*MY CODE*/

    if ($this->ping) {
        $this->pingGoogle();
    }
}

public function pingGoogle()
{
    $client = new \GuzzleHttp\Client();
    $request = $client->request('GET', 'https://www.google.com/ping?sitemap='.$this->sitemapIndex);
}
}

How can I solve this problem ?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire