From c3daad7545b567a4b3a8fe0273bb80eddc508312 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Mon, 4 Sep 2017 12:55:32 +0200
Subject: [PATCH 1/5] Fix not reachable code
---
.../class/PSWebServiceLibrary.class.php | 69 +++++++++++++------
.../class/expensereport.class.php | 2 -
2 files changed, 48 insertions(+), 23 deletions(-)
diff --git a/htdocs/admin/dolistore/class/PSWebServiceLibrary.class.php b/htdocs/admin/dolistore/class/PSWebServiceLibrary.class.php
index bb59fa93929..4b8978462fb 100644
--- a/htdocs/admin/dolistore/class/PSWebServiceLibrary.class.php
+++ b/htdocs/admin/dolistore/class/PSWebServiceLibrary.class.php
@@ -48,6 +48,7 @@ class PrestaShopWebservice
const PSCOMPATIBLEVERSIONMIN = '1.4.0.0';
const PSCOMPATIBLEVERSIONMAX = '1.6.99.99';
+
/**
* PrestaShopWebservice constructor. Throw an exception when CURL is not installed/activated
*
@@ -79,6 +80,7 @@ class PrestaShopWebservice
/**
* Take the status code and throw an exception if the server didn't return 200 or 201 code
+ *
* @param int $status_code Status code of an HTTP return
*/
protected function checkStatusCode($status_code)
@@ -86,21 +88,32 @@ class PrestaShopWebservice
$error_label = 'This call to PrestaShop Web Services failed and returned an HTTP status of %d. That means: %s.';
switch($status_code)
{
- case 200: case 201: break;
- case 204: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'No content'));break;
- case 400: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Bad Request'));break;
- case 401: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Unauthorized'));break;
- case 404: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Not Found'));break;
- case 405: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Method Not Allowed'));break;
- case 500: throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Internal Server Error'));break;
- default: throw new PrestaShopWebserviceException('This call to PrestaShop Web Services returned an unexpected HTTP status of:' . $status_code);
+ case 200:
+ case 201:
+ break;
+ case 204:
+ throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'No content'));
+ case 400:
+ throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Bad Request'));
+ case 401:
+ throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Unauthorized'));
+ case 404:
+ throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Not Found'));
+ case 405:
+ throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Method Not Allowed'));
+ case 500:
+ throw new PrestaShopWebserviceException(sprintf($error_label, $status_code, 'Internal Server Error'));
+ default:
+ throw new PrestaShopWebserviceException('This call to PrestaShop Web Services returned an unexpected HTTP status of:' . $status_code);
}
}
+
/**
* Handles a CURL request to PrestaShop Webservice. Can throw exception.
- * @param string $url Resource name
- * @param mixed $curl_params CURL parameters (sent to curl_set_opt)
- * @return array status_code, response
+ *
+ * @param string $url Resource name
+ * @param mixed $curl_params CURL parameters (sent to curl_set_opt)
+ * @return array status_code, response
*/
public function executeRequest($url, $curl_params = array())
{
@@ -178,11 +191,23 @@ class PrestaShopWebservice
return array('status_code' => $status_code, 'response' => $body, 'header' => $header);
}
+ /**
+ * Output debug info
+ *
+ * @param string $title Title
+ * @param string $content Content
+ * @return void
+ */
public function printDebug($title, $content)
{
echo ''.$title.'
'.htmlentities($content).'
';
}
+ /**
+ * Return version
+ *
+ * @return string Version
+ */
public function getVersion()
{
return $this->version;
@@ -190,8 +215,9 @@ class PrestaShopWebservice
/**
* Load XML from string. Can throw exception
- * @param string $response String from a CURL response
- * @return SimpleXMLElement status_code, response
+ *
+ * @param string $response String from a CURL response
+ * @return SimpleXMLElement status_code, response
*/
protected function parseXML($response)
{
@@ -268,8 +294,8 @@ class PrestaShopWebservice
* }
* ?>
*
- * @param array $options Array representing resource to get.
- * @return SimpleXMLElement status_code, response
+ * @param array $options Array representing resource to get.
+ * @return SimpleXMLElement status_code, response
*/
public function get($options)
{
@@ -301,8 +327,8 @@ class PrestaShopWebservice
/**
* Head method (HEAD) a resource
*
- * @param array $options Array representing resource for head request.
- * @return SimpleXMLElement status_code, response
+ * @param array $options Array representing resource for head request.
+ * @return SimpleXMLElement status_code, response
*/
public function head($options)
{
@@ -336,7 +362,9 @@ class PrestaShopWebservice
* 'id' => ID of a resource you want to edit,
* 'putXml' => Modified XML string of a resource
* Examples are given in the tutorial
- * @param array $options Array representing resource to edit.
+ *
+ * @param array $options Array representing resource to edit.
+ * @return SimpleXMLElement status_code, response
*/
public function edit($options)
{
@@ -381,7 +409,8 @@ class PrestaShopWebservice
* }
* ?>
*
- * @param array $options Array representing resource to delete.
+ * @param array $options Array representing resource to delete.
+ * @return boolean true
*/
public function delete($options)
{
@@ -400,8 +429,6 @@ class PrestaShopWebservice
self::checkStatusCode($request['status_code']);// check the response validity
return true;
}
-
-
}
/**
diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php
index 0123535ebb1..8c762121c32 100644
--- a/htdocs/expensereport/class/expensereport.class.php
+++ b/htdocs/expensereport/class/expensereport.class.php
@@ -1171,8 +1171,6 @@ class ExpenseReport extends CommonObject
$this->error=$this->db->lasterror();
return -1;
}
-
- return 0;
}
/**
From 4c8945e460a743a5cbc15737ac3c3cc8dada6669 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Mon, 4 Sep 2017 12:59:54 +0200
Subject: [PATCH 2/5] Fix bad use
---
htdocs/accountancy/journal/bankjournal.php | 2 --
1 file changed, 2 deletions(-)
diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php
index 505e2a9f534..0fbb60c2e2d 100644
--- a/htdocs/accountancy/journal/bankjournal.php
+++ b/htdocs/accountancy/journal/bankjournal.php
@@ -1,6 +1,4 @@
* Copyright (C) 2007-2010 Jean Heimburger
* Copyright (C) 2011 Juanjo Menent
From c15454e62b51179f84bb5a75d1175b6a7a666f9d Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Mon, 4 Sep 2017 13:09:26 +0200
Subject: [PATCH 3/5] Fix method to delete a bookkeeping record
---
htdocs/accountancy/class/bookkeeping.class.php | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php
index 799ebf85a34..52f7a473bed 100644
--- a/htdocs/accountancy/class/bookkeeping.class.php
+++ b/htdocs/accountancy/class/bookkeeping.class.php
@@ -1224,18 +1224,17 @@ class BookKeeping extends CommonObject
/**
* Delete bookkepping by piece number
*
- * @param int $piecenum peicenum to delete
- * @param string $mode Mode
- * @return int Result
+ * @param int $piecenum Piecenum to delete
+ * @return int Result
*/
- function deleteMvtNum($piecenum, $mode) {
+ function deleteMvtNum($piecenum) {
global $conf;
$this->db->begin();
// first check if line not yet in bookkeeping
$sql = "DELETE";
- $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element. $mode;
+ $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element;
$sql .= " WHERE piece_num = " . $piecenum;
$sql .= " AND entity IN (" . getEntity('accountancy') . ")";
From 9304df21a0dbdd8df9ba90bffbc672be92aa9035 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Mon, 4 Sep 2017 13:17:18 +0200
Subject: [PATCH 4/5] Clean code
---
htdocs/contact/canvas/actions_contactcard_common.class.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php
index 3d6b792d99b..b5df91ce210 100644
--- a/htdocs/contact/canvas/actions_contactcard_common.class.php
+++ b/htdocs/contact/canvas/actions_contactcard_common.class.php
@@ -79,18 +79,18 @@ abstract class ActionsContactCardCommon
*/
function getObject($id)
{
- $ret = $this->getInstanceDao();
+ /*$ret = $this->getInstanceDao();
if (is_object($this->object) && method_exists($this->object,'fetch'))
{
if (! empty($id)) $this->object->fetch($id);
}
else
- {
+ {*/
$object = new Contact($this->db);
if (! empty($id)) $object->fetch($id);
$this->object = $object;
- }
+ //}
}
/**
From 8de51ede1837e31d6e6db07fab6a8748fe1678ce Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Mon, 4 Sep 2017 13:22:21 +0200
Subject: [PATCH 5/5] Add warning to warn against json emulation
---
htdocs/core/lib/json.lib.php | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php
index 7388ba47806..3d14d035a61 100644
--- a/htdocs/core/lib/json.lib.php
+++ b/htdocs/core/lib/json.lib.php
@@ -19,14 +19,14 @@
/**
* \file htdocs/core/lib/json.lib.php
- * \brief Functions to emulate json function for PHP < 5.3 compatibility
+ * \brief Functions to emulate json function when there were not activated
* \ingroup core
*/
if (! function_exists('json_encode'))
{
/**
- * Implement json_encode for PHP that does not support it
+ * Implement json_encode for PHP that does not have module enabled.
*
* @param mixed $elements PHP Object to json encode
* @return string Json encoded string
@@ -42,12 +42,11 @@ if (! function_exists('json_encode'))
*
* @param mixed $elements PHP Object to json encode
* @return string Json encoded string
- * @deprecated PHP >= 5.3 supports native json_encode
* @see json_encode()
*/
function dol_json_encode($elements)
{
- dol_syslog('dol_json_encode() is deprecated. Please update your code to use native json_encode().', LOG_WARNING);
+ dol_syslog("For better permorfance, enable the native json in your PHP", LOG_WARNING);
$num=0;
if (is_object($elements)) // Count number of properties for an object