Skip to content

Commit 570e060

Browse files
committed
Fix clear caches
Signed-off-by: Andrew Welch <andrew@nystudio107.com>
1 parent 0ab6e87 commit 570e060

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/Transcoder.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
use craft\events\RegisterUrlRulesEvent;
2424
use craft\events\RegisterCacheOptionsEvent;
2525
use craft\helpers\Assets as AssetsHelper;
26+
use craft\helpers\FileHelper;
2627
use craft\helpers\UrlHelper;
2728
use craft\services\Assets;
2829
use craft\services\Plugins;
2930
use craft\utilities\ClearCaches;
3031
use craft\web\twig\variables\CraftVariable;
3132
use craft\web\UrlManager;
3233

34+
use yii\base\ErrorException;
3335
use yii\base\Event;
36+
use yii\base\InvalidArgumentException;
3437

3538
/**
3639
* Class Transcode
@@ -80,6 +83,31 @@ public function init()
8083
);
8184
}
8285

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+
83111
// Protected Methods
84112
// =========================================================================
85113

@@ -137,7 +165,7 @@ function (RegisterCacheOptionsEvent $event) {
137165
$event->options[] = [
138166
'key' => 'transcoder',
139167
'label' => Craft::t('transcoder', 'Transcoder caches'),
140-
'action' => Transcoder::$plugin->getSettings()->transcoderPaths['default'],
168+
'action' => [$this, 'clearAllCaches']
141169
];
142170
}
143171
);

0 commit comments

Comments
 (0)