Skip to content

Commit

Permalink
Merge pull request #1368 from nexcess/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
miguelbalparda committed Feb 21, 2017
2 parents 4929b8a + b3dbe4e commit 5e2f6d0
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 71 deletions.
30 changes: 15 additions & 15 deletions app/code/community/Nexcessnet/Turpentine/Block/Poll/ActivePoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@

class Nexcessnet_Turpentine_Block_Poll_ActivePoll extends Mage_Poll_Block_ActivePoll {

public function setTemplate($template)
{
if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) &&
(!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll')))
{
$this->_template = $template;
$this->setPollTemplate('turpentine/ajax.phtml', 'poll');
$this->setPollTemplate('turpentine/ajax.phtml', 'results');
}
else
{
// Mage_Poll is disabled, so do nothing
}
return $this;
}
public function setTemplate($template)
{
if ((Mage::getConfig()->getModuleConfig('Mage_Poll')->is('active', 'true')) &&
(!Mage::getStoreConfig('advanced/modules_disable_output/Mage_Poll')))
{
$this->_template = $template;
$this->setPollTemplate('turpentine/ajax.phtml', 'poll');
$this->setPollTemplate('turpentine/ajax.phtml', 'results');
}
else
{
// Mage_Poll is disabled, so do nothing
}
return $this;
}
}
26 changes: 26 additions & 0 deletions app/code/community/Nexcessnet/Turpentine/Helper/Esi.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,32 @@ public function getFormKeyEsiUrl() {
return $esiUrl;
}

/**
* Grab a block node by name from the layout XML.
*
* Multiple blocks with the same name may exist in the layout, because some themes
* use 'unsetChild' to remove a block and create it with the same name somewhere
* else. For example Ultimo does this.
*
* @param Mage_Core_Model_Layout $layout
* @param string $blockName value of name= attribute in layout XML
* @return Mage_Core_Model_Layout_Element
*/
public function getEsiLayoutBlockNode($layout, $blockName) {
// first try very specific by checking for action setEsiOptions inside block
$blockNode = current($layout->getNode()->xpath(
sprintf('//block[@name=\'%s\'][action[@method=\'setEsiOptions\']]',
$blockName)
));
// fallback: only match name
if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) {
$blockNode = current($layout->getNode()->xpath(
sprintf('//block[@name=\'%s\']', $blockName)
));
}
return $blockNode;
}

/**
* Load the ESI cache clear events from the layout
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function toOptionArray() {
array('value' => '2.1', 'label' => $helper->__('2.1.x')),
array('value' => '3.0', 'label' => $helper->__('3.0.x')),
array('value' => '4.0', 'label' => $helper->__('4.0.x')),
array('value' => '4.1', 'label' => $helper->__('4.1.x')),
array('value' => 'auto', 'label' => $helper->__('Auto')),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function real_getFormKey()
*/
public function renewFormKey()
{
$this->setData('_form_key', Mage::helper('core')->getRandomString(16));
$this->setData('_form_key', Mage::helper('core')->getRandomString(16));
}

/**
Expand Down
20 changes: 12 additions & 8 deletions app/code/community/Nexcessnet/Turpentine/Model/Observer/Esi.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ public function injectEsi($eventObject) {
'Checking ESI block candidate: %s',
$blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName() );

$debugHelper->logInfo( "-- block testing: shouldResponseUseEsi = " . $esiHelper->shouldResponseUseEsi());
$debugHelper->logInfo( "-- block testing: instanceof Mage_Core_Block_Template = " . $blockObject instanceof Mage_Core_Block_Template );
$debugHelper->logInfo( "-- block testing: Esi Options = " . print_r($blockObject->getEsiOptions(), true) );
$debugHelper->logInfo("-- block testing: shouldResponseUseEsi = ".$esiHelper->shouldResponseUseEsi());
$debugHelper->logInfo("-- block testing: instanceof Mage_Core_Block_Template = ".$blockObject instanceof Mage_Core_Block_Template);
$debugHelper->logInfo("-- block testing: Esi Options = ".print_r($blockObject->getEsiOptions(), true));
}
if ($esiHelper->shouldResponseUseEsi() &&
$blockObject instanceof Mage_Core_Block_Template &&
Expand Down Expand Up @@ -297,6 +297,11 @@ public function injectEsi($eventObject) {
);
}

/**
* Keep params from original url
*/
$urlOptions['_query'] = Mage::app()->getRequest()->getParams();

