Skip to content

Commit

Permalink
Fix admin backend log out issue with LiteMage
Browse files Browse the repository at this point in the history
  • Loading branch information
litespeedtech committed Oct 28, 2019
1 parent 99c7b3e commit 1ebf066
Show file tree
Hide file tree
Showing 26 changed files with 704 additions and 481 deletions.
137 changes: 69 additions & 68 deletions Block/Backend/Cache/Management.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* LiteMage
* @package LiteSpeed_LiteMage
Expand All @@ -10,6 +11,7 @@

class Management extends \Magento\Backend\Block\Template
{

/**
* @var \Litespeed\Litemage\Model\Config
*/
Expand All @@ -19,20 +21,23 @@ class Management extends \Magento\Backend\Block\Template
* @var \Magento\Framework\HTTP\ClientFactory
*/
protected $httpClientFactory;

/**
*
* @param \Magento\Backend\Block\Template\Context $context
* @param \Litespeed\Litemage\Model\Config $config,
* @param \Litespeed\Litemage\Model\Config $config
* @param \Magento\Framework\HTTP\ClientFactory $httpClientFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Litespeed\Litemage\Model\Config $config,
\Magento\Framework\HTTP\ClientFactory $httpClientFactory,
array $data = [])
\Magento\Backend\Block\Template\Context $context,
\Litespeed\Litemage\Model\Config $config,
\Magento\Framework\HTTP\ClientFactory $httpClientFactory,
array $data = [])
{
parent::__construct($context, $data);
$this->config = $config;
$this->httpClientFactory = $httpClientFactory;
$this->config = $config;
$this->httpClientFactory = $httpClientFactory;
}

/**
Expand All @@ -42,75 +47,72 @@ public function __construct(
*/
public function getPurgeUrl($type)
{
if ($type == 'Refresh') {
return $this->getUrl('*/*/cache/index');
}
else {
$types = ['All', 'Tag', 'Url'];
if ($type == 'Refresh') {
return $this->getUrl('*/*/cache/index');
} else {
$types = ['All', 'Tag', 'Url'];

if (in_array($type, $types)) {
return $this->getUrl('*/litemageCache/purge' . $type);
}
else {
return $this->getUrl('*/litemageCache/purgeAll');
}
}
if (in_array($type, $types)) {
return $this->getUrl('*/litemageCache/purge' . $type);
} else {
return $this->getUrl('*/litemageCache/purgeAll');
}
}
}

public function getCacheStatistics()
{
$statUri = '/__LSCACHE/STATS';
public function getCacheStatistics()
{
$statUri = '/__LSCACHE/STATS';
$base = $this->getUrl();
if ((stripos($base, 'http') !== false) && ($pos = strpos($base, '://'))) {
$pos2 = strpos($base, '/', $pos+ 4);
if ($pos2 === false) {
$statBase = $base;
}
else {
$statBase = substr($base, 0, $pos2);
if (substr($base, $pos2+1, 1) == '~') {
if ($pos3 = strpos($base, '/', $pos2+1)) {
$statBase = substr($base, 0, $pos3);
}
}
}
}
$statUri = $statBase . $statUri;
if ((stripos($base, 'http') !== false) && ($pos = strpos($base, '://'))) {
$pos2 = strpos($base, '/', $pos + 4);
if ($pos2 === false) {
$statBase = $base;
} else {
$statBase = substr($base, 0, $pos2);
if (substr($base, $pos2 + 1, 1) == '~') {
if ($pos3 = strpos($base, '/', $pos2 + 1)) {
$statBase = substr($base, 0, $pos3);
}
}
}
}
$statUri = $statBase . $statUri;

try {
$client = $this->httpClientFactory->create();
try {
$client = $this->httpClientFactory->create();
$client->setOption(CURLOPT_SSL_VERIFYHOST, 0);
$client->setOption(CURLOPT_SSL_VERIFYPEER, 0);
$client->setOption(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); // need to force http1.1
$client->get($statUri) ;
$data = trim($client->getBody());
if ($data == '' || $data{0} !== '{') {
return null;
}

$data1 = json_decode($data, true);
$data2 = array_values($data1);
if (count($data2)) {
$stats = $data2[0];
switch ($stats['LITEMAGE_PLAN']) {
case 11: $stats['plan'] = 'LiteMage Standard';
$stats['plan_desc'] = 'up to 25000 publicly cached objects';
break;
case 3: $stats['plan'] = 'LiteMage Unlimited';
$stats['plan_desc'] = 'unlimited publicly cached objects';
break;
case 9:
default:
$stats['plan'] = 'LiteMage Starter';
$stats['plan_desc'] = 'up to 1500 publicly cached objects';
}
return $stats;
}
} catch ( Exception $e ) {
}
return null;
}
$client->get($statUri);
$data = trim($client->getBody());
if ($data == '' || $data{0} !== '{') {
return null;
}

$data1 = json_decode($data, true);
$data2 = array_values($data1);
if (count($data2)) {
$stats = $data2[0];
switch ($stats['LITEMAGE_PLAN']) {
case 11: $stats['plan'] = 'LiteMage Standard';
$stats['plan_desc'] = 'up to 25000 publicly cached objects';
break;
case 3: $stats['plan'] = 'LiteMage Unlimited';
$stats['plan_desc'] = 'unlimited publicly cached objects';
break;
case 9:
default:
$stats['plan'] = 'LiteMage Starter';
$stats['plan_desc'] = 'up to 1500 publicly cached objects';
}
return $stats;
}
} catch (Exception $e) {

}
return null;
}

/**
* Check if block can be displayed
Expand All @@ -122,5 +124,4 @@ public function canShowButton()
return $this->config->moduleEnabled();
}


}
17 changes: 8 additions & 9 deletions Block/Inject/CustomVary.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@ class CustomVary extends \Magento\Framework\View\Element\Template
{

/**
* @var \Litespeed\Litemage\Model\CacheControl
* @var \Litespeed\Litemage\Helper\Data
*/
protected $litemageCache;
protected $helper;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Litespeed\Litemage\Model\Config $config,
* @param \Magento\Framework\View\Element\Template\Context $context,
* @param \Litespeed\Litemage\Helper\Data $helper,
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Litespeed\Litemage\Model\CacheControl $litemageCache,
\Magento\Framework\View\Element\Template\Context $context,
\Litespeed\Litemage\Helper\Data $helper,
array $data = [])
{
parent::__construct($context, $data);
$this->litemageCache = $litemageCache;
$this->helper = $helper;
}


public function needAjax()
{
return $this->litemageCache->needCustVaryAjax();
return $this->helper->needCustVaryAjax();
}

public function getCheckUrl()
Expand Down
6 changes: 4 additions & 2 deletions Controller/Block/CustomVary.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* LiteMage
* @package LiteSpeed_LiteMage
Expand All @@ -10,6 +11,7 @@

class CustomVary extends \Magento\Framework\App\Action\Action
{

/** @var \Magento\Framework\Controller\Result\JsonFactory */
protected $jsonFactory;

Expand All @@ -18,7 +20,6 @@ class CustomVary extends \Magento\Framework\App\Action\Action
*/
protected $litemageCache;


/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Controller\Result\JsonFactory $jsonFactory
Expand All @@ -28,7 +29,8 @@ public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Controller\Result\JsonFactory $jsonFactory,
\Litespeed\Litemage\Model\CacheControl $litemageCache
) {
)
{
parent::__construct($context);
$this->jsonFactory = $jsonFactory;
$this->litemageCache = $litemageCache;
Expand Down
13 changes: 8 additions & 5 deletions Controller/Block/Esi.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* LiteMage
* @package LiteSpeed_LiteMage
Expand All @@ -10,6 +11,7 @@

class Esi extends \Magento\Framework\App\Action\Action
{

/**
* @var \Magento\Framework\Translate\InlineInterface
*/
Expand All @@ -20,7 +22,6 @@ class Esi extends \Magento\Framework\App\Action\Action
*/
protected $litemageCache;


/**
* @param \Magento\Framework\App\Action\Context $context
* @param \Magento\Framework\Translate\InlineInterface $translateInline
Expand All @@ -30,7 +31,8 @@ public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Translate\InlineInterface $translateInline,
\Litespeed\Litemage\Model\CacheControl $litemageCache
) {
)
{
parent::__construct($context);
$this->translateInline = $translateInline;
$this->litemageCache = $litemageCache;
Expand All @@ -49,7 +51,8 @@ public function execute()
$response = $this->getResponse();
$ttl = 86400;
$html = $layout->renderElement($block);
if ( $tags = $this->litemageCache->getElementCacheTags($layout, $block) ) {
if ($tags = $this->litemageCache->getElementCacheTags($layout,
$block)) {
$this->litemageCache->setCacheTags($tags);
}

Expand Down Expand Up @@ -83,7 +86,7 @@ protected function _prepareLayout(&$block)
if ($layout->hasElement($block)) {
return $layout;
}
else
return null;
return null;
}

}
Loading

0 comments on commit 1ebf066

Please sign in to comment.