[*] Core: you can now pass a query string with php-cli which will merged with for cronjobs and other things

This commit is contained in:
Rémi Gaillard
2013-05-15 14:46:40 +02:00
parent 35463be99a
commit 2c10ba5359
3 changed files with 30 additions and 2 deletions

View File

@@ -2198,6 +2198,27 @@ exit;
return (PHP_INT_MAX == '9223372036854775807');
}
/**
*
* @return bool true if php-cli is used
*/
public static function isPHPCLI()
{
return (defined('STDIN') || (Tools::strtolower(php_sapi_name()) == 'cli' && (!isset($_SERVER['REMOTE_ADDR']) || empty($_SERVER['REMOTE_ADDR']))));
}
public static function argvToGET($argc, $argv)
{
if ($argc <= 1)
return;
// get the first argument and parse it like a query string
parse_str($argv[1], $args);
if (!is_array($args) || !count($args))
return;
$_GET = array_merge($args, $_GET);
}
/**
* Get max file upload size considering server settings and optional max value
*

View File

@@ -349,12 +349,16 @@ class ShopCore extends ObjectModel
}
}
if (!$id_shop && defined('_PS_ADMIN_DIR_'))
if ((!$id_shop && defined('_PS_ADMIN_DIR_')) || Tools::isPHPCLI())
{
// If in admin, we can access to the shop without right URL
$shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
$shop = new Shop((int)Configuration::get('PS_SHOP_DEFAULT'));
$shop->physical_uri = preg_replace('#/+#', '/', str_replace('\\', '/', dirname(dirname($_SERVER['SCRIPT_NAME']))).'/');
$shop->virtual_uri = '';
// Define HTTP_HOST if PHP is launched with php-cli
if (Tools::isPHPCLI() && !isset($_SERVER['HTTP_HOST']) || empty($_SERVER['HTTP_HOST']))
$_SERVER['HTTP_HOST'] = $shop->domain;
}
else
{

View File

@@ -53,6 +53,9 @@ require_once(dirname(__FILE__).'/settings.inc.php');
require_once(dirname(__FILE__).'/autoload.php');
if (Tools::isPHPCLI())
Tools::argvToGET($argc, $argv);
if (_PS_DEBUG_PROFILING_)
{
include_once(_PS_TOOL_DIR_.'profiling/Controller.php');