$esiUrl = Mage::getUrl('turpentine/esi/getBlock', $urlOptions);
if ($esiOptions[$methodParam] == 'esi') {
// setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS
Expand Down Expand Up @@ -332,8 +337,8 @@ protected function _getEsiData($blockObject, $esiOptions) {
$methodParam = $esiHelper->getEsiMethodParam();
$esiData = new Varien_Object();
$esiData->setStoreId(Mage::app()->getStore()->getId());
$esiData->setDesignPackage( Mage::getDesign()->getPackageName() );
$esiData->setDesignTheme( Mage::getDesign()->getTheme( 'layout' ) );
$esiData->setDesignPackage(Mage::getDesign()->getPackageName());
$esiData->setDesignTheme(Mage::getDesign()->getTheme('layout'));
$esiData->setNameInLayout($blockObject->getNameInLayout());
$esiData->setBlockType(get_class($blockObject));
$esiData->setLayoutHandles($this->_getBlockLayoutHandles($blockObject));
Expand Down Expand Up @@ -415,9 +420,8 @@ protected function _getBlockLayoutHandles($block) {
$activeHandles = array();
// get the xml node representing the block we're working on (from the
// default handle probably)
$blockNode = current($layout->getNode()->xpath(sprintf(
'//block[@name=\'%s\']',
$block->getNameInLayout() )));
$blockNode = Mage::helper('turpentine/esi')->getEsiLayoutBlockNode(
$layout, $block->getNameInLayout());
$childBlocks = Mage::helper('turpentine/data')
->getChildBlockNames($blockNode);
foreach ($childBlocks as $blockName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function addProductListToolbarRewrite($eventObject) {
*/
public function fixCmRedisSessionLocks($eventObject) {
if (Mage::helper('core')->isModuleEnabled('Cm_RedisSession')) {
if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend']) {
if ( ! empty($_COOKIE['frontend']) && 'crawler-session' == $_COOKIE['frontend'] &&
! defined('CM_REDISSESSION_LOCKING_ENABLED')) {
define('CM_REDISSESSION_LOCKING_ENABLED', false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function _testEsiSyntaxParam($socket) {
$result = false;

if ($helper->csrfFixupNeeded()) {
if ($socket->getVersion() === '4.0') {
if ($socket->getVersion() === '4.0' || $socket->getVersion() === '4.1') {
$paramName = 'feature';
$value = $socket->param_show($paramName);
$value = explode("\n", $value['text']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Nexcessnet_Turpentine_Model_Varnish_Admin_Socket {
// varnish default, can only be changed at Varnish startup time
// if data to write is over this limit the actual run-time limit is checked
// and used
const CLI_CMD_LENGTH_LIMIT = 8192;
const CLI_CMD_LENGTH_LIMIT = 16384;

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

/**
* Varnish socket connection
Expand Down Expand Up @@ -405,7 +405,7 @@ protected function _write($data) {
if ($dataLength >= self::CLI_CMD_LENGTH_LIMIT) {
$cliBufferResponse = $this->param_show('cli_buffer');
$regexp = '~^cli_buffer\s+(\d+)\s+\[bytes\]~';
if ($this->getVersion() === '4.0') {
if ($this->getVersion() === '4.0' || $this->getVersion() === '4.1') {
// Varnish4 supports "16k" style notation
$regexp = '~^cli_buffer\s+Value is:\s+(\d+)([k|m|g|b]{1})?\s+\[bytes\]~';
}
Expand Down Expand Up @@ -500,7 +500,7 @@ protected function _command($verb, $okCode = 200) {
$response['code'], $response['text'] ));
} else {
if (Mage::getStoreConfig('turpentine_varnish/general/varnish_log_commands')) {
Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: ' . $data);
Mage::helper('turpentine/debug')->logDebug('VARNISH command sent: '.$data);
}
return $response;
}
Expand All @@ -518,6 +518,7 @@ protected function _translateCommandMethod($verb) {
case '2.1':
$command = str_replace('ban', 'purge', $command);
break;
case '4.1':
case '4.0':
case '3.0':
$command = str_replace('purge', 'ban', $command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static public function getFromSocket($socket) {
}
switch ($version) {
case '4.0':
case '4.1':
return Mage::getModel(
'turpentine/varnish_configurator_version4',
array('socket' => $socket) );
Expand Down Expand Up @@ -110,8 +111,8 @@ public function save($generatedConfig) {
* @return string
*/
protected function _getVclTemplateFilename($baseFilename) {
$extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine');
return sprintf('%s/misc/%s', $extensionDir, $baseFilename);
$extensionDir = Mage::getModuleDir('', 'Nexcessnet_Turpentine');
return sprintf('%s/misc/%s', $extensionDir, $baseFilename);
}

/**
Expand All @@ -130,7 +131,7 @@ protected function _getVclFilename() {
*
* @return string
*/
protected function _getCustomIncludeFilename($position='') {
protected function _getCustomIncludeFilename($position = '') {
$key = 'custom_include_file';
$key .= ($position) ? '_'.$position : '';
return $this->_formatTemplate(
Expand All @@ -150,8 +151,7 @@ protected function _getCustomTemplateFilename() {
Mage::getStoreConfig('turpentine_varnish/servers/custom_vcl_template'),
array('root_dir' => Mage::getBaseDir())
);
if (is_file($filePath)) { return $filePath; }
else { return null; }
if (is_file($filePath)) { return $filePath; } else { return null; }
}


Expand Down Expand Up @@ -192,8 +192,8 @@ protected function _vcl_call($subroutine) {
*/
protected function _getAdminFrontname() {
if (Mage::getStoreConfig('admin/url/use_custom_path')) {
if(Mage::getStoreConfig('web/url/use_store')) {
return Mage::getModel('core/store')->load(0)->getCode() . "/" . Mage::getStoreConfig('admin/url/custom_path');
if (Mage::getStoreConfig('web/url/use_store')) {
return Mage::getModel('core/store')->load(0)->getCode()."/".Mage::getStoreConfig('admin/url/custom_path');
} else {
return Mage::getStoreConfig('admin/url/custom_path');
}
Expand Down Expand Up @@ -868,6 +868,7 @@ protected function _vcl_sub_maintenance_allowed_ips() {

switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) {
case 4.0:
case 4.1:
$tpl = <<<EOS
if (req.http.X-Forwarded-For) {
if (req.http.X-Forwarded-For !~ "{{debug_ips}}") {
Expand Down Expand Up @@ -907,11 +908,12 @@ protected function _vcl_sub_maintenance_allowed_ips() {
*/
protected function _vcl_sub_https_redirect_fix() {
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$baseUrl = str_replace(array('http:https://','https://'), '', $baseUrl);
$baseUrl = rtrim($baseUrl,'/');
$baseUrl = str_replace(array('http:https://', 'https://'), '', $baseUrl);
$baseUrl = rtrim($baseUrl, '/');

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

switch (Mage::getStoreConfig('turpentine_varnish/servers/version')) {
case 4.0:
case 4.1:
$tpl = <<<EOS
sub vcl_synth {
if (resp.status == 999) {
Expand Down Expand Up @@ -978,7 +981,7 @@ protected function _vcl_sub_synth_https_fix()
{
$tpl = $this->_vcl_sub_synth();

if(!$tpl){
if ( ! $tpl) {
$tpl = <<<EOS
sub vcl_synth {
if (resp.status == 750) {
Expand All @@ -988,7 +991,7 @@ protected function _vcl_sub_synth_https_fix()
}
}
EOS;
}else{
} else{
$tpl_750 = '
sub vcl_synth {
if (resp.status == 750) {
Expand Down Expand Up @@ -1085,12 +1088,12 @@ protected function _getTemplateVars() {

if (Mage::getStoreConfig('turpentine_varnish/general/https_redirect_fix')) {
$vars['https_redirect'] = $this->_vcl_sub_https_redirect_fix();
if(Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0'){
if (Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.0' || Mage::getStoreConfig('turpentine_varnish/servers/version') == '4.1') {
$vars['vcl_synth'] = $this->_vcl_sub_synth_https_fix();
}
}

foreach (array('','top') as $position) {
foreach (array('', 'top') as $position) {
$customIncludeFile = $this->_getCustomIncludeFilename($position);
if (is_readable($customIncludeFile)) {
$key = 'custom_vcl_include';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function generate($doClean = true) {
$customTemplate = $this->_getCustomTemplateFilename();
if ($customTemplate) {
$tplFile = $customTemplate;
}
else {
} else {
$tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE);
}
$vcl = $this->_formatTemplate(file_get_contents($tplFile),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function generate($doClean = true) {
$customTemplate = $this->_getCustomTemplateFilename();
if ($customTemplate) {
$tplFile = $customTemplate;
}
else {
} else {
$tplFile = $this->_getVclTemplateFilename(self::VCL_TEMPLATE_FILE);
}
$vcl = $this->_formatTemplate(file_get_contents($tplFile),
Expand Down Expand Up @@ -94,13 +93,13 @@ protected function _vcl_directors()
$backendNodes = Mage::helper('turpentine/data')->cleanExplode(PHP_EOL,
Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes'));

for($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) {
for ($i = 0, $iMax = count($backendNodes); $i < $iMax; $i++) {
$tpl .= <<<EOS
vdir.add_backend(web{$i});
EOS;
}

for($i = 0, $iMax = count($adminBackendNodes); $i < $iMax; $i++) {
for ($i = 0, $iMax = count($adminBackendNodes); $i < $iMax; $i++) {
$tpl .= <<<EOS
vdir_admin.add_backend(webadmin{$i});
EOS;
Expand Down Expand Up @@ -132,7 +131,7 @@ protected function _vcl_director($name, $backendOptions) {
Mage::getStoreConfig('turpentine_vcl/backend/backend_nodes'));
$probeUrl = Mage::getStoreConfig('turpentine_vcl/backend/backend_probe_url');

if('admin' == $name) {
if ('admin' == $name) {
$prefix = 'admin';
} else {
$prefix = '';
Expand All @@ -145,7 +144,7 @@ protected function _vcl_director($name, $backendOptions) {
$parts = explode(':', $backendNode, 2);
$host = (empty($parts[0])) ? '127.0.0.1' : $parts[0];
$port = (empty($parts[1])) ? '80' : $parts[1];
$backends .= $this->_vcl_director_backend($host, $port, $prefix . $number, $probeUrl, $backendOptions);
$backends .= $this->_vcl_director_backend($host, $port, $prefix.$number, $probeUrl, $backendOptions);

$number++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ protected function _getEsiBlock($esiData) {
}
}
$layout = Mage::getSingleton('core/layout');
Mage::getSingleton( 'core/design_package' )
->setPackageName( $esiData->getDesignPackage() )
->setTheme( $esiData->getDesignTheme() );
Mage::getSingleton('core/design_package')
->setPackageName($esiData->getDesignPackage())
->setTheme($esiData->getDesignTheme());

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

$blockNode = current($layout->getNode()->xpath(
sprintf('//block[@name=\'%s\']', $esiData->getNameInLayout())
));

$blockNode = Mage::helper('turpentine/esi')->getEsiLayoutBlockNode(
$layout, $esiData->getNameInLayout());
if ( ! ($blockNode instanceof Mage_Core_Model_Layout_Element)) {
Mage::helper('turpentine/debug')->logWarn(
'No block node found with @name="%s"',
Expand Down
2 changes: 1 addition & 1 deletion app/code/community/Nexcessnet/Turpentine/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<config>
<modules>
<Nexcessnet_Turpentine>
<version>0.7.1</version>
<version>0.7.2</version>
</Nexcessnet_Turpentine>
</modules>
<default>
Expand Down
Loading

0 comments on commit 5e2f6d0

Please sign in to comment.