REBELinBLUE\Deployer\Console\Commands\ClearOldKeys::handle PHP Method

handle() public method

Execute the console command.
public handle ( ) : mixed
return mixed
    public function handle()
    {
        // Clear out old SSH key files and archives
        $keys = glob(storage_path('app/tmp/') . '*ssh*');
        $archives = glob(storage_path('app/') . '*.tar.gz');
        $files = array_merge($keys, $archives);
        $folders = glob(storage_path('app/tmp/') . 'clone_*');
        // cloned copies of code
        $this->info('Found ' . count($files) . ' files and ' . count($folders) . ' folders to purge');
        // Now loop through the temp files and delete them from storage
        foreach (array_merge($files, $folders) as $path) {
            $file = basename($path);
            // Don't delete recently created files as a precaution, 12 hours is more than enough
            if (filemtime($path) > strtotime('-12 hours')) {
                $this->info('Skipping ' . $file);
                continue;
            }
            $success = true;
            if (is_dir($path)) {
                if (!rmdir($path)) {
                    $this->error('Failed to delete folder ' . $file);
                    $success = false;
                }
            } elseif (!unlink($path)) {
                $this->error('Failed to delete file ' . $file);
                $success = false;
            }
            if ($success) {
                $this->info('Deleted ' . $file);
            }
        }
    }
ClearOldKeys