Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

[RFC] Add command in bin for clearing cache even if environment is broken #1105

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions bin/clear-cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env php
<?php

$varName = 'var';
$rootPath = dirname(__DIR__);
$composerPath = $rootPath.'/composer.json';

if (file_exists($composerPath) && is_readable($composerPath)) {
$composer = json_decode(file_get_contents($composerPath), JSON_OBJECT_AS_ARRAY);
if ($composer && isset($composer['extra']) && isset($composer['extra']['symfony-var-dir'])) {
$varName = $composer['extra']['symfony-var-dir'];
}
}

$cacheDir = $rootPath.'/'.$varName.'/cache';
if (!is_dir($cacheDir) || !is_writable($cacheDir)) {
die (sprintf("Cache directory '%s' does not seem to exist or is not writable to the current user.\n", $cacheDir));
}

if ($argc > 1) {
$cacheDir .= '/' . $argv[1];
if (!is_dir($cacheDir) || !is_writable($cacheDir)) {
die (sprintf("Environment cache directory '%s' does not seem to exist or is not writable to the current user.\n", $cacheDir));
}
}

if ('/' === DIRECTORY_SEPARATOR) {
system('rm -rf '.escapeshellarg($cacheDir));
} else {
system('rmdir /S /Q '.escapeshellarg($cacheDir));
}

die (sprintf("Cache directory '%s' successfully removed.\n", $cacheDir));