Skip to content

Commit 5e2f6d0

Browse files
authoredFeb 21, 2017
Merge pull request #1368 from nexcess/devel
Devel
2 parents 4929b8a + b3dbe4e commit 5e2f6d0

File tree

15 files changed

+103
-71
lines changed

15 files changed

+103
-71
lines changed
 

‎app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121

2222
class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll {
2323

24-
public function setTemplate($template)
25-
{
26-
if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) &&
27-
(!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll')))
28-
{
29-
$this->_template = $template;
30-
$this->setPollTemplate('turpentine/ajax.phtml', 'poll');
31-
$this->setPollTemplate('turpentine/ajax.phtml', 'results');
32-
}
33-
else
34-
{
35-
// Mage_Poll is disabled, so do nothing
36-
}
37-
return $this;
38-
}
24+
public function setTemplate($template)
25+
{
26+
if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) &&
27+
(!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll')))
28+
{
29+
$this->_template = $template;
30+
$this->setPollTemplate('turpentine/ajax.phtml', 'poll');
31+
$this->setPollTemplate('turpentine/ajax.phtml', 'results');
32+
}
33+
else
34+
{
35+
// Mage_Poll is disabled, so do nothing
36+
}
37+
return $this;
38+
}
3939
}

‎app/code/community/Nexcessnet/Turpentine/Helper/Esi.php

+26
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,32 @@ public function getFormKeyEsiUrl() {
362362
return $esiUrl;
363363
}
364364

365+
/**
366+
* Grab a block node by name from the layout XML.
367+
*
368+
* Multiple blocks with the same name may exist in the layout, because some themes
369+
* use 'unsetChild' to remove a block and create it with the same name somewhere
370+
* else. For example Ultimo does this.
371+
*
372+
* @param Mage_Core_Model_Layout $layout
373+
* @param string $blockName value of name= attribute in layout XML
374+
* @return Mage_Core_Model_Layout_Element
375+
*/
376+
public function getEsiLayoutBlockNode($layout, $blockName) {
377+
// first try very specific by checking for action setEsiOptions inside block
378+
$blockNode = current($layout->getNode()->xpath(
379+
sprintf('//block[@name=\'%s\'][action[@method=\'setEsiOptions\']]',
380+
$blockName)
381+
));
382+
// fallback: only match name
383+
if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) {
384+
$blockNode = current($layout->getNode()->xpath(
385+
sprintf('//block[@name=\'%s\']', $blockName)
386+
));
387+
}
388+
return $blockNode;
389+
}
390+
365391
/**
366392
* Load the ESI cache clear events from the layout
367393
*

‎app/code/community/Nexcessnet/Turpentine/Model/Config/Select/Version.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function toOptionArray() {
2626
array('value' => '2.1', 'label' => $helper->__('2.1.x')),
2727
array('value' => '3.0', 'label' => $helper->__('3.0.x')),
2828
array('value' => '4.0', 'label' => $helper->__('4.0.x')),
29+
array('value' => '4.1', 'label' => $helper->__('4.1.x')),
2930
array('value' => 'auto', 'label' => $helper->__('Auto')),
3031
);
3132
}

‎app/code/community/Nexcessnet/Turpentine/Model/Core/Session.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function real_getFormKey()
5656
*/
5757
public function renewFormKey()
5858
{
59-
$this->setData('_form_key', Mage::helper('core')->getRandomString(16));
59+
$this->setData('_form_key', Mage::helper('core')->getRandomString(16));
6060
}
6161

6262
/**

‎app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ public function injectEsi($eventObject) {
227227
'Checking ESI block candidate: %s',
228228
$blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );
229229

230-
$debugHelper->logInfo( "-- block testing: shouldResponseUseEsi = " . $esiHelper->shouldResponseUseEsi());
231-
$debugHelper->logInfo( "-- block testing: instanceof Mage_Core_Block_Template = " . $blockObject instanceof Mage_Core_Block_Template );
232-
$debugHelper->logInfo( "-- block testing: Esi Options = " . print_r($blockObject->getEsiOptions(), true) );
230+
$debugHelper->logInfo("-- block testing: shouldResponseUseEsi = ".$esiHelper->shouldResponseUseEsi());
231+
$debugHelper->logInfo("-- block testing: instanceof Mage_Core_Block_Template = ".$blockObject instanceof Mage_Core_Block_Template);
232+
$debugHelper->logInfo("-- block testing: Esi Options = ".print_r($blockObject->getEsiOptions(), true));
233233
}
234234
if ($esiHelper->shouldResponseUseEsi() &&
235235
$blockObject instanceof Mage_Core_Block_Template &&
@@ -297,6 +297,11 @@ public function injectEsi($eventObject) {
297297
);
298298
}
299299

300+
/**
301+
* Keep params from original url
302+
*/
303+
$urlOptions['_query'] = Mage::app()->getRequest()->getParams();
304+
300305
$esiUrl = Mage::getUrl('turpentine/esi/getBlock', $urlOptions);
301306
if ($esiOptions[$methodParam] == 'esi') {
302307
// setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS
@@ -332,8 +337,8 @@ protected function _getEsiData($blockObject, $esiOptions) {
332337
$methodParam = $esiHelper->getEsiMethodParam();
333338
$esiData = new Varien_Object();
334339
$esiData->setStoreId(Mage::app()->getStore()->getId());
335-
$esiData->setDesignPackage( Mage::getDesign()->getPackageName() );
336-
$esiData->setDesignTheme( Mage::getDesign()->getTheme( 'layout' ) );
340+
$esiData->setDesignPackage(Mage::getDesign()->getPackageName());
341+
$esiData->setDesignTheme(Mage::getDesign()->getTheme('layout'));
337342
$esiData->setNameInLayout($blockObject->getNameInLayout());
338343
$esiData->setBlockType(get_class($blockObject));
339344
$esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject));
@@ -415,9 +420,8 @@ protected function _getBlockLayoutHandles($block) {
415420
$activeHandles = array();
416421
// get the xml node representing the block we're working on (from the
417422
// default handle probably)
418-
$blockNode = current($layout->getNode()->xpath(sprintf(
419-
'//block[@name=\'%s\']',
420-
$block->getNameInLayout() )));
423+
$blockNode = Mage::helper('turpentine/esi')->getEsiLayoutBlockNode(
424+
$layout, $block->getNameInLayout());
421425
$childBlocks = Mage::helper('turpentine/data')
422426
->getChildBlockNames($blockNode);
423427
foreach ($childBlocks as $blockName) {

‎app/code/community/Nexcessnet/Turpentine/Model/Observer/Varnish.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public function addProductListToolbarRewrite($eventObject) {
6565
*/
6666
public function fixCmRedisSessionLocks($eventObject) {
6767
if (Mage::helper('core')->isModuleEnabled('Cm_RedisSession')) {
68-
if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend']) {
68+
if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend'] &&
69+
! defined('CM_REDISSESSION_LOCKING_ENABLED')) {
6970
define('CM_REDISSESSION_LOCKING_ENABLED', false);
7071
}
7172
}

‎app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected function _testEsiSyntaxParam($socket) {
138138
$result = false;
139139

140140
if ($helper->csrfFixupNeeded()) {
141-
if ($socket->getVersion() === '4.0') {
141+
if ($socket->getVersion() === '4.0' || $socket->getVersion() === '4.1') {
142142
$paramName = 'feature';
143143
$value = $socket->param_show($paramName);
144144
$value = explode("\n", $value['text']);

‎app/code/community/Nexcessnet/Turpentine/Model/Varnish/Admin/Socket.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket {
8282
// varnish default, can only be changed at Varnish startup time
8383
// if data to write is over this limit the actual run-time limit is checked
8484
// and used
85-
const CLI_CMD_LENGTH_LIMIT = 8192;
85+
const CLI_CMD_LENGTH_LIMIT = 16384;
8686

8787
/**
8888
* Regexp to detect the varnish version number
@@ -93,7 +93,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket {
9393
/**
9494
* VCL config versions, should match config select values
9595
*/
96-
static protected $_VERSIONS = array('2.1', '3.0', '4.0');
96+
static protected $_VERSIONS = array('2.1', '3.0', '4.0', '4.1');
9797

9898
/**
9999
* Varnish socket connection
@@ -405,7 +405,7 @@ protected function _write($data) {
405405
if ($dataLength >= self::CLI_CMD_LENGTH_LIMIT) {
406406
$cliBufferResponse = $this->param_show('cli_buffer');
407407
$regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~';
408-
if ($this->getVersion() === '4.0') {
408+
if ($this->getVersion() === '4.0' || $this->getVersion() === '4.1') {
409409
// Varnish4 supports "16k" style notation
410410
$regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g|b]{1})?\s+\[bytes\]~';
411411
}
@@ -500,7 +500,7 @@ protected function _command($verb, $okCode = 200) {
500500
$response['code'], $response['text'] ));
501501
} else {
502502
if (Mage::getStoreConfig('turpentine_varnish/general/varnish_log_commands')) {
503-
Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: ' . $data);
503+
Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: '.$data);
504504
}
505505
return $response;
506506
}
@@ -518,6 +518,7 @@ protected function _translateCommandMethod($verb) {
518518
case '2.1':
519519
$command = str_replace('ban', 'purge', $command);
520520
break;
521+
case '4.1':
521522
case '4.0':
522523
case '3.0':
523524
$command = str_replace('purge', 'ban', $command);

‎app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Abstract.php

+16-13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static public function getFromSocket($socket) {
4040
}
4141
switch ($version) {
4242
case '4.0':
43+
case '4.1':
4344
return Mage::getModel(
4445
'turpentine/varnish_configurator_version4',
4546
array('socket' => $socket) );
@@ -110,8 +111,8 @@ public function save($generatedConfig) {
110111
* @return string
111112
*/
112113
protected function _getVclTemplateFilename($baseFilename) {
113-
$extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine');
114-
return sprintf('%s/misc/%s', $extensionDir, $baseFilename);
114+
$extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine');
115+
return sprintf('%s/misc/%s', $extensionDir, $baseFilename);
115116
}
116117

117118
/**
@@ -130,7 +131,7 @@ protected function _getVclFilename() {
130131
*
131132
* @return string
132133
*/
133-
protected function _getCustomIncludeFilename($position='') {
134+
protected function _getCustomIncludeFilename($position = '') {
134135
$key = 'custom_include_file';
135136
$key .= ($position) ? '_'.$position : '';
136137
return $this->_formatTemplate(
@@ -150,8 +151,7 @@ protected function _getCustomTemplateFilename() {
150151
Mage::getStoreConfig('turpentine_varnish/servers/custom_vcl_template'),
151152
array('root_dir' => Mage::getBaseDir())
152153
);
153-
if (is_file($filePath)) { return $filePath; }
154-
else { return null; }
154+
if (is_file($filePath)) { return $filePath; } else { return null; }
155155
}
156156

157157

@@ -192,8 +192,8 @@ protected function _vcl_call($subroutine) {
192192
*/
193193
protected function _getAdminFrontname() {
194194
if (Mage::getStoreConfig('admin/url/use_custom_path')) {
195-
if(Mage::getStoreConfig('web/url/use_store')) {
196-
return Mage::getModel('core/store')->load(0)->getCode() . "/" . Mage::getStoreConfig('admin/url/custom_path');
195+
if (Mage::getStoreConfig('web/url/use_store')) {
196+
return Mage::getModel('core/store')->load(0)->getCode()."/".Mage::getStoreConfig('admin/url/custom_path');
197197
} else {
198198
return Mage::getStoreConfig('admin/url/custom_path');
199199
}
@@ -868,6 +868,7 @@ protected function _vcl_sub_maintenance_allowed_ips() {
868868

869869
switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) {
870870
case 4.0:
871+
case 4.1:
871872
$tpl = <<<EOS
872873
if (req.http.X-Forwarded-For) {
873874
if (req.http.X-Forwarded-For !~ "{{debug_ips}}") {
@@ -907,11 +908,12 @@ protected function _vcl_sub_maintenance_allowed_ips() {
907908
*/
908909
protected function _vcl_sub_https_redirect_fix() {
909910
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
910-
$baseUrl = str_replace(array('http://','https://'), '', $baseUrl);
911-
$baseUrl = rtrim($baseUrl,'/');
911+
$baseUrl = str_replace(array('http://', 'https://'), '', $baseUrl);
912+
$baseUrl = rtrim($baseUrl, '/');
912913

913914
switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) {
914915
case 4.0:
916+
case 4.1:
915917
$tpl = <<<EOS
916918
if ( (req.http.host ~ "^(?i)www.$baseUrl" || req.http.host ~ "^(?i)$baseUrl") && req.http.X-Forwarded-Proto !~ "(?i)https") {
917919
return (synth(750, ""));
@@ -942,6 +944,7 @@ protected function _vcl_sub_synth()
942944

943945
switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) {
944946
case 4.0:
947+
case 4.1:
945948
$tpl = <<<EOS
946949
sub vcl_synth {
947950
if (resp.status == 999) {
@@ -978,7 +981,7 @@ protected function _vcl_sub_synth_https_fix()
978981
{
979982
$tpl = $this->_vcl_sub_synth();
980983

981-
if(!$tpl){
984+
if ( ! $tpl) {
982985
$tpl = <<<EOS
983986
sub vcl_synth {
984987
if (resp.status == 750) {
@@ -988,7 +991,7 @@ protected function _vcl_sub_synth_https_fix()
988991
}
989992
}
990993
EOS;
991-
}else{
994+
} else{
992995
$tpl_750 = '
993996
sub vcl_synth {
994997
if (resp.status == 750) {
@@ -1085,12 +1088,12 @@ protected function _getTemplateVars() {
10851088

10861089
if (Mage::getStoreConfig('turpentine_varnish/general/https_redirect_fix')) {
10871090
$vars['https_redirect'] = $this->_vcl_sub_https_redirect_fix();
1088-
if(Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0'){
1091+
if (Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0' || Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.1') {
10891092
$vars['vcl_synth'] = $this->_vcl_sub_synth_https_fix();
10901093
}
10911094
}
10921095

1093-
foreach (array('','top') as $position) {
1096+
foreach (array('', 'top') as $position) {
10941097
$customIncludeFile = $this->_getCustomIncludeFilename($position);
10951098
if (is_readable($customIncludeFile)) {
10961099
$key = 'custom_vcl_include';

‎app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version3.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function generate($doClean = true) {
3535
$customTemplate = $this->_getCustomTemplateFilename();
3636
if ($customTemplate) {
3737
$tplFile = $customTemplate;
38-
}
39-
else {
38+
} else {
4039
$tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE);
4140
}
4241
$vcl = $this->_formatTemplate(file_get_contents($tplFile),

‎app/code/community/Nexcessnet/Turpentine/Model/Varnish/Configurator/Version4.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function generate($doClean = true) {
3535
$customTemplate = $this->_getCustomTemplateFilename();
3636
if ($customTemplate) {
3737
$tplFile = $customTemplate;
38-
}
39-
else {
38+
} else {
4039
$tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE);
4140
}
4241
$vcl = $this->_formatTemplate(file_get_contents($tplFile),
@@ -94,13 +93,13 @@ protected function _vcl_directors()
9493
$backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL,
9594
Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes'));
9695

97-
for($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) {
96+
for ($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) {
9897
$tpl .= <<<EOS
9998
vdir.add_backend(web{$i});
10099
EOS;
101100
}
102101

103-
for($i = 0, $iMax = count($adminBackendNodes); $i < $iMax; $i++) {
102+
for ($i = 0, $iMax = count($adminBackendNodes); $i < $iMax; $i++) {
104103
$tpl .= <<<EOS
105104
vdir_admin.add_backend(webadmin{$i});
106105
EOS;
@@ -132,7 +131,7 @@ protected function _vcl_director($name, $backendOptions) {
132131
Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes'));
133132
$probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url');
134133

135-
if('admin' == $name) {
134+
if ('admin' == $name) {
136135
$prefix = 'admin';
137136
} else {
138137
$prefix = '';
@@ -145,7 +144,7 @@ protected function _vcl_director($name, $backendOptions) {
145144
$parts = explode(':', $backendNode, 2);
146145
$host = (empty($parts[0])) ? '127.0.0.1' : $parts[0];
147146
$port = (empty($parts[1])) ? '80' : $parts[1];
148-
$backends .= $this->_vcl_director_backend($host, $port, $prefix . $number, $probeUrl, $backendOptions);
147+
$backends .= $this->_vcl_director_backend($host, $port, $prefix.$number, $probeUrl, $backendOptions);
149148

150149
$number++;
151150
}

‎app/code/community/Nexcessnet/Turpentine/controllers/EsiController.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ protected function _getEsiBlock($esiData) {
183183
}
184184
}
185185
$layout = Mage::getSingleton('core/layout');
186-
Mage::getSingleton( 'core/design_package' )
187-
->setPackageName( $esiData->getDesignPackage() )
188-
->setTheme( $esiData->getDesignTheme() );
186+
Mage::getSingleton('core/design_package')
187+
->setPackageName($esiData->getDesignPackage())
188+
->setTheme($esiData->getDesignTheme());
189189

190190
// dispatch event for adding handles to layout update
191191
Mage::dispatchEvent(
@@ -212,10 +212,8 @@ protected function _getEsiBlock($esiData) {
212212
$turpentineHelper = Mage::helper('turpentine/data')
213213
->setLayout($layout);
214214

215-
$blockNode = current($layout->getNode()->xpath(
216-
sprintf('//block[@name=\'%s\']', $esiData->getNameInLayout())
217-
));
218-
215+
$blockNode = Mage::helper('turpentine/esi')->getEsiLayoutBlockNode(
216+
$layout, $esiData->getNameInLayout());
219217
if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) {
220218
Mage::helper('turpentine/debug')->logWarn(
221219
'No block node found with @name="%s"',

‎app/code/community/Nexcessnet/Turpentine/etc/config.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<config>
2121
<modules>
2222
<Nexcessnet_Turpentine>
23-
<version>0.7.1</version>
23+
<version>0.7.2</version>
2424
</Nexcessnet_Turpentine>
2525
</modules>
2626
<default>

‎app/code/community/Nexcessnet/Turpentine/misc/version-4.vcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ sub vcl_recv {
127127
if (!{{enable_caching}} || req.http.Authorization ||
128128
req.method !~ "^(GET|HEAD|OPTIONS)$" ||
129129
req.http.Cookie ~ "varnish_bypass={{secret_handshake}}") {
130-
return (pass);
130+
return (pipe);
131131
}
132132

133133
if({{send_unmodified_url}}) {

‎contrib/tools/esi-decoder.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
22
/**
3-
* ESI DECODER
4-
*
5-
* This tool can be used to decode an ESI request.
6-
* You can just paste the whole ESI URL and push the button to decode it.
7-
*
8-
* Make sure you place this utility on a protected spot on your web server where only authorized users can use it.
9-
*
10-
* If the URLs you see in "varnishlog" or "varnishncsa" are not working because they are cut off, read this FAQ item:
11-
* https://github.com/nexcess/magento-turpentine/wiki/FAQ#im-using-varnishncsa-to-generate-logs-and-the-esi-urls-are-cut-off-how-do-i-get-the-full-url-in-the-logs
12-
*
13-
*/
3+
* ESI DECODER
4+
*
5+
* This tool can be used to decode an ESI request.
6+
* You can just paste the whole ESI URL and push the button to decode it.
7+
*
8+
* Make sure you place this utility on a protected spot on your web server where only authorized users can use it.
9+
*
10+
* If the URLs you see in "varnishlog" or "varnishncsa" are not working because they are cut off, read this FAQ item:
11+
* https://github.com/nexcess/magento-turpentine/wiki/FAQ#im-using-varnishncsa-to-generate-logs-and-the-esi-urls-are-cut-off-how-do-i-get-the-full-url-in-the-logs
12+
*
13+
*/
1414

1515
$tries = 5;
1616
$dir = dirname(__FILE__);

0 commit comments

Comments
 (0)
Please sign in to comment.