4343 * @since 1.0.0
4444 *
4545 * @property Transcode $transcode
46+ * @property Settings $settings
47+ * @method Settings getSettings()
4648 */
4749class Transcoder extends Plugin
4850{
@@ -89,28 +91,24 @@ public function init()
8991 public function clearAllCaches ()
9092 {
9193 $ transcoderPaths = Transcoder::$ plugin ->getSettings ()->transcoderPaths ;
92- $ clearCaches = Transcoder::$ plugin ->getSettings ()->clearCaches ;
93-
94- if ($ clearCaches ) {
95- foreach ($ transcoderPaths as $ key => $ value ) {
96- $ dir = Craft::getAlias ($ value );
97- try {
98- FileHelper::clearDirectory ($ dir );
99- Craft::info (
100- Craft::t (
101- 'transcoder ' ,
102- '{name} cache directory cleared ' ,
103- ['name ' => $ key ]
104- ),
105- __METHOD__
106- );
107- } catch (ErrorException $ e ) {
108- // the directory doesn't exist
109- Craft::error ($ e ->getMessage (), __METHOD__ );
110- }
94+
95+ foreach ($ transcoderPaths as $ key => $ value ) {
96+ $ dir = Craft::getAlias ($ value );
97+ try {
98+ FileHelper::clearDirectory ($ dir );
99+ Craft::info (
100+ Craft::t (
101+ 'transcoder ' ,
102+ '{name} cache directory cleared ' ,
103+ ['name ' => $ key ]
104+ ),
105+ __METHOD__
106+ );
107+ } catch (ErrorException $ e ) {
108+ // the directory doesn't exist
109+ Craft::error ($ e ->getMessage (), __METHOD__ );
111110 }
112111 }
113-
114112 }
115113
116114 // Protected Methods
@@ -146,6 +144,7 @@ function (Event $event) {
146144 */
147145 protected function installEventHandlers ()
148146 {
147+ $ settings = $ this ->getSettings ();
149148 // Handler: Assets::EVENT_GET_THUMB_PATH
150149 Event::on (
151150 Assets::class,
@@ -162,18 +161,20 @@ function (AssetThumbEvent $event) {
162161 }
163162 }
164163 );
165- // Add the Transcode path to the list of things the Clear Caches tool can delete.
166- Event::on (
167- ClearCaches::class,
168- ClearCaches::EVENT_REGISTER_CACHE_OPTIONS ,
169- function (RegisterCacheOptionsEvent $ event ) {
170- $ event ->options [] = [
171- 'key ' => 'transcoder ' ,
172- 'label ' => Craft::t ('transcoder ' , 'Transcoder caches ' ),
173- 'action ' => [$ this , 'clearAllCaches ' ]
174- ];
175- }
176- );
164+ if ($ settings ->clearCaches ) {
165+ // Add the Transcode path to the list of things the Clear Caches tool can delete.
166+ Event::on (
167+ ClearCaches::class,
168+ ClearCaches::EVENT_REGISTER_CACHE_OPTIONS ,
169+ function (RegisterCacheOptionsEvent $ event ) {
170+ $ event ->options [] = [
171+ 'key ' => 'transcoder ' ,
172+ 'label ' => Craft::t ('transcoder ' , 'Transcoder caches ' ),
173+ 'action ' => [$ this , 'clearAllCaches ' ],
174+ ];
175+ }
176+ );
177+ }
177178 // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN
178179 Event::on (
179180 Plugins::class,
0 commit comments