aelvan / VarnishPurge-Craft

Craft plugin for purging Varnish when elements are saved.
MIT License
33 stars 11 forks source link

Fix undefined variable in event callback #12

Closed timkelty closed 7 years ago

timkelty commented 7 years ago

As far as I can tell master is totally broken without this...

aelvan commented 7 years ago

What PHP version were you on?

timkelty commented 7 years ago

7.0.13

timkelty commented 7 years ago

Weird, and of course now I can't reproduce the error.

aelvan commented 7 years ago

I thought that way of using use() was only necessary in PHP 5.3 to make things accessible inside the scope of the anonymous function. No problem merging in the PR, as PHP 5.3 compatibility is a plus, just curious if there was something I'd missed. :)

timkelty commented 7 years ago

That's right - and we're in an anonymous function (2nd arg of craft()->on) and need access to the outside scope's $purgeRelated.

timkelty commented 7 years ago

/index.php?p=cp/actions/elements/saveElement

<h1>PHP Error [500]</h1>
<p>Undefined variable: purgeRelated (/Users/timkelty/Sites/paddling/craft/plugins/varnishpurge/VarnishpurgePlugin.php:78)</p>
<pre>#0 /Users/timkelty/Sites/paddling/craft/app/etc/errors/ErrorHandler.php(184): Craft\ErrorHandler->handleError()
#1 /Users/timkelty/Sites/paddling/craft/app/framework/base/CErrorHandler.php(133): Craft\ErrorHandler->handleError()
#2 /Users/timkelty/Sites/paddling/craft/app/framework/base/CApplication.php(834): Craft\ErrorHandler->handle()
#3 /Users/timkelty/Sites/paddling/craft/app/etc/web/WebApp.php(687): Craft\WebApp->handleError()
#4 /Users/timkelty/Sites/paddling/craft/plugins/varnishpurge/VarnishpurgePlugin.php(78): Craft\WebApp->handleError()
#5 /Users/timkelty/Sites/paddling/craft/app/framework/base/CComponent.php(567): Craft\VarnishpurgePlugin->Craft\{closure}()
#6 /Users/timkelty/Sites/paddling/craft/app/services/ElementsService.php(2379): Craft\ElementsService->raiseEvent()
#7 /Users/timkelty/Sites/paddling/craft/app/services/ElementsService.php(1657): Craft\ElementsService->onSaveElement()
#8 /Users/timkelty/Sites/paddling/craft/app/elementtypes/BaseElementType.php(656): Craft\ElementsService->saveElement()
#9 /Users/timkelty/Sites/paddling/craft/app/elementtypes/AssetElementType.php(555): Craft\AssetElementType->saveElement()
#10 /Users/timkelty/Sites/paddling/craft/app/controllers/ElementsController.php(114): Craft\AssetElementType->saveElement()
#11 /Users/timkelty/Sites/paddling/craft/app/framework/web/actions/CInlineAction.php(49): Craft\ElementsController->actionSaveElement()
#12 /Users/timkelty/Sites/paddling/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams()
#13 /Users/timkelty/Sites/paddling/craft/app/framework/web/CController.php(286): Craft\ElementsController->runAction()
#14 /Users/timkelty/Sites/paddling/craft/app/framework/web/CController.php(265): Craft\ElementsController->runActionWithFilters()
#15 /Users/timkelty/Sites/paddling/craft/app/framework/web/CWebApplication.php(282): Craft\ElementsController->run()
#16 /Users/timkelty/Sites/paddling/craft/app/etc/web/WebApp.php(817): Craft\WebApp->runController()
#17 /Users/timkelty/Sites/paddling/craft/app/etc/web/WebApp.php(287): Craft\WebApp->_processActionRequest()
#18 /Users/timkelty/Sites/paddling/craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
#19 /Users/timkelty/Sites/paddling/craft/app/index.php(62): Craft\WebApp->run()
#20 /Users/timkelty/Sites/paddling/public/index.php(18): require_once()
</pre>