mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
fix: only clear cloudflare on prod
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Console\Commands;
|
|||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
class CloudflarePurgeCommand extends Command
|
class CloudflarePurgeCommand extends Command
|
||||||
{
|
{
|
||||||
@@ -17,30 +18,32 @@ class CloudflarePurgeCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): void
|
||||||
{
|
{
|
||||||
$client = new Client();
|
if (App::environment('production')) {
|
||||||
$cf_zone_id = config('cloudflare.cf_zone_id');
|
$client = new Client();
|
||||||
$cf_auth_bearer = config('cloudflare.cf_auth_bearer');
|
$cf_zone_id = config('cloudflare.cf_zone_id');
|
||||||
|
$cf_auth_bearer = config('cloudflare.cf_auth_bearer');
|
||||||
|
|
||||||
$response = $client->request(
|
$response = $client->request(
|
||||||
'POST',
|
'POST',
|
||||||
"https://api.cloudflare.com/client/v4/zones/" . $cf_zone_id . "/purge_cache",
|
"https://api.cloudflare.com/client/v4/zones/" . $cf_zone_id . "/purge_cache",
|
||||||
[
|
[
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Authorization' => 'Bearer ' . $cf_auth_bearer,
|
'Authorization' => 'Bearer ' . $cf_auth_bearer,
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
],
|
],
|
||||||
'json' => [
|
'json' => [
|
||||||
'purge_everything' => true,
|
'purge_everything' => true,
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
$body = json_decode($response->getBody(), true);
|
$body = json_decode($response->getBody(), true);
|
||||||
|
|
||||||
if ($body['success'] === true) {
|
if ($body['success'] === true) {
|
||||||
$this->info('Cloudflare cache purged successfully.');
|
$this->info('Cloudflare cache purged successfully.');
|
||||||
} else {
|
} else {
|
||||||
$this->error('Cloudflare cache could not be purged.');
|
$this->error('Cloudflare cache could not be purged.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user