// Merge -> revision 8984
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8988 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -62,10 +62,6 @@ abstract class CacheCore
|
||||
{
|
||||
}
|
||||
|
||||
protected function __destruct()
|
||||
{
|
||||
}
|
||||
|
||||
protected function isBlacklist($query)
|
||||
{
|
||||
foreach ($this->_blackList AS $find)
|
||||
|
||||
@@ -271,6 +271,8 @@ class LocalizationPackCore
|
||||
$this->_errors[] = Tools::displayError('An error occurred while importing the currency: ').strval($attributes['name']);
|
||||
return false;
|
||||
}
|
||||
|
||||
PaymentModule::addCurrencyPermissions($currency->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -538,5 +538,57 @@ abstract class PaymentModuleCore extends Module
|
||||
return false;
|
||||
return (new Currency($id_currency));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows specified payment modules to be used by a specific currency
|
||||
*
|
||||
* @since 1.4.5
|
||||
* @param int $id_currency
|
||||
* @param array $id_module_list
|
||||
* @return boolean
|
||||
*/
|
||||
public static function addCurrencyPermissions($id_currency, array $id_module_list = array())
|
||||
{
|
||||
$values = '';
|
||||
if (count($id_module_list) == 0)
|
||||
{
|
||||
// fetch all installed module ids
|
||||
$modules = PaymentModuleCore::getInstalledPaymentModules();
|
||||
foreach ($modules as $module)
|
||||
$id_module_list[] = $module['id_module'];
|
||||
}
|
||||
|
||||
foreach ($id_module_list as $id_module)
|
||||
$values .= '('.(int)$id_module.','.(int)$id_currency.'),';
|
||||
|
||||
if (!empty($values))
|
||||
{
|
||||
return Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'module_currency` (`id_module`, `id_currency`)
|
||||
VALUES '.rtrim($values, ',')
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* List all installed and active payment modules
|
||||
* @see Module::getPaymentModules() if you need a list of module related to the user context
|
||||
*
|
||||
* @since 1.4.5
|
||||
* @return array module informations
|
||||
*/
|
||||
public static function getInstalledPaymentModules()
|
||||
{
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT DISTINCT m.`id_module`, h.`id_hook`, m.`name`, hm.`position`
|
||||
FROM `'._DB_PREFIX_.'module` m
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
|
||||
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
|
||||
WHERE h.`name` = \'payment\'
|
||||
AND m.`active` = 1
|
||||
');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -2656,7 +2656,11 @@ class ProductCore extends ObjectModel
|
||||
|
||||
public static function duplicateDownload($id_product_old, $id_product_new)
|
||||
{
|
||||
$resource = Db::getInstance()->ExecuteS('SELECT `display_filename`, `filename`, `date_add`, `date_expiration`, `nb_days_accessible`, `nb_downloadable`, `active`, `is_shareable` FROM `'._DB_PREFIX_.'product_download` WHERE `id_product` = '.(int)($id_product_old));
|
||||
$sql = 'SELECT `display_filename`, `filename`, `date_add`, `date_expiration`, `nb_days_accessible`, `nb_downloadable`, `active`, `is_shareable`
|
||||
FROM `'._DB_PREFIX_.'product_download`
|
||||
WHERE `id_product` = '.(int)$id_product_old;
|
||||
$resource = Db::getInstance()->Execute($sql);
|
||||
|
||||
if (!Db::getInstance()->NumRows())
|
||||
return true;
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_download` (`id_product`, `display_filename`, `filename`, `date_add`, `date_expiration`, `nb_days_accessible`, `nb_downloadable`, `active`, `is_shareable`) VALUES';
|
||||
|
||||
+16
-16
@@ -29,7 +29,7 @@ class ProductDownloadCore extends ObjectModel
|
||||
{
|
||||
/** @var integer Product id which download belongs */
|
||||
public $id_product;
|
||||
|
||||
|
||||
/** @var integer Attribute Product id which download belongs */
|
||||
public $id_product_attribute;
|
||||
|
||||
@@ -38,13 +38,13 @@ class ProductDownloadCore extends ObjectModel
|
||||
|
||||
/** @var string PhysicallyFilename the name of the file on hard disk */
|
||||
public $filename;
|
||||
|
||||
|
||||
/** @var string DateDeposit when the file is upload */
|
||||
public $date_add;
|
||||
|
||||
/** @var string DateExpiration deadline of the file */
|
||||
public $date_expiration;
|
||||
|
||||
|
||||
/** @var string NbDaysAccessible how many days the customer can access to file */
|
||||
public $nb_days_accessible;
|
||||
|
||||
@@ -53,7 +53,7 @@ class ProductDownloadCore extends ObjectModel
|
||||
|
||||
/** @var boolean Active if file is accessible or not */
|
||||
public $active = 1;
|
||||
|
||||
|
||||
/** @var boolean is_shareable indicates whether the product can be shared */
|
||||
public $is_shareable = 0;
|
||||
|
||||
@@ -133,20 +133,20 @@ class ProductDownloadCore extends ObjectModel
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
$date_expiration = $this->date_expiration;
|
||||
if (!$date_expiration)
|
||||
$date_expiration = '0000-00-00 00:00:00';
|
||||
|
||||
if (!$this->date_expiration)
|
||||
$this->date_expiration = '0000-00-00 00:00:00';
|
||||
|
||||
$fields['id_product'] = (int)($this->id_product);
|
||||
$fields['id_product'] = (int)$this->id_product;
|
||||
$fields['id_product_attribute'] = pSQL($this->id_product_attribute);
|
||||
$fields['display_filename'] = pSQL($this->display_filename);
|
||||
$fields['filename'] = pSQL($this->filename);
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_expiration'] = pSQL($this->date_expiration);
|
||||
$fields['nb_days_accessible'] = (int)($this->nb_days_accessible);
|
||||
$fields['nb_downloadable'] = (int)($this->nb_downloadable);
|
||||
$fields['active'] = (int)($this->active);
|
||||
$fields['is_shareable'] = (int)($this->is_shareable);
|
||||
$fields['date_expiration'] = pSQL($date_expiration);
|
||||
$fields['nb_days_accessible'] = (int)$this->nb_days_accessible;
|
||||
$fields['nb_downloadable'] = (int)$this->nb_downloadable;
|
||||
$fields['active'] = (int)$this->active;
|
||||
$fields['is_shareable'] = (int)$this->is_shareable;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ class ProductDownloadCore extends ObjectModel
|
||||
WHERE `id_product_attribute` = '.(int)$id_product_attribute.' AND `active` = 1');
|
||||
return self::$_productIds[$id_product_attribute];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the display filename from a physical filename
|
||||
*
|
||||
@@ -237,7 +237,7 @@ class ProductDownloadCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'product_download`
|
||||
WHERE `id_product` = '.(int)$id_product.' AND `active` = 1');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the display filename from a physical filename
|
||||
*
|
||||
@@ -254,7 +254,7 @@ class ProductDownloadCore extends ObjectModel
|
||||
FROM `'._DB_PREFIX_.'product_download`
|
||||
WHERE `filename` = \''.pSQL($filename).'\'');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the filename from an id_product
|
||||
*
|
||||
|
||||
@@ -466,11 +466,6 @@ class SearchCore
|
||||
// If we find words that need to be indexed, they're added to the word table in the database
|
||||
if (count($pArray))
|
||||
{
|
||||
$list = '';
|
||||
foreach ($pArray AS $word => $weight)
|
||||
$list .= '\''.$word.'\',';
|
||||
$list = rtrim($list, ',');
|
||||
|
||||
$queryArray = array();
|
||||
$queryArray2 = array();
|
||||
foreach ($pArray AS $word => $weight)
|
||||
|
||||
+49
-9
@@ -1206,11 +1206,11 @@ class ToolsCore
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::minifyHTML()
|
||||
*/
|
||||
|
||||
|
||||
public static function minifyHTML($html_content)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
@@ -1237,7 +1237,7 @@ class ToolsCore
|
||||
$b = hexdec(substr($hex, 4, 2));
|
||||
return (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::minifyHTMLpregCallback()
|
||||
*/
|
||||
@@ -1246,7 +1246,7 @@ class ToolsCore
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::minifyHTMLpregCallback($preg_matches);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::packJSinHTML()
|
||||
*/
|
||||
@@ -1255,7 +1255,7 @@ class ToolsCore
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::packJSinHTML($html_content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::packJSinHTMLpregCallback()
|
||||
*/
|
||||
@@ -1285,7 +1285,7 @@ class ToolsCore
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::minifyCSS()
|
||||
*/
|
||||
@@ -1341,7 +1341,7 @@ class ToolsCore
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::cccCss()
|
||||
*/
|
||||
public static function cccCss($css_files)
|
||||
public static function cccCss($css_files)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::cccCss($css_files);
|
||||
@@ -1351,14 +1351,14 @@ class ToolsCore
|
||||
/**
|
||||
* @deprecated as of 1.5 use Media::cccJS()
|
||||
*/
|
||||
public static function cccJS($js_files)
|
||||
public static function cccJS($js_files)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
return Media::cccJS($css_files);
|
||||
}
|
||||
|
||||
private static $_cache_nb_media_servers = null;
|
||||
|
||||
|
||||
public static function getMediaServer($filename)
|
||||
{
|
||||
if (self::$_cache_nb_media_servers === null)
|
||||
@@ -1912,6 +1912,46 @@ FileETag INode MTime Size
|
||||
$result = min($post_max_size, $upload_max_filesize);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* apacheModExists return true if the apache module $name is loaded
|
||||
* @TODO move this method in class Information (when it will exist)
|
||||
*
|
||||
* @param string $name module name
|
||||
* @return boolean true if exists
|
||||
* @since 1.4.5.0
|
||||
*/
|
||||
public static function apacheModExists($name)
|
||||
{
|
||||
if (function_exists('apache_get_modules'))
|
||||
{
|
||||
static $apacheModuleList = null;
|
||||
|
||||
if (!is_array($apacheModuleList))
|
||||
$apacheModuleList = apache_get_modules();
|
||||
|
||||
// we need strpos (example can be evasive20
|
||||
foreach ($apacheModuleList as $module)
|
||||
{
|
||||
if (strpos($module, $name)!==false)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If apache_get_modules does not exists,
|
||||
// one solution should be parsing httpd.conf,
|
||||
// but we could simple parse phpinfo(INFO_MODULES) return string
|
||||
ob_start();
|
||||
phpinfo(INFO_MODULES);
|
||||
$phpinfo = ob_get_contents();
|
||||
ob_end_clean();
|
||||
if (strpos($phpinfo, $module) !== false)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,6 +52,10 @@ class TaxCore extends ObjectModel
|
||||
protected static $_product_country_tax = array();
|
||||
protected static $_product_tax_via_rules = array();
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'objectsNodeName' => 'taxes',
|
||||
);
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -32,13 +32,13 @@
|
||||
class WebserviceOutputBuilderCore
|
||||
{
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var int constant
|
||||
*/
|
||||
const VIEW_LIST = 1;
|
||||
const VIEW_DETAILS = 2;
|
||||
|
||||
protected $wsUrl;
|
||||
|
||||
protected $wsUrl;
|
||||
protected $output;
|
||||
public $objectRender;
|
||||
protected $wsResource;
|
||||
@@ -47,7 +47,7 @@ class WebserviceOutputBuilderCore
|
||||
protected $fieldsToDisplay;
|
||||
protected $specificFields = array();
|
||||
protected $virtualFields = array();
|
||||
|
||||
|
||||
// Header properties
|
||||
protected $headerParams = array(
|
||||
'Access-Time' => 0,
|
||||
@@ -55,22 +55,22 @@ class WebserviceOutputBuilderCore
|
||||
'PSWS-Version' => 0,
|
||||
'Content-Type' => 0,
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* @var string Status header sent at return
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
|
||||
public function __construct($ws_url)
|
||||
{
|
||||
$this->status = $_SERVER['SERVER_PROTOCOL'].' 200 OK';
|
||||
$this->wsUrl = $ws_url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the render object for set the output format.
|
||||
* Set the Content-type for the http header.
|
||||
*
|
||||
*
|
||||
* @param WebserviceOutputInterface $obj_render
|
||||
* @throw WebserviceException if the object render is not an instance of WebserviceOutputInterface
|
||||
* @return $this
|
||||
@@ -79,14 +79,14 @@ class WebserviceOutputBuilderCore
|
||||
{
|
||||
if (!$obj_render instanceof WebserviceOutputInterface)
|
||||
throw new WebserviceException('Obj_render param must be an WebserviceOutputInterface object type', array(83, 500));
|
||||
|
||||
|
||||
$this->objectRender = $obj_render;
|
||||
$this->objectRender->setWsUrl($this->wsUrl);
|
||||
if ($this->objectRender->getContentType())
|
||||
$this->setHeaderParams('Content-Type', $this->objectRender->getContentType());
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getter
|
||||
* @return WebserviceOutputInterface
|
||||
@@ -94,12 +94,12 @@ class WebserviceOutputBuilderCore
|
||||
public function getObjectRender()
|
||||
{
|
||||
return $this->objectRender;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Need to have the resource list to get the class name for an entity,
|
||||
* To build
|
||||
*
|
||||
* To build
|
||||
*
|
||||
* @param array $resources
|
||||
* @return $this
|
||||
*/
|
||||
@@ -108,13 +108,13 @@ class WebserviceOutputBuilderCore
|
||||
$this->wsResource = $resources;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method return an array with each http header params for a content.
|
||||
* This check each required params.
|
||||
*
|
||||
*
|
||||
* If this method is overrided don't forget to check required specific params (for xml etc...)
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function buildHeader()
|
||||
@@ -127,7 +127,7 @@ class WebserviceOutputBuilderCore
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $key The normalized key expected for an http response
|
||||
* @param $value
|
||||
@@ -142,7 +142,7 @@ class WebserviceOutputBuilderCore
|
||||
$this->headerParams[$key] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null|string $key if null get all header params otherwise the params specified by the key
|
||||
* @throw WebserviceException if the key is corrupted (use Validate::isCleanHtml method)
|
||||
@@ -152,10 +152,10 @@ class WebserviceOutputBuilderCore
|
||||
public function getHeaderParams($key = null)
|
||||
{
|
||||
$return = '';
|
||||
|
||||
|
||||
if (!is_null($key))
|
||||
{
|
||||
if (!is_null($key) && Validate::isCleanHtml($key))
|
||||
if (!Validate::isCleanHtml($key))
|
||||
throw new WebserviceException('the key you write is a corrupted text.', array(95, 500));
|
||||
if (!array_key_exists($key, $this->headerParams))
|
||||
throw new WebserviceException(sprintf('The key %s does\'nt exist', $key), array(96, 500));
|
||||
@@ -163,13 +163,13 @@ class WebserviceOutputBuilderCore
|
||||
}
|
||||
else
|
||||
$return = $this->headerParams;
|
||||
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete all Header parameters previously set.
|
||||
*
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function resetHeaderParams()
|
||||
@@ -177,7 +177,7 @@ class WebserviceOutputBuilderCore
|
||||
$this->headerParams = array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string the normalized status for http request
|
||||
*/
|
||||
@@ -233,10 +233,10 @@ class WebserviceOutputBuilderCore
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build errors output using an error array
|
||||
*
|
||||
*
|
||||
* @param array $errors
|
||||
* @return string output in the format specified by WebserviceOutputBuilder::objectRender
|
||||
*/
|
||||
@@ -264,7 +264,7 @@ class WebserviceOutputBuilderCore
|
||||
}
|
||||
return $str_output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the resource list in the output format specified by WebserviceOutputBuilder::objectRender
|
||||
* @param $key_permissions
|
||||
@@ -290,11 +290,11 @@ class WebserviceOutputBuilderCore
|
||||
'head' => (in_array('HEAD', $key_permissions[$resourceName]) ? 'true' : 'false'),
|
||||
);
|
||||
$output .= $this->objectRender->renderNodeHeader($resourceName, array(), $more_attr);
|
||||
|
||||
|
||||
$output .= $this->objectRender->renderNodeHeader('description', array(), $more_attr);
|
||||
$output .= $resource['description'];
|
||||
$output .= $this->objectRender->renderNodeFooter('description', array());
|
||||
|
||||
|
||||
if (!isset($resource['specific_management']) || !$resource['specific_management'])
|
||||
{
|
||||
$more_attr_schema = array(
|
||||
@@ -322,8 +322,8 @@ class WebserviceOutputBuilderCore
|
||||
* - list of entities,
|
||||
* - tree diagram of entity details (full or minimum),
|
||||
* - schema (synopsis & blank),
|
||||
*
|
||||
* @param array $objects each object created by entity asked
|
||||
*
|
||||
* @param array $objects each object created by entity asked
|
||||
* @see WebserviceOutputBuilder::executeEntityGetAndHead
|
||||
* @param null|string $schema_to_display if null display the entities list or entity details.
|
||||
* @param string|array $fields_to_display the fields allow for the output
|
||||
@@ -336,22 +336,22 @@ class WebserviceOutputBuilderCore
|
||||
$this->fieldsToDisplay = $fields_to_display;
|
||||
$this->depth = $depth;
|
||||
$output = '';
|
||||
|
||||
|
||||
if ($schema_to_display != null)
|
||||
{
|
||||
$this->schemaToDisplay = $schema_to_display;
|
||||
$this->objectRender->setSchemaToDisplay($this->schemaToDisplay);
|
||||
|
||||
// If a shema is asked the view must be an details type
|
||||
|
||||
// If a shema is asked the view must be an details type
|
||||
$type_of_view = self::VIEW_DETAILS;
|
||||
}
|
||||
|
||||
|
||||
$ws_params = $objects['empty']->getWebserviceParameters();
|
||||
|
||||
|
||||
// If a list is asked, need to wrap with a plural node
|
||||
if ($type_of_view === self::VIEW_LIST)
|
||||
$output .= $this->setIndent($depth).$this->objectRender->renderNodeHeader($ws_params['objectsNodeName'], $ws_params);
|
||||
|
||||
|
||||
if (is_null($this->schemaToDisplay))
|
||||
{
|
||||
foreach ($objects as $key => $object)
|
||||
@@ -369,11 +369,11 @@ class WebserviceOutputBuilderCore
|
||||
{
|
||||
$output .= $this->renderSchema($objects['empty'], $ws_params);
|
||||
}
|
||||
|
||||
|
||||
// If a list is asked, need to wrap with a plural node
|
||||
if ($type_of_view === self::VIEW_LIST)
|
||||
$output .= $this->setIndent($depth).$this->objectRender->renderNodeFooter($ws_params['objectsNodeName'], $ws_params);
|
||||
|
||||
|
||||
if ($override)
|
||||
$output = $this->objectRender->overrideContent($output);
|
||||
return $output;
|
||||
@@ -381,7 +381,7 @@ class WebserviceOutputBuilderCore
|
||||
|
||||
/**
|
||||
* Create the tree diagram with no details
|
||||
*
|
||||
*
|
||||
* @param $object create by the entity
|
||||
* @param $depth the depth for the tree diagram
|
||||
* @return string
|
||||
@@ -397,7 +397,7 @@ class WebserviceOutputBuilderCore
|
||||
|
||||
/**
|
||||
* Build a schema blank or synopsis
|
||||
*
|
||||
*
|
||||
* @param $object create by the entity
|
||||
* @param $ws_params webserviceParams from the entity
|
||||
* @return string
|
||||
@@ -420,7 +420,7 @@ class WebserviceOutputBuilderCore
|
||||
|
||||
/**
|
||||
* Build the entity detail.
|
||||
*
|
||||
*
|
||||
* @param ObjectModel $object create by the entity
|
||||
* @param int $depth the depth for the tree diagram
|
||||
* @return string
|
||||
@@ -430,14 +430,14 @@ class WebserviceOutputBuilderCore
|
||||
$output = '';
|
||||
$ws_params = $object->getWebserviceParameters();
|
||||
$output .= $this->setIndent($depth).$this->objectRender->renderNodeHeader($ws_params['objectNodeName'], $ws_params);
|
||||
|
||||
|
||||
if ($object->id != 0)
|
||||
{
|
||||
// This to add virtual Fields for a particular entity.
|
||||
$virtual_fields = $this->addVirtualFields($ws_params['objectsNodeName'], $object);
|
||||
if (!empty($virtual_fields))
|
||||
$ws_params['fields'] = array_merge($ws_params['fields'], $virtual_fields);
|
||||
|
||||
|
||||
foreach ($ws_params['fields'] as $field_name => $field)
|
||||
{
|
||||
if ($this->fieldsToDisplay === 'full' || array_key_exists($field_name, $this->fieldsToDisplay))
|
||||
@@ -468,7 +468,7 @@ class WebserviceOutputBuilderCore
|
||||
|
||||
/**
|
||||
* Build a field and use recursivity depend on the depth parameter.
|
||||
*
|
||||
*
|
||||
* @param ObjectModel $object create by the entity
|
||||
* @param array $ws_params webserviceParams from the entity
|
||||
* @param string $field_name
|
||||
@@ -480,7 +480,7 @@ class WebserviceOutputBuilderCore
|
||||
{
|
||||
$output = '';
|
||||
$show_field = true;
|
||||
|
||||
|
||||
if (isset($ws_params['hidden_fields']) && in_array($field_name, $ws_params['hidden_fields']))
|
||||
return;
|
||||
|
||||
@@ -489,9 +489,10 @@ class WebserviceOutputBuilderCore
|
||||
$field['synopsis_details'] = $this->getSynopsisDetails($field);
|
||||
if ($field_name === 'id')
|
||||
$show_field = false;
|
||||
elseif (isset($field['setter']) && !$field['setter'])
|
||||
$show_field = false;
|
||||
}
|
||||
else if ($this->schemaToDisplay === 'blank')
|
||||
if (isset($field['setter']) && !$field['setter'])
|
||||
$show_field = false;
|
||||
|
||||
// don't set any value for a schema
|
||||
if (isset($field['synopsis_details']) || $this->schemaToDisplay === 'blank')
|
||||
@@ -504,10 +505,10 @@ class WebserviceOutputBuilderCore
|
||||
$field['value'] = $object->$field['getter']();
|
||||
elseif (!isset($field['value']))
|
||||
$field['value'] = $object->$field_name;
|
||||
|
||||
|
||||
// this apply specific function for a particular field on a choosen entity
|
||||
$field = $this->overrideSpecificField($ws_params['objectsNodeName'], $field_name, $field, $object, $ws_params);
|
||||
|
||||
|
||||
// don't display informations for a not existant id
|
||||
if (substr($field['sqlId'], 0, 3) == 'id_' && $field['value'] == 0)
|
||||
{
|
||||
@@ -519,8 +520,8 @@ class WebserviceOutputBuilderCore
|
||||
// set "id" for each node name which display the id of the entity
|
||||
if ($field_name === 'id')
|
||||
$field['sqlId'] = 'id';
|
||||
|
||||
|
||||
|
||||
|
||||
// don't display the node id for a synopsis schema
|
||||
if ($show_field)
|
||||
$output .= $this->setIndent($depth-1).$this->objectRender->renderField($field);
|
||||
@@ -528,8 +529,8 @@ class WebserviceOutputBuilderCore
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param $object
|
||||
* @param $depth
|
||||
* @param $associations
|
||||
@@ -545,17 +546,17 @@ class WebserviceOutputBuilderCore
|
||||
{
|
||||
$getter = $association['getter'];
|
||||
$objects_assoc = array();
|
||||
|
||||
|
||||
$fields_assoc = array();
|
||||
if (isset($association['fields']))
|
||||
$fields_assoc = $association['fields'];
|
||||
|
||||
$fields_assoc = $association['fields'];
|
||||
|
||||
$parent_details = array(
|
||||
'object_id' => $object->id,
|
||||
'entity_name' => $ws_params['objectNodeName'],
|
||||
'entities_name' => $ws_params['objectsNodeName'],
|
||||
);
|
||||
|
||||
|
||||
if (method_exists($object, $getter) && is_null($this->schemaToDisplay))
|
||||
{
|
||||
$association_resources = $object->$getter();
|
||||
@@ -571,7 +572,7 @@ class WebserviceOutputBuilderCore
|
||||
{
|
||||
$objects_assoc[] = '';
|
||||
}
|
||||
|
||||
|
||||
$class_name = null;
|
||||
if (isset($this->wsResource[$assoc_name]['class']) && class_exists($this->wsResource[$assoc_name]['class'], true))
|
||||
$class_name = $this->wsResource[$assoc_name]['class'];
|
||||
@@ -614,7 +615,7 @@ class WebserviceOutputBuilderCore
|
||||
$output .= $this->objectRender->renderAssociationWrapperFooter();
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
private function renderFlatAssociation($object, $depth, $assoc_name, $resource_name, $fields_assoc, $object_assoc, $parent_details)
|
||||
{
|
||||
$output = '';
|
||||
@@ -627,7 +628,7 @@ class WebserviceOutputBuilderCore
|
||||
$more_attr['xlink_resource'] = $this->wsUrl.$assoc_name.'/'.$object_assoc['id'];
|
||||
}
|
||||
$output .= $this->setIndent($depth-1).$this->objectRender->renderNodeHeader($resource_name, array(), $more_attr);
|
||||
|
||||
|
||||
foreach ($fields_assoc as $field_name=>$field)
|
||||
{
|
||||
if (!is_array($this->fieldsToDisplay) || in_array($field_name, $this->fieldsToDisplay[$assoc_name]))
|
||||
@@ -644,17 +645,17 @@ class WebserviceOutputBuilderCore
|
||||
}
|
||||
$field['entities_name'] = $assoc_name;
|
||||
$field['entity_name'] = $resource_name;
|
||||
|
||||
|
||||
if (!is_null($this->schemaToDisplay))
|
||||
$field['synopsis_details'] = $this->getSynopsisDetails($field);
|
||||
|
||||
|
||||
$output .= $this->setIndent($depth-1).$this->objectRender->renderField($field);
|
||||
}
|
||||
}
|
||||
$output .= $this->setIndent($depth-1).$this->objectRender->renderNodeFooter($resource_name, array());
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
public function setIndent($depth)
|
||||
{
|
||||
$string = '';
|
||||
@@ -663,7 +664,7 @@ class WebserviceOutputBuilderCore
|
||||
$string .= "\t";
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
public function getSynopsisDetails($field)
|
||||
{
|
||||
$arr_details = '';
|
||||
@@ -675,9 +676,9 @@ class WebserviceOutputBuilderCore
|
||||
$arr_details['format'] = $field['validateMethod'];
|
||||
return $arr_details;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string|object $object
|
||||
* @param string $method
|
||||
* @return $this
|
||||
@@ -689,9 +690,9 @@ class WebserviceOutputBuilderCore
|
||||
} catch (WebserviceException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
$this->specificFields[$field_name] = array('entity'=>$entity_name, 'object' => $object, 'method' => $method, 'type' => gettype($object));
|
||||
return $this;
|
||||
return $this;
|
||||
}
|
||||
private function validateObjectAndMethod($object, $method)
|
||||
{
|
||||
@@ -712,7 +713,7 @@ class WebserviceOutputBuilderCore
|
||||
$object = new $this->specificFields[$field_name]['object']();
|
||||
elseif ($this->specificFields[$field_name]['type'] == 'object')
|
||||
$object= $this->specificFields[$field_name]['object'];
|
||||
|
||||
|
||||
$field = $object->{$this->specificFields[$field_name]['method']}($field, $entity_object, $ws_params);
|
||||
}
|
||||
return $field;
|
||||
@@ -724,7 +725,7 @@ class WebserviceOutputBuilderCore
|
||||
} catch (WebserviceException $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
$this->virtualFields[$entity_name][] = array('parameters' => $parameters, 'object' => $object, 'method' => $method, 'type' => gettype($object));
|
||||
}
|
||||
public function getVirtualFields()
|
||||
@@ -743,7 +744,7 @@ class WebserviceOutputBuilderCore
|
||||
$object = new $function_infos['object']();
|
||||
elseif ($function_infos['type'] == 'object')
|
||||
$object= $function_infos['object'];
|
||||
|
||||
|
||||
$return_fields = $object->{$function_infos['method']}($entity_object, $function_infos['parameters']);
|
||||
foreach ($return_fields as $field_name => $value)
|
||||
{
|
||||
@@ -756,7 +757,7 @@ class WebserviceOutputBuilderCore
|
||||
}
|
||||
return $arr_return;
|
||||
}
|
||||
|
||||
|
||||
public function setFieldsToDisplay($fields)
|
||||
{
|
||||
$this->fieldsToDisplay = $fields;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2010 PrestaShop
|
||||
* 2007-2010 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -28,173 +28,173 @@
|
||||
class WebserviceRequestCore
|
||||
{
|
||||
protected $_available_languages = null;
|
||||
/**
|
||||
/**
|
||||
* Errors triggered at execution
|
||||
* @var array
|
||||
*/
|
||||
public $errors = array();
|
||||
|
||||
|
||||
/**
|
||||
* Set if return should display content or not
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_outputEnabled = true;
|
||||
|
||||
|
||||
/**
|
||||
* Set if the management is specific or if it is classic (entity management)
|
||||
* @var boolean
|
||||
*/
|
||||
protected $objectSpecificManagement = false;
|
||||
|
||||
|
||||
/**
|
||||
* Base PrestaShop webservice URL
|
||||
* @var string
|
||||
*/
|
||||
public $wsUrl;
|
||||
|
||||
|
||||
/**
|
||||
* PrestaShop Webservice Documentation URL
|
||||
* @var string
|
||||
* @var string
|
||||
*/
|
||||
protected $_docUrl = 'http://prestashop.com/docs/1.4/webservice';
|
||||
|
||||
|
||||
/**
|
||||
* Set if the authentication key was checked
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_authenticated = false;
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Method to support
|
||||
* @var string
|
||||
*/
|
||||
public $method;
|
||||
|
||||
|
||||
/**
|
||||
* The segment of the URL
|
||||
* @var array
|
||||
*/
|
||||
public $urlSegment = array();
|
||||
|
||||
|
||||
/**
|
||||
* The segment list of the URL after the "api" segment
|
||||
* @var array
|
||||
*/
|
||||
public $urlFragments = array();
|
||||
|
||||
|
||||
/**
|
||||
* The time in microseconds of the start of the execution of the web service request
|
||||
* @var int
|
||||
*/
|
||||
protected $_startTime = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The list of each resources manageable via web service
|
||||
* @var array
|
||||
*/
|
||||
public $resourceList;
|
||||
|
||||
|
||||
/**
|
||||
* The configuration parameters of the current resource
|
||||
* @var array
|
||||
*/
|
||||
public $resourceConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
* The permissions for the current key
|
||||
* @var array
|
||||
*/
|
||||
public $keyPermissions;
|
||||
|
||||
|
||||
/**
|
||||
* The XML string to display if web service call succeed
|
||||
* @var string
|
||||
*/
|
||||
protected $specificOutput = '';
|
||||
|
||||
|
||||
/**
|
||||
* The list of objects to display
|
||||
* @var array
|
||||
*/
|
||||
public $objects;
|
||||
|
||||
|
||||
/**
|
||||
* The current object to support, it extends the PrestaShop ObjectModel
|
||||
* @var ObjectModel
|
||||
*/
|
||||
protected $_object;
|
||||
|
||||
|
||||
/**
|
||||
* The schema to display.
|
||||
* The schema to display.
|
||||
* If null, no schema have to be displayed and normal management has to be performed
|
||||
* @var string
|
||||
* @var string
|
||||
*/
|
||||
public $schemaToDisplay;
|
||||
|
||||
|
||||
/**
|
||||
* The fields to display. These fields will be displayed when retrieving objects
|
||||
* @var string
|
||||
*/
|
||||
public $fieldsToDisplay = 'minimum';
|
||||
|
||||
|
||||
/**
|
||||
* If we are in PUT or POST case, we use this attribute to store the xml string value during process
|
||||
* @var string
|
||||
*/
|
||||
protected $_inputXml;
|
||||
|
||||
|
||||
/**
|
||||
* Object instance for singleton
|
||||
* @var WebserviceRequest
|
||||
*/
|
||||
protected static $_instance;
|
||||
|
||||
|
||||
/**
|
||||
* Key used for authentication
|
||||
* @var string
|
||||
*/
|
||||
protected $_key;
|
||||
|
||||
|
||||
/**
|
||||
* This is used to have a deeper tree diagram.
|
||||
* @var int
|
||||
*/
|
||||
public $depth = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the output format
|
||||
* @var string
|
||||
*/
|
||||
protected $outputFormat = 'xml';
|
||||
|
||||
|
||||
/**
|
||||
* The object to build the output.
|
||||
* @var WebserviceOutputBuilder
|
||||
*/
|
||||
protected $objOutput;
|
||||
|
||||
|
||||
/**
|
||||
* Save the class name for override used in getInstance()
|
||||
* @var ws_current_classname
|
||||
*/
|
||||
public static $ws_current_classname;
|
||||
|
||||
|
||||
|
||||
|
||||
public static $shopIDs;
|
||||
|
||||
|
||||
|
||||
public function getOutputEnabled()
|
||||
{
|
||||
return $this->_outputEnabled;
|
||||
}
|
||||
|
||||
|
||||
public function setOutputEnabled($bool)
|
||||
{
|
||||
if (Validate::isBool($bool))
|
||||
$this->_outputEnabled = $bool;
|
||||
$this->_outputEnabled = $bool;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get WebserviceRequest object instance (Singleton)
|
||||
*
|
||||
@@ -206,7 +206,7 @@ class WebserviceRequestCore
|
||||
self::$_instance = new WebserviceRequest::$ws_current_classname();
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
|
||||
protected function getOutputObject($type)
|
||||
{
|
||||
switch ($type)
|
||||
@@ -218,7 +218,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
return $obj_render;
|
||||
}
|
||||
|
||||
|
||||
public static function getResources()
|
||||
{
|
||||
$resources = array(
|
||||
@@ -262,16 +262,17 @@ class WebserviceRequestCore
|
||||
'stock_movement_reasons' => array('description' => 'The stock movement reason', 'class' => 'StockMvtReason'),
|
||||
'shops' => array('description' => 'Shops from multi-shop feature', 'class' => 'Shop'),
|
||||
'shop_groups' => array('description' => 'Shop groups from multi-shop feature', 'class' => 'GroupShop'),
|
||||
'taxes' => array('description' => 'The tax rate', 'class' => 'Tax'),
|
||||
);
|
||||
ksort($resources);
|
||||
return $resources;
|
||||
}
|
||||
|
||||
|
||||
// @todo Check how get parameters
|
||||
// @todo : set this method out
|
||||
/**
|
||||
* This method is used for calculate the price for products on the output details
|
||||
*
|
||||
*
|
||||
* @param $field
|
||||
* @param $entity_object
|
||||
* @param $ws_params
|
||||
@@ -286,11 +287,11 @@ class WebserviceRequestCore
|
||||
}
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
||||
// @todo : set this method out
|
||||
/**
|
||||
* This method is used for calculate the price for products on a virtual fields
|
||||
*
|
||||
*
|
||||
* @param $entity_object
|
||||
* @param array $parameters
|
||||
* @return array
|
||||
@@ -318,12 +319,12 @@ class WebserviceRequestCore
|
||||
$decimals = (isset($value['decimals']) ? $value['decimals'] : Configuration::get('PS_PRICE_ROUND_MODE'));
|
||||
$id_product_attribute = (isset($value['product_attribute']) ? $value['product_attribute'] : null);
|
||||
$id_county = (isset($value['county']) ? $value['county'] : null);
|
||||
|
||||
|
||||
$only_reduc = (isset($value['only_reduction']) ? $value['only_reduction'] : false);
|
||||
$use_reduc = (isset($value['use_reduction']) ? $value['use_reduction'] : true);
|
||||
$use_ecotax = (isset($value['use_ecotax']) ? $value['use_ecotax'] : Configuration::get('PS_USE_ECOTAX'));
|
||||
$specific_price_output = null;
|
||||
$return_value = Product::priceCalculation(null, $value['object_id'], $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity,
|
||||
$return_value = Product::priceCalculation(null, $value['object_id'], $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity,
|
||||
$use_tax, $decimals, $only_reduc, $use_reduc, $use_ecotax, $specific_price_output, null);
|
||||
$arr_return[$name] = array('sqlId'=>strtolower($name), 'value'=>$return_value);
|
||||
}
|
||||
@@ -332,7 +333,7 @@ class WebserviceRequestCore
|
||||
// @todo : set this method out
|
||||
/**
|
||||
* This method is used for calculate the price for products on a virtual fields
|
||||
*
|
||||
*
|
||||
* @param $entity_object
|
||||
* @param array $parameters
|
||||
* @return array
|
||||
@@ -347,7 +348,7 @@ class WebserviceRequestCore
|
||||
$arr_return = $this->specificPriceCalculation($parameters);
|
||||
return $arr_return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start Webservice request
|
||||
* Check webservice activation
|
||||
@@ -356,7 +357,7 @@ class WebserviceRequestCore
|
||||
* Check HTTP Method
|
||||
* Execute the action
|
||||
* Display the result
|
||||
*
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $method
|
||||
* @param string $url
|
||||
@@ -370,7 +371,7 @@ class WebserviceRequestCore
|
||||
// Time logger
|
||||
$this->_startTime = microtime(true);
|
||||
$this->objects = array();
|
||||
|
||||
|
||||
// Two global vars, for compatibility with the PS core...
|
||||
global $webservice_call, $display_errors;
|
||||
$webservice_call = true;
|
||||
@@ -379,13 +380,13 @@ class WebserviceRequestCore
|
||||
$this->wsUrl = Tools::getHttpHost(true).__PS_BASE_URI__;
|
||||
// set the output object which manage the content and header structure and informations
|
||||
$this->objOutput = new WebserviceOutputBuilder($this->wsUrl);
|
||||
|
||||
|
||||
// Error handler
|
||||
set_error_handler(array($this, 'webserviceErrorHandler'));
|
||||
ini_set('html_errors', 'off');
|
||||
|
||||
|
||||
$this->_key = trim($key);
|
||||
|
||||
|
||||
$this->outputFormat = isset($params['output_format']) ? $params['output_format'] : $this->outputFormat;
|
||||
// Set the render object to build the output on the asked format (XML, JSON, CSV, ...)
|
||||
$this->objOutput->setObjectRender($this->getOutputObject($this->outputFormat));
|
||||
@@ -400,8 +401,8 @@ class WebserviceRequestCore
|
||||
$this->urlFragments = $params;
|
||||
$this->_inputXml = $inputXml;
|
||||
$this->depth = isset($this->urlFragments['depth']) ? (int)$this->urlFragments['depth'] : $this->depth;
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
// Method below set a particular fonction to use on the price field for products entity
|
||||
// @see WebserviceRequest::getPriceForProduct() method
|
||||
@@ -415,7 +416,7 @@ class WebserviceRequestCore
|
||||
} catch (Exception $e) {
|
||||
$this->setError(500, $e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
|
||||
if (isset($this->urlFragments['language']))
|
||||
$this->_available_languages = $this->filterLanguage();
|
||||
else
|
||||
@@ -423,25 +424,25 @@ class WebserviceRequestCore
|
||||
foreach (Language::getLanguages() as $key=>$language)
|
||||
$this->_available_languages[] = $language['id_lang'];
|
||||
}
|
||||
|
||||
|
||||
if (empty($this->_available_languages))
|
||||
$this->setError(400, 'language is not available', 81);
|
||||
|
||||
|
||||
// Need to set available languages for the render object.
|
||||
// Thus we can filter i18n field for the output
|
||||
// @see WebserviceOutputXML::renderField() method for example
|
||||
$this->objOutput->objectRender->setLanguages($this->_available_languages);
|
||||
|
||||
|
||||
// check method and resource
|
||||
if (empty($this->errors) && $this->checkResource() && $this->checkHTTPMethod())
|
||||
{
|
||||
// The resource list is necessary for build the output
|
||||
$this->objOutput->setWsResources($this->resourceList);
|
||||
|
||||
|
||||
// if the resource is a core entity...
|
||||
if (!isset($this->resourceList[$this->urlSegment[0]]['specific_management']) || !$this->resourceList[$this->urlSegment[0]]['specific_management'])
|
||||
{
|
||||
|
||||
|
||||
// load resource configuration
|
||||
if ($this->urlSegment[0] != '')
|
||||
{
|
||||
@@ -472,7 +473,7 @@ class WebserviceRequestCore
|
||||
$this->executeEntityDelete();
|
||||
break;
|
||||
}
|
||||
// Need to set an object for the WebserviceOutputBuilder object in any case
|
||||
// Need to set an object for the WebserviceOutputBuilder object in any case
|
||||
// because schema need to get webserviceParameters of this object
|
||||
if (isset($object))
|
||||
$this->objects['empty'] = $object;
|
||||
@@ -489,7 +490,7 @@ class WebserviceRequestCore
|
||||
$this->objectSpecificManagement = new $specificObjectName();
|
||||
$this->objectSpecificManagement->setObjectOutput($this->objOutput)
|
||||
->setWsObject($this);
|
||||
|
||||
|
||||
try {
|
||||
$this->objectSpecificManagement->manage();
|
||||
} catch (WebserviceException $e) {
|
||||
@@ -506,8 +507,8 @@ class WebserviceRequestCore
|
||||
unset($webservice_call);
|
||||
unset ($display_errors);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set a webservice error
|
||||
*
|
||||
@@ -522,7 +523,7 @@ class WebserviceRequestCore
|
||||
$this->objOutput->setStatus($status);
|
||||
$this->errors[] = $display_errors ? array($code, $label) : 'Internal error. To see this error please display the PHP errors.';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set a webservice error and propose a new value near from the available values
|
||||
*
|
||||
@@ -537,7 +538,7 @@ class WebserviceRequestCore
|
||||
{
|
||||
$this->setError($num, $label.'. Did you mean: "'.$this->getClosest($value, $available_values).'"?'.(count($available_values) > 1 ? ' The full list is: "'.implode('", "', $available_values).'"' : ''), $code);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the nearest value picked in the values list
|
||||
*
|
||||
@@ -565,9 +566,9 @@ class WebserviceRequestCore
|
||||
}
|
||||
return $closest;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to replace the default PHP error handler, in order to display PHP errors in a XML format
|
||||
* Used to replace the default PHP error handler, in order to display PHP errors in a XML format
|
||||
*
|
||||
* @param string $errno contains the level of the error raised, as an integer
|
||||
* @param array $errstr contains the error message, as a string
|
||||
@@ -579,7 +580,7 @@ class WebserviceRequestCore
|
||||
{
|
||||
if (!(error_reporting() & $errno))
|
||||
return;
|
||||
|
||||
|
||||
switch($errno)
|
||||
{
|
||||
case E_ERROR:
|
||||
@@ -626,7 +627,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if there is one or more error
|
||||
*
|
||||
@@ -636,7 +637,7 @@ class WebserviceRequestCore
|
||||
{
|
||||
return (boolean)$this->errors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check request authentication
|
||||
*
|
||||
@@ -675,7 +676,7 @@ class WebserviceRequestCore
|
||||
{
|
||||
$this->setError(401, 'Authentification key is not active', 20);
|
||||
}
|
||||
|
||||
|
||||
if (!$this->keyPermissions)
|
||||
{
|
||||
$this->setError(401, 'No permission for this authentication key', 21);
|
||||
@@ -696,7 +697,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check webservice activation
|
||||
*
|
||||
@@ -711,7 +712,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected function shopHasRight($key)
|
||||
{
|
||||
$sql = 'SELECT 1
|
||||
@@ -727,7 +728,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected function shopExists($params)
|
||||
{
|
||||
// Case no shop specified
|
||||
@@ -736,7 +737,7 @@ class WebserviceRequestCore
|
||||
self::$shopIDs[] = Configuration::get('PS_SHOP_DEFAULT');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if ($params['id_shop'][0] == '[' && $params['id_shop'][strlen($params['id_shop']) - 1] == ']')
|
||||
$shops = explode(',', substr($params['id_shop'], 1, strlen($params['id_shop']) - 2));
|
||||
else
|
||||
@@ -767,7 +768,7 @@ class WebserviceRequestCore
|
||||
$this->setError(404, 'This shop id doesn\'t exist', 129);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check HTTP method
|
||||
*
|
||||
@@ -785,7 +786,7 @@ class WebserviceRequestCore
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check resource validity
|
||||
*
|
||||
@@ -812,8 +813,8 @@ class WebserviceRequestCore
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected function setObjects()
|
||||
{
|
||||
$objects = array();
|
||||
@@ -840,18 +841,18 @@ class WebserviceRequestCore
|
||||
$objects[] = $object;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($arr_avoid_id) || empty($ids))
|
||||
{
|
||||
$this->setError(404, 'Id(s) not exists: '.implode(', ', $arr_avoid_id), 87);
|
||||
$this->_outputEnabled = true;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function parseDisplayFields($str)
|
||||
{
|
||||
$bracket_level = 0;
|
||||
@@ -891,7 +892,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
public function setFieldsToDisplay()
|
||||
{
|
||||
// set the fields to display in the list : "full", "minimum", "field_1", "field_1,field_2,field_3"
|
||||
@@ -943,7 +944,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected function manageFilters()
|
||||
{
|
||||
// filtered fields which can not use filters : hidden_fields
|
||||
@@ -953,12 +954,12 @@ class WebserviceRequestCore
|
||||
foreach ($this->resourceConfiguration['fields'] as $fieldName => $field)
|
||||
if ((!isset($this->resourceConfiguration['hidden_fields']) ||
|
||||
(isset($this->resourceConfiguration['hidden_fields']) && !in_array($fieldName, $this->resourceConfiguration['hidden_fields']))))
|
||||
if ((!isset($field['i18n']) ||
|
||||
if ((!isset($field['i18n']) ||
|
||||
(isset($field['i18n']) && !$field['i18n'])))
|
||||
$available_filters[] = $fieldName;
|
||||
else
|
||||
$i18n_available_filters[] = $fieldName;
|
||||
|
||||
|
||||
// Date feature : date=1
|
||||
if (!empty($this->urlFragments['date']) && $this->urlFragments['date'])
|
||||
{
|
||||
@@ -1011,7 +1012,7 @@ class WebserviceRequestCore
|
||||
{
|
||||
// contruct SQL join for linked tables
|
||||
$sql_join .= 'LEFT JOIN `'._DB_PREFIX_.pSQL($this->resourceConfiguration['linked_tables'][$field]['table']).'` '.pSQL($field).' ON (main.`'.pSQL($this->resourceConfiguration['fields']['id']['sqlId']).'` = '.pSQL($field).'.`'.pSQL($this->resourceConfiguration['fields']['id']['sqlId']).'`)'."\n";
|
||||
|
||||
|
||||
// construct SQL filter for linked tables
|
||||
foreach ($url_param as $field2 => $value)
|
||||
{
|
||||
@@ -1081,7 +1082,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$this->setFieldsToDisplay())
|
||||
return false;
|
||||
// construct SQL Sort
|
||||
@@ -1093,7 +1094,7 @@ class WebserviceRequestCore
|
||||
$sorts = explode(',', $matches[1]);
|
||||
else
|
||||
$sorts = array($this->urlFragments['sort']);
|
||||
|
||||
|
||||
$sql_sort .= ' ORDER BY ';
|
||||
foreach ($sorts as $sort)
|
||||
{
|
||||
@@ -1147,12 +1148,12 @@ class WebserviceRequestCore
|
||||
$filters['sql_filter'] = $sql_filter;
|
||||
$filters['sql_sort'] = $sql_sort;
|
||||
$filters['sql_limit'] = $sql_limit;
|
||||
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function getFilteredObjectList()
|
||||
{
|
||||
$objects = array();
|
||||
@@ -1162,7 +1163,7 @@ class WebserviceRequestCore
|
||||
$this->resourceConfiguration['retrieveData']['params'][] = $filters['sql_sort'];
|
||||
$this->resourceConfiguration['retrieveData']['params'][] = $filters['sql_limit'];
|
||||
//list entities
|
||||
|
||||
|
||||
$tmp = new $this->resourceConfiguration['retrieveData']['className']();
|
||||
$sqlObjects = call_user_func_array(array($tmp, $this->resourceConfiguration['retrieveData']['retrieveMethod']), $this->resourceConfiguration['retrieveData']['params']);
|
||||
if ($sqlObjects)
|
||||
@@ -1174,13 +1175,13 @@ class WebserviceRequestCore
|
||||
return $objects;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getFilteredObjectDetails()
|
||||
{
|
||||
$objects = array();
|
||||
if (!isset($this->urlFragments['display']))
|
||||
if (!isset($this->urlFragments['display']))
|
||||
$this->fieldsToDisplay = 'full';
|
||||
|
||||
|
||||
// Check if Object is accessible for this/those id_shop
|
||||
$assoc = Shop::getAssoTables();
|
||||
if (array_key_exists($this->resourceConfiguration['retrieveData']['table'] ,$assoc))
|
||||
@@ -1207,15 +1208,15 @@ class WebserviceRequestCore
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute GET and HEAD requests
|
||||
*
|
||||
*
|
||||
* Build filter
|
||||
* Build fields display
|
||||
* Build sort
|
||||
* Build limit
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function executeEntityGetAndHead()
|
||||
@@ -1226,7 +1227,7 @@ class WebserviceRequestCore
|
||||
$return = $this->getFilteredObjectList();
|
||||
else
|
||||
$return = $this->getFilteredObjectDetails();
|
||||
|
||||
|
||||
if (!$return)
|
||||
return false;
|
||||
else
|
||||
@@ -1234,20 +1235,20 @@ class WebserviceRequestCore
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute POST method on a PrestaShop entity
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function executeEntityPost()
|
||||
{
|
||||
return $this->saveEntityFromXml(201);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute PUT method on a PrestaShop entity
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function executeEntityPut()
|
||||
@@ -1255,13 +1256,13 @@ class WebserviceRequestCore
|
||||
return $this->saveEntityFromXml(200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Execute DELETE method on a PrestaShop entity
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function executeEntityDelete()
|
||||
@@ -1290,13 +1291,13 @@ class WebserviceRequestCore
|
||||
$objects[] = $object;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!empty($arr_avoid_id) || empty($ids))
|
||||
{
|
||||
$this->setError(404, 'Id(s) not exists: '.implode(', ', $arr_avoid_id), 87);
|
||||
$this->_outputEnabled = true;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
$assoc = Shop::getAssoTables();
|
||||
foreach ($objects as $object)
|
||||
@@ -1305,12 +1306,12 @@ class WebserviceRequestCore
|
||||
$result = $object->{$this->resourceConfiguration['objectMethods']['delete']}();
|
||||
else
|
||||
$result = $object->delete();
|
||||
|
||||
|
||||
if (!$result)
|
||||
$arr_avoid_id[] = $object->id;
|
||||
elseif (array_key_exists($this->resourceConfiguration['retrieveData']['table'] ,$assoc))
|
||||
{
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.$this->resourceConfiguration['retrieveData']['table'].'_'.$assoc[$this->resourceConfiguration['retrieveData']['table']]['type'].'`
|
||||
$sql = 'DELETE FROM `'._DB_PREFIX_.$this->resourceConfiguration['retrieveData']['table'].'_'.$assoc[$this->resourceConfiguration['retrieveData']['table']]['type'].'`
|
||||
WHERE '.$this->resourceConfiguration['fields']['id']['sqlId'].' = '.$object->id;
|
||||
Db::getInstance()->Execute($sql);
|
||||
}
|
||||
@@ -1326,16 +1327,16 @@ class WebserviceRequestCore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write XML output after GET and HEAD action
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* save Entity Object from XML
|
||||
*
|
||||
*
|
||||
* @param int $successReturnCode
|
||||
* @return boolean
|
||||
*/
|
||||
@@ -1352,9 +1353,9 @@ class WebserviceRequestCore
|
||||
}
|
||||
$xmlEntities = $xml->children();
|
||||
$object = null;
|
||||
|
||||
|
||||
$ids = array();
|
||||
foreach ($xmlEntities as $entity)
|
||||
foreach ($xmlEntities as $entity)
|
||||
{
|
||||
// To cast in string allow to check null values
|
||||
if ((string)$entity->id != '')
|
||||
@@ -1380,11 +1381,11 @@ class WebserviceRequestCore
|
||||
$this->setError(400, 'id is forbidden when adding a new resource', 91);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
foreach ($xmlEntities as $xmlEntity)
|
||||
{
|
||||
$attributes = $xmlEntity->children();
|
||||
|
||||
|
||||
if ($this->method == 'POST')
|
||||
$object = new $this->resourceConfiguration['retrieveData']['className']();
|
||||
elseif ($this->method == 'PUT')
|
||||
@@ -1402,7 +1403,7 @@ class WebserviceRequestCore
|
||||
foreach ($this->resourceConfiguration['fields'] as $fieldName => $fieldProperties)
|
||||
{
|
||||
$sqlId = $fieldProperties['sqlId'];
|
||||
|
||||
|
||||
if ($fieldName == 'id')
|
||||
$sqlId = $fieldName;
|
||||
if (isset($attributes->$fieldName) && isset($fieldProperties['sqlId']) && (!isset($fieldProperties['i18n']) || !$fieldProperties['i18n']))
|
||||
@@ -1423,7 +1424,7 @@ class WebserviceRequestCore
|
||||
$object->$sqlId = (string)$attributes->$fieldName;
|
||||
else
|
||||
$this->setError(400, 'Parameter "'.$fieldName.'" can\'t be set to the object "'.$this->resourceConfiguration['retrieveData']['className'].'"', 123);
|
||||
|
||||
|
||||
}
|
||||
elseif (isset($fieldProperties['required']) && $fieldProperties['required'] && !$fieldProperties['i18n'])
|
||||
{
|
||||
@@ -1432,7 +1433,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
elseif ((!isset($fieldProperties['required']) || !$fieldProperties['required']) && Tools::property_exists($object, $sqlId))
|
||||
$object->$sqlId = null;
|
||||
|
||||
|
||||
if (isset($fieldProperties['i18n']) && $fieldProperties['i18n'])
|
||||
{
|
||||
$i18n = true;
|
||||
@@ -1440,7 +1441,7 @@ class WebserviceRequestCore
|
||||
$object->{$fieldName}[(int)$lang->attributes()->id] = (string)$lang;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!$this->hasErrors())
|
||||
{
|
||||
if ($i18n && ($retValidateFieldsLang = $object->validateFieldsLang(false, true)) !== true)
|
||||
@@ -1512,10 +1513,10 @@ class WebserviceRequestCore
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get SQL retrieve Filter
|
||||
*
|
||||
*
|
||||
* @param string $sqlId
|
||||
* @param string $filterValue
|
||||
* @param string $tableAlias = 'main.'
|
||||
@@ -1565,7 +1566,7 @@ class WebserviceRequestCore
|
||||
$ret .= ' AND '.$tableAlias.'`'.pSQL($sqlId).'` '.(Validate::isFloat(pSQL($filterValue)) ? 'LIKE' : '=').' "'.pSQL($filterValue)."\"\n";
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public function filterLanguage()
|
||||
{
|
||||
$arr_languages = array();
|
||||
@@ -1617,40 +1618,40 @@ class WebserviceRequestCore
|
||||
$this->setError(400, 'Language ID must be numeric', 80);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
foreach ($arr_languages as $key=>$id_lang)
|
||||
if (!Language::getLanguage($id_lang))
|
||||
unset($arr_languages[$key]);
|
||||
|
||||
|
||||
return $arr_languages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Thanks to the (WebserviceOutputBuilder) WebserviceKey::objOutput
|
||||
* Thanks to the (WebserviceOutputBuilder) WebserviceKey::objOutput
|
||||
* Method build the output depend on the WebserviceRequest::outputFormat
|
||||
* and set HTTP header parameters.
|
||||
*
|
||||
*
|
||||
* @return array with displaying informations (used in the dispatcher).
|
||||
*/
|
||||
protected function returnOutput()
|
||||
{
|
||||
$return = array();
|
||||
|
||||
|
||||
// write headers
|
||||
$this->objOutput->setHeaderParams('Access-Time', time())
|
||||
->setHeaderParams('X-Powered-By', 'PrestaShop Webservice')
|
||||
->setHeaderParams('PSWS-Version', _PS_VERSION_)
|
||||
->setHeaderParams('Execution-Time', round(microtime(true) - $this->_startTime,3));
|
||||
|
||||
|
||||
|
||||
|
||||
$return['type'] = strtolower($this->outputFormat);
|
||||
|
||||
|
||||
// write this header only now (avoid hackers happiness...)
|
||||
if ($this->_authenticated)
|
||||
{
|
||||
$this->objOutput->setHeaderParams('PSWS-Version', _PS_VERSION_);
|
||||
}
|
||||
|
||||
|
||||
// If Specific Management is asked
|
||||
if ($this->objectSpecificManagement instanceof WebserviceSpecificManagementInterface)
|
||||
{
|
||||
@@ -1663,7 +1664,7 @@ class WebserviceRequestCore
|
||||
$this->setError($e->getStatus(), $e->getMessage(), $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// for use a general output
|
||||
if (!$this->hasErrors() && $this->objectSpecificManagement == null)
|
||||
{
|
||||
@@ -1685,13 +1686,13 @@ class WebserviceRequestCore
|
||||
$type_of_view = WebserviceOutputBuilder::VIEW_DETAILS;
|
||||
else
|
||||
$type_of_view = WebserviceOutputBuilder::VIEW_LIST;
|
||||
|
||||
|
||||
if (in_array($this->method, array('PUT', 'POST')))
|
||||
{
|
||||
$type_of_view = WebserviceOutputBuilder::VIEW_DETAILS;
|
||||
$this->fieldsToDisplay = 'full';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$return['content'] = $this->objOutput->getContent($this->objects, $this->schemaToDisplay, $this->fieldsToDisplay, $this->depth, $type_of_view);
|
||||
} catch (WebserviceException $e) {
|
||||
if ($e->getType() == WebserviceException::DID_YOU_MEAN)
|
||||
@@ -1703,7 +1704,7 @@ class WebserviceRequestCore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// if the output is not enable, delete the content
|
||||
// the type content too
|
||||
if (!$this->_outputEnabled)
|
||||
@@ -1713,18 +1714,18 @@ class WebserviceRequestCore
|
||||
if (isset($return['content']))
|
||||
unset($return['content']);
|
||||
}
|
||||
|
||||
|
||||
elseif (isset($return['content']))
|
||||
$this->objOutput->setHeaderParams('Content-Sha1', sha1($return['content']));
|
||||
|
||||
// if errors happends when creating returned xml,
|
||||
|
||||
// if errors happends when creating returned xml,
|
||||
// the usual xml content is replaced by the nice error handler content
|
||||
if ($this->hasErrors())
|
||||
{
|
||||
$this->_outputEnabled = true;
|
||||
$return['content'] = $this->objOutput->getErrors($this->errors);
|
||||
}
|
||||
|
||||
|
||||
if (!isset($return['content']) || strlen($return['content']) <= 0)
|
||||
{
|
||||
$this->objOutput->setHeaderParams('Content-Type', '');
|
||||
|
||||
Reference in New Issue
Block a user