Skip to content

Commit

Permalink
Adds CacheTidy addon and README
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Peercy committed Feb 19, 2019
1 parent d5e8f72 commit 518e9a1
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added CacheTidy/.DS_Store
Binary file not shown.
75 changes: 75 additions & 0 deletions CacheTidy/CacheTidyController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Statamic\Addons\CacheTidy;

use Illuminate\Support\Facades\Artisan;
use Statamic\Extend\Controller;

class CacheTidyController extends Controller
{
/**
* Maps to your route definition in routes.yaml
*
* @return mixed
*/
public function index()
{
return $this->view('index');
}

public function cache()
{
$command = 'clear:cache';

try {
Artisan::call($command);
$call = trim(Artisan::output());
return back()->with('success', $call);
} catch (\Exception $e) {
Log::error('Problem running command: ' . $command);
return back()->withErrors('error', ' There was a problem' . $e);
}
}

public function glide()
{
$command = 'clear:glide';

try {
Artisan::call($command);
$call = trim(Artisan::output());
return back()->with('success', $call);
} catch (\Exception $e) {
Log::error('Problem running command: ' . $command);
return back()->withErrors('error', ' There was a problem' . $e);
}
}

public function stache()
{
$command = 'clear:stache';

try {
Artisan::call($command);
$call = trim(Artisan::output());
return back()->with('success', $call);
} catch (\Exception $e) {
Log::error('Problem running command: ' . $command);
return back()->withErrors('error', ' There was a problem' . $e);
}
}

public function staticCache()
{
$command = 'clear:static';

try {
Artisan::call($command);
$call = trim(Artisan::output());
return back()->with('success', $call);
} catch (\Exception $e) {
Log::error('Problem running command: ' . $command);
return back()->withErrors('error', ' There was a problem' . $e);
}
}
}
25 changes: 25 additions & 0 deletions CacheTidy/CacheTidyListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Statamic\Addons\CacheTidy;

use Statamic\API\Nav;
use Statamic\Extend\Listener;

class CacheTidyListener extends Listener
{
/**
* The events to be listened for, and the methods to call.
*
* @var array
*/
public $events = [
'cp.nav.created' => 'addNavItems'
];

public function addNavItems($nav)
{
$tidy = Nav::item('Cache Tidy')->route('addons.cache_tidy')->icon('flat-brush');

$nav->addTo('tools', $tidy);
}
}
5 changes: 5 additions & 0 deletions CacheTidy/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "pattern/cache-tidy",
"require": {
}
}
6 changes: 6 additions & 0 deletions CacheTidy/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: 'Cache Tidy'
version: '1.0'
description: 'Clear caches from within the CP'
url: 'https://github.com/pttrnco/cache-tidy'
developer: Pattern
developer_url: 'https://pttrn.co'
51 changes: 51 additions & 0 deletions CacheTidy/resources/views/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@extends('layout')

@section('content')
<div class="flexy mb-3">
<h1>Cache Tidy</h1>
</div>
<div class="card flush dossier-for-mobile">
<div class="dossier-table-wrapper">
<table class="dossier">
<tbody>
<tr>
<td class="cell-name first-cell" style="width:200px;">
<span class="column-label">Name</span> <a href="{{ route('addons.clear_cache') }}">Clear Cache</a>
</td>
<td class="cell-description">
<span class="column-label">Description</span> Clear the application cache.
</td>
<td class="column-actions"></td>
</tr>
<tr>
<td class="cell-name first-cell">
<span class="column-label">Name</span> <a href="{{ route('addons.clear_glide') }}">Clear Glide</a>
</td>
<td class="cell-description">
<span class="column-label">Description</span> Clear the Glide image cache.
</td>
<td class="column-actions"></td>
</tr>
<tr>
<td class="cell-name first-cell">
<span class="column-label">Name</span> <a href="{{ route('addons.clear_stache') }}">Clear Stache</a>
</td>
<td class="cell-description">
<span class="column-label">Description</span> Clear the "Stache" cache.
</td>
<td class="column-actions"></td>
</tr>
<tr>
<td class="cell-name first-cell">
<span class="column-label">Name</span> <a href="{{ route('addons.clear_static') }}">Clear Static</a>
</td>
<td class="cell-description">
<span class="column-label">Description</span> Clear the Static Page Cache.
</td>
<td class="column-actions"></td>
</tr>
</tbody>
</table>
</div>
</div>
@endsection
16 changes: 16 additions & 0 deletions CacheTidy/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
routes:
/:
as: addons.cache_tidy
uses: index
cache:
as: addons.clear_cache
uses: cache
glide:
as: addons.clear_glide
uses: glide
stache:
as: addons.clear_stache
uses: stache
static:
as: addons.clear_static
uses: staticCache
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Cache Tidy

Gives Statamic control panel users the ability to clear Statamic's caches.

## Installation

Unzip and place the `CacheTidy` directory in your `site/addons` directory. Then run `php please update:addons`.

After installation, you can find Cache Tidy in the 'Tools' section of the CP nav.

0 comments on commit 518e9a1

Please sign in to comment.