// Better control of the requests when our website is down
This commit is contained in:
1 parent
53241af228
commit
ec11b7e064
3 files changed
+59
-87
No files matched your search
@@ -110,14 +110,14 @@ $(document).ready(function() {
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div id="partner_preactivation">
|
<div id="partner_preactivation">
|
||||||
<p class="center"><img src="../img/loader.gif" alt="" /></p>
|
<p class="center"><img src="../img/loader.gif" alt="" /> {l s='Loading...'}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="separation"></div>
|
<div class="separation"></div>
|
||||||
|
|
||||||
|
|
||||||
{$tips_optimization}
|
{$tips_optimization}
|
||||||
<div id="discover_prestashop"><p class="center"><img src="../img/loader.gif" alt="" />{l s='Loading...'}</p></div>
|
<div id="discover_prestashop"><p class="center"><img src="../img/loader.gif" alt="" /> {l s='Loading...'}</p></div>
|
||||||
|
|
||||||
{hook h="displayAdminHomeInfos"}
|
{hook h="displayAdminHomeInfos"}
|
||||||
{hook h="displayBackOfficeHome"} {*old name of the hook*}
|
{hook h="displayBackOfficeHome"} {*old name of the hook*}
|
||||||
@@ -212,7 +212,7 @@ $(document).ready(function() {
|
|||||||
{
|
{
|
||||||
// don't show/hide screencast if it's deactivated
|
// don't show/hide screencast if it's deactivated
|
||||||
{if $employee->bo_show_screencast}
|
{if $employee->bo_show_screencast}
|
||||||
$('#adminpresentation').fadeOut('slow');
|
$('#adminpresentation').fadeOut('slow');
|
||||||
{/if}
|
{/if}
|
||||||
$('#partner_preactivation').fadeOut('slow');
|
$('#partner_preactivation').fadeOut('slow');
|
||||||
$('#discover_prestashop').fadeOut('slow');
|
$('#discover_prestashop').fadeOut('slow');
|
||||||
|
|||||||
+43
-66
@@ -2481,89 +2481,66 @@ exit;
|
|||||||
return preg_replace('/\\\[px]\{[a-z]\}{1,2}|(\/[a-z]*)u([a-z]*)$/i', "$1$2", $pattern);
|
return preg_replace('/\\\[px]\{[a-z]\}{1,2}|(\/[a-z]*)u([a-z]*)$/i', "$1$2", $pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static $is_addons_up = true;
|
||||||
public static function addonsRequest($request, $params = array())
|
public static function addonsRequest($request, $params = array())
|
||||||
{
|
{
|
||||||
$addons_url = 'api.addons.prestashop.com';
|
if (!self::$is_addons_up)
|
||||||
$postData = '';
|
return false;
|
||||||
$postDataArray = array(
|
|
||||||
|
$postData = http_build_query(array(
|
||||||
'version' => isset($params['version']) ? $params['version'] : _PS_VERSION_,
|
'version' => isset($params['version']) ? $params['version'] : _PS_VERSION_,
|
||||||
'iso_lang' => Tools::strtolower(isset($params['iso_lang']) ? $params['iso_lang'] : Context::getContext()->language->iso_code),
|
'iso_lang' => Tools::strtolower(isset($params['iso_lang']) ? $params['iso_lang'] : Context::getContext()->language->iso_code),
|
||||||
'iso_code' => Tools::strtolower(isset($params['iso_country']) ? $params['iso_country'] : Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))),
|
'iso_code' => Tools::strtolower(isset($params['iso_country']) ? $params['iso_country'] : Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT'))),
|
||||||
'shop_url' => urlencode(isset($params['shop_url']) ? $params['shop_url'] : Tools::getShopDomain()),
|
'shop_url' => isset($params['shop_url']) ? $params['shop_url'] : Tools::getShopDomain(),
|
||||||
'mail' => urlencode(isset($params['email']) ? $params['email'] : Configuration::get('email'))
|
'mail' => isset($params['email']) ? $params['email'] : Configuration::get('email')
|
||||||
);
|
));
|
||||||
foreach ($postDataArray as $postDataKey => $postDataValue)
|
|
||||||
$postData .= '&'.$postDataKey.'='.$postDataValue;
|
|
||||||
$postData = ltrim($postData, '&');
|
|
||||||
|
|
||||||
// Config for each request
|
$protocols = array('https');
|
||||||
if ($request == 'native')
|
switch ($request)
|
||||||
{
|
{
|
||||||
// Define protocol accepted and post data values for this request
|
case 'native':
|
||||||
$protocolsList = array('https://' => 443, 'http://' => 80);
|
$protocols[] = 'http';
|
||||||
$postData .= '&method=listing&action=native';
|
$postData .= '&method=listing&action=native';
|
||||||
}
|
break;
|
||||||
if ($request == 'must-have')
|
case 'must-have':
|
||||||
{
|
$protocols[] = 'http';
|
||||||
// Define protocol accepted and post data values for this request
|
$postData .= '&method=listing&action=must-have';
|
||||||
$protocolsList = array('https://' => 443, 'http://' => 80);
|
break;
|
||||||
$postData .= '&method=listing&action=must-have';
|
case 'customer':
|
||||||
}
|
$postData .= '&method=listing&action=customer&username='.urlencode(trim(Context::getContext()->cookie->username_addons)).'&password='.urlencode(trim(Context::getContext()->cookie->password_addons));
|
||||||
if ($request == 'customer')
|
break;
|
||||||
{
|
case 'check_customer':
|
||||||
// Define protocol accepted and post data values for this request
|
$postData .= '&method=check_customer&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']);
|
||||||
$protocolsList = array('https://' => 443);
|
break;
|
||||||
$postData .= '&method=listing&action=customer&username='.urlencode(trim(Context::getContext()->cookie->username_addons)).'&password='.urlencode(trim(Context::getContext()->cookie->password_addons));
|
case 'module':
|
||||||
}
|
|
||||||
if ($request == 'check_customer')
|
|
||||||
{
|
|
||||||
// Define protocol accepted and post data values for this request
|
|
||||||
$protocolsList = array('https://' => 443);
|
|
||||||
$postData .= '&method=check_customer&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']);
|
|
||||||
}
|
|
||||||
if ($request == 'module')
|
|
||||||
{
|
|
||||||
// Define protocol accepted and post data values for this request
|
|
||||||
if (isset($params['username_addons']) && isset($params['password_addons']))
|
|
||||||
{
|
|
||||||
$protocolsList = array('https://' => 443);
|
|
||||||
$postData .= '&method=module&id_module='.urlencode($params['id_module']).'&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$protocolsList = array('https://' => 443, 'http://' => 80);
|
|
||||||
$postData .= '&method=module&id_module='.urlencode($params['id_module']);
|
$postData .= '&method=module&id_module='.urlencode($params['id_module']);
|
||||||
}
|
if (isset($params['username_addons']) && isset($params['password_addons']))
|
||||||
}
|
$postData .= '&username='.urlencode($params['username_addons']).'&password='.urlencode($params['password_addons']);
|
||||||
|
else
|
||||||
if ($request == 'install-modules')
|
$protocols[] = 'http';
|
||||||
{
|
|
||||||
// Define protocol accepted and post data values for this request
|
break;
|
||||||
$protocolsList = array('https://' => 443, 'http://' => 80);
|
case 'install-modules':
|
||||||
$postData .= '&method=listing&action=install-modules';
|
$protocols[] = 'http';
|
||||||
|
$postData .= '&method=listing&action=install-modules';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the request
|
$context = stream_context_create(array(
|
||||||
$opts = array(
|
'http' => array(
|
||||||
'http'=>array(
|
|
||||||
'method'=> 'POST',
|
'method'=> 'POST',
|
||||||
'content' => $postData,
|
'content' => $postData,
|
||||||
'header' => 'Content-type: application/x-www-form-urlencoded',
|
'header' => 'Content-type: application/x-www-form-urlencoded',
|
||||||
'timeout' => 5,
|
'timeout' => 5,
|
||||||
)
|
)
|
||||||
);
|
));
|
||||||
$context = stream_context_create($opts);
|
foreach ($protocols as $protocol)
|
||||||
foreach ($protocolsList as $protocol => $port)
|
if ($content = Tools::file_get_contents($protocol.'://api.addons.prestashop.com', false, $context))
|
||||||
{
|
|
||||||
$content = Tools::file_get_contents($protocol.$addons_url, false, $context);
|
|
||||||
|
|
||||||
// If content returned, we cache it
|
|
||||||
if ($content)
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
|
||||||
|
|
||||||
// No content, return false
|
self::$is_addons_up = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1539,24 +1539,23 @@ class AdminControllerCore extends Controller
|
|||||||
|
|
||||||
protected function addToolBarModulesListButton()
|
protected function addToolBarModulesListButton()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!$this->isFresh(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 86400))
|
if (!$this->isFresh(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 86400))
|
||||||
file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, Tools::addonsRequest('native'));
|
file_put_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, Tools::addonsRequest('native'));
|
||||||
|
|
||||||
$country_module_list_xml = simplexml_load_file(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST);
|
$country_module_list = file_get_contents(_PS_ROOT_DIR_.Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST);
|
||||||
if($country_module_list_xml === TRUE)
|
if (!empty($country_module_list) && $country_module_list_xml = simplexml_load_string($country_module_list))
|
||||||
{
|
{
|
||||||
$country_module_list = array();
|
$country_module_list_array = array();
|
||||||
foreach ($country_module_list_xml->module as $k => $m)
|
foreach ($country_module_list_xml->module as $k => $m)
|
||||||
$country_module_list[] = (string)$m->name;
|
$country_module_list_array[] = (string)$m->name;
|
||||||
$this->tab_modules_list['slider_list'] = array_intersect($this->tab_modules_list['slider_list'], $country_module_list);
|
$this->tab_modules_list['slider_list'] = array_intersect($this->tab_modules_list['slider_list'], $country_module_list_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($this->tab_modules_list['slider_list']) && count($this->tab_modules_list['slider_list']))
|
if (is_array($this->tab_modules_list['slider_list']) && count($this->tab_modules_list['slider_list']))
|
||||||
$this->toolbar_btn['modules-list'] = array(
|
$this->toolbar_btn['modules-list'] = array(
|
||||||
'href' => '#',
|
'href' => '#',
|
||||||
'desc' => $this->l('Modules List')
|
'desc' => $this->l('Modules List')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2946,21 +2945,17 @@ class AdminControllerCore extends Controller
|
|||||||
|
|
||||||
public function isFresh($file, $timeout = 604800000)
|
public function isFresh($file, $timeout = 604800000)
|
||||||
{
|
{
|
||||||
if (file_exists(_PS_ROOT_DIR_.$file))
|
if (file_exists(_PS_ROOT_DIR_.$file) && filesize(_PS_ROOT_DIR_.$file) > 0)
|
||||||
{
|
|
||||||
if (filesize(_PS_ROOT_DIR_.$file) < 1)
|
|
||||||
return false;
|
|
||||||
return ((time() - filemtime(_PS_ROOT_DIR_.$file)) < $timeout);
|
return ((time() - filemtime(_PS_ROOT_DIR_.$file)) < $timeout);
|
||||||
}
|
return false;
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static $is_prestashop_up = true;
|
||||||
public function refresh($file_to_refresh, $external_file)
|
public function refresh($file_to_refresh, $external_file)
|
||||||
{
|
{
|
||||||
$content = Tools::file_get_contents($external_file);
|
if (self::$is_prestashop_up && $content = Tools::file_get_contents($external_file))
|
||||||
if ($content)
|
|
||||||
return (bool)file_put_contents(_PS_ROOT_DIR_.$file_to_refresh, $content);
|
return (bool)file_put_contents(_PS_ROOT_DIR_.$file_to_refresh, $content);
|
||||||
|
self::$is_prestashop_up = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user