|
23 | 23 | use craft\events\RegisterUrlRulesEvent; |
24 | 24 | use craft\events\RegisterCacheOptionsEvent; |
25 | 25 | use craft\helpers\Assets as AssetsHelper; |
| 26 | +use craft\helpers\FileHelper; |
26 | 27 | use craft\helpers\UrlHelper; |
27 | 28 | use craft\services\Assets; |
28 | 29 | use craft\services\Plugins; |
29 | 30 | use craft\utilities\ClearCaches; |
30 | 31 | use craft\web\twig\variables\CraftVariable; |
31 | 32 | use craft\web\UrlManager; |
32 | 33 |
|
| 34 | +use yii\base\ErrorException; |
33 | 35 | use yii\base\Event; |
| 36 | +use yii\base\InvalidArgumentException; |
34 | 37 |
|
35 | 38 | /** |
36 | 39 | * Class Transcode |
@@ -80,6 +83,31 @@ public function init() |
80 | 83 | ); |
81 | 84 | } |
82 | 85 |
|
| 86 | + /** |
| 87 | + * Clear all the caches! |
| 88 | + */ |
| 89 | + public function clearAllCaches() |
| 90 | + { |
| 91 | + $transcoderPaths = Transcoder::$plugin->getSettings()->transcoderPaths; |
| 92 | + foreach ($transcoderPaths as $key => $value) { |
| 93 | + $dir = Craft::getAlias($value); |
| 94 | + try { |
| 95 | + FileHelper::clearDirectory($dir); |
| 96 | + Craft::info( |
| 97 | + Craft::t( |
| 98 | + 'transcoder', |
| 99 | + '{name} cache directory cleared', |
| 100 | + ['name' => $key] |
| 101 | + ), |
| 102 | + __METHOD__ |
| 103 | + ); |
| 104 | + } catch (ErrorException $e) { |
| 105 | + // the directory doesn't exist |
| 106 | + Craft::error($e->getMessage(), __METHOD__); |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
83 | 111 | // Protected Methods |
84 | 112 | // ========================================================================= |
85 | 113 |
|
@@ -137,7 +165,7 @@ function (RegisterCacheOptionsEvent $event) { |
137 | 165 | $event->options[] = [ |
138 | 166 | 'key' => 'transcoder', |
139 | 167 | 'label' => Craft::t('transcoder', 'Transcoder caches'), |
140 | | - 'action' => Transcoder::$plugin->getSettings()->transcoderPaths['default'], |
| 168 | + 'action' => [$this, 'clearAllCaches'] |
141 | 169 | ]; |
142 | 170 | } |
143 | 171 | ); |
|
0 commit comments