コード例 #1
0
 public static function initForceRequest($wsNameGetList, $wsNamePostList)
 {
     /*
      * GLOBAL PARAMETERS
      * $_GET["action"]
      * $_GET["date_debut"]
      * $_GET["date_fin"]
      */
     $wsReqList = array_merge($wsNameGetList, $wsNamePostList);
     /* Check for actions */
     if (isset($_GET["action"]) && in_array($_GET["action"], $wsReqList)) {
         self::$isForced = true;
         self::$wsName = $_GET["action"];
         if (in_array($_GET["action"], $wsNameGetList)) {
             self::$wsType = "GET";
         } else {
             self::$wsType = "POST";
         }
         if (isset($_GET["date_debut"]) && isset($_GET["time_debut"])) {
             self::$wsDateFrom = $_GET["date_debut"];
             self::$wsTimeFrom = $_GET["time_debut"];
         } else {
             Log::write("Veuillez ajouter les paramètres date_debut et time_debut [ex => URL?action=" . $_GET["action"] . "&date_debut=jj-mm-aaaa&time_debut=hh:mm:ss]", "error");
             die;
         }
         if (isset($_GET["date_fin"]) && isset($_GET["time_fin"])) {
             self::$wsDateTo = $_GET["date_fin"];
             self::$wsTimeTo = $_GET["time_fin"];
         } else {
             Log::write("Veuillez ajouter les paramètres date_fin et time_fin [ex => URL?action=" . $_GET["action"] . "&date_fin=jj-mm-aaaa&time_fin=hh:mm:ss]", "error");
             die;
         }
     } else {
         if (Configuration::get('OSI_ACTIVE_' . $_GET["action"]) == 0 && Configuration::get('OSI_ACTIVE_' . $_GET["action"]) != '') {
             Log::write("Ce webservice est désactivé", "error");
             die;
         } else {
             if (isset($_GET["action"])) {
                 Log::write("Cette action est invalide", "error");
                 die;
             }
         }
     }
 }
コード例 #2
0
ファイル: cron.php プロジェクト: rtajmahal/PrestaShop-modules
if (file_exists(dirname(__FILE__) . '/utils/xml.class.php')) {
    include_once "utils/xml.class.php";
}
if (file_exists(dirname(__FILE__) . '/utils/scheduler.class.php')) {
    include_once "utils/scheduler.class.php";
}
if (file_exists(dirname(__FILE__) . '/utils/forceRequest.class.php')) {
    include_once "utils/forceRequest.class.php";
}
/* Init log default type */
Log::setDefaultType($CONF_default_log);
/* Init of scheduler */
Scheduler::initTimer($CONF_WsGetReqList, $CONF_WsPostReqList, $CONF_CachetimeLbl, $CONF_LastrequestLbl);
/* Init of forceRequest (used to test only one request) */
ForceRequest::initForceRequest(Scheduler::getWsNameGetList(), Scheduler::getWsNamePostList());
if (ForceRequest::isForcedRequest() && isset($_GET['log'])) {
    Log::setDefaultType($_GET['log']);
}
/*
 * Execute POST requests
 */
Log::write("###### DO POST REQUESTS ######", "info");
$listPOST = '';
for ($i = 0; $i < sizeof($CONF_WsPostReqList); $i++) {
    $listPOST .= $i == 0 ? $CONF_WsPostReqList[$i] : ' - ' . $CONF_WsPostReqList[$i];
}
Log::write("Webservices to call : " . $listPOST, "info");
include "postSynchCtrl.php";
Log::write("###### END POST REQUESTS / TREATMENTS ######<br /><br />", "info");
/*
 * Execute GET requests
コード例 #3
0
function doPostSynch($wsName, $dateFrom, $dateTo)
{
    global $dao, $postOSIReq, $CONF_LastrequestLbl, $isOkResponses, $nbChildrenProducts, $nbResponse200, $nbResponseError, $nbResponse409, $nbNoReference;
    /* Check if allow to get this request */
    $isAllow = Scheduler::isAllowedToRequest($wsName);
    if (!ForceRequest::isForcedRequest() && !$isAllow) {
        return;
    }
    switch ($wsName) {
        /*
         * WSO-P005
         * POST /article
         */
        case "WSO-P005":
            Log::write("###### Do request " . $wsName . " - action=create_article ######", "info");
            $offset = 0;
            $limit = 1000;
            do {
                $newProducts = $dao->getLastCreateProducts($dateFrom, $dateTo, GlobalConfig::getDefaultLangId(), GlobalConfig::getDefaultCountryId(), $offset, $limit);
                $isOkResponses = true;
                $nbMainProducts = 0;
                $nbChildrenProducts = 0;
                $nbResponse200 = 0;
                $nbResponseError = 0;
                $nbResponse409 = 0;
                $nbNoReference = 0;
                if ($newProducts) {
                    $nbMainProducts = count($newProducts);
                    foreach ($newProducts as $product) {
                        /*
                         * Create main product
                         * @param $product => array
                         * @param create child products
                         * @param send publication
                         */
                        createMainProduct($product, true, true);
                    }
                    Log::write("Nb total main products = " . $nbMainProducts, "info");
                    Log::write("Nb total children products = " . $nbChildrenProducts, "info");
                    Log::write("Nb without reference = " . $nbNoReference, "info");
                    Log::write("Nb sent products = " . ($nbMainProducts + $nbChildrenProducts - $nbNoReference), "info");
                    Log::write("Nb response 200 (ok) = " . $nbResponse200, "info");
                    Log::write("Nb response 409 (duplicate) = " . $nbResponse409, "info");
                    Log::write("Nb response error = " . $nbResponseError, "info");
                } else {
                    Log::write("No request to send", "info");
                }
                $offset += $limit;
            } while (count($newProducts) == $limit);
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P006
             * POST /article/$reference$
             */
        /*
         * WSO-P006
         * POST /article/$reference$
         */
        case "WSO-P006":
            Log::write("###### Do request " . $wsName . " - action=update_article ######", "info");
            $offset = 0;
            $limit = 1000;
            do {
                $updateProducts = $dao->getLastUpdateProducts($dateFrom, $dateTo, GlobalConfig::getDefaultLangId(), GlobalConfig::getDefaultCountryId(), $offset, $limit);
                $isOkResponses = true;
                $nbMainProducts = 0;
                $nbChildrenProducts = 0;
                $nbResponse200 = 0;
                $nbResponseError = 0;
                $nbResponse409 = 0;
                $nbNoReference = 0;
                if ($updateProducts) {
                    $nbMainProducts = count($updateProducts);
                    foreach ($updateProducts as $product) {
                        updateMainProduct($product);
                    }
                    Log::write("Nb total main products = " . $nbMainProducts, "info");
                    Log::write("Nb total children products = " . $nbChildrenProducts, "info");
                    Log::write("Nb without reference = " . $nbNoReference, "info");
                    Log::write("Nb sent products = " . ($nbMainProducts + $nbChildrenProducts - $nbNoReference), "info");
                    Log::write("Nb response 200 (ok) = " . $nbResponse200, "info");
                    Log::write("Nb response 409 (duplicate) = " . $nbResponse409, "info");
                    Log::write("Nb response error = " . $nbResponseError, "info");
                } else {
                    Log::write("No request to send", "info");
                }
                $offset += $limit;
            } while (count($updateProducts) == $limit);
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P010
             * POST /client/web
             */
        /*
         * WSO-P010
         * POST /client/web
         */
        case "WSO-P010":
            Log::write("###### Do request " . $wsName . " - action=create_client_web ######", "info");
            $newCustomers = $dao->getLastCustomers($dateFrom, $dateTo);
            $isOkResponses = true;
            if ($newCustomers) {
                foreach ($newCustomers as $customer) {
                    $xmlCustomer = XML::createCustomerXml($customer);
                    Log::write("Send request for login =  "******" - ", "info");
                    $response = $postOSIReq->wso_p010($xmlCustomer);
                    if (!isOkPostResult($response->getCode())) {
                        $isOkResponses = false;
                    }
                }
            } else {
                Log::write("No request to send", "info");
            }
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P011
             * POST /affaire/commande/web
             */
        /*
         * WSO-P011
         * POST /affaire/commande/web
         */
        case "WSO-P011":
            Log::write("###### Do request " . $wsName . " - action=create_commande_web ######", "info");
            /* Check if So Colissimo is installed */
            $tableSoColissimo = $dao->socolissimo_exists(_DB_NAME_);
            if ($tableSoColissimo > 0) {
                /* So Colissimo is installed */
                $orders = $dao->getLastOrdersSoColissimo($dateFrom, $dateTo, GlobalConfig::getDefaultCountryId());
            } else {
                /* So Colissimo is not installed */
                $orders = $dao->getLastOrders($dateFrom, $dateTo, GlobalConfig::getDefaultCountryId());
            }
            $giftTax = $dao->getGiftTax();
            $isOkResponses = true;
            if ($giftTax != null) {
                $giftTax = floatval($giftTax);
            } else {
                $giftTax = 0;
            }
            if ($orders) {
                foreach ($orders as $order) {
                    $orderDetails = $dao->getOrderDetails($order['id_order'], GlobalConfig::getDefaultLangId());
                    if ($orderDetails) {
                        /* Add virtual article for gift */
                        if ($order['gift'] == "1") {
                            $virtualArticle['reference'] = '_EMB';
                            $virtualArticle['product_name'] = 'Emballage cadeau';
                            $virtualArticle['product_quantity'] = 1;
                            $virtualArticle['tax_rate'] = $giftTax;
                            $virtualArticle['Remise_Pourc'] = 0;
                            $virtualArticle['id_order'] = $order['id_order'];
                            $virtualArticle['product_price'] = $order['total_wrapping'] / (1 + floatval($giftTax) / 100);
                            $orderDetails[] = $virtualArticle;
                        }
                        $xmlProduct = XML::createOrderXml($order, $orderDetails);
                        $orderNumber = $order['id_order'];
                        Log::write("Send request for order = " . $orderNumber . " - ", "info");
                        $response = $postOSIReq->wso_p011($xmlProduct, $reference);
                        if (!isOkPostResult($response->getCode())) {
                            $isOkResponses = false;
                        } else {
                            $now = date('Y-m-d H:i:s');
                            Db::getInstance()->Execute('
								INSERT INTO `' . _DB_PREFIX_ . 'opensi_order` (id_order, date_order_synchro, transaction, date_transaction, paid, date_paid)
								VALUES ("' . $order['id_order'] . '", "' . $now . '", 0, 0, 0, 0);
							');
                        }
                    } else {
                        Log::write("ERROR - Order ID " . $order['id_order'] . " - Error during synchronisation of the order : No products found for this order !", "ERROR");
                    }
                }
            } else {
                Log::write("No request to send", "info");
            }
            /* Update OSI_LASTREQUEST_WSO-P011 value */
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P015
             * POST /affaire/commande/web/transaction
             */
        /*
         * WSO-P015
         * POST /affaire/commande/web/transaction
         */
        case "WSO-P015":
            Log::write("###### Do request " . $wsName . " - action=create_transaction_bancaire ######", "info");
            $orders = $dao->getLastCreateOrUpdateOrders($dateFrom, $dateTo);
            $isOkResponses = true;
            if ($orders) {
                foreach ($orders as $order) {
                    if ($order['valid'] == 1 && $order['total_paid_real'] != 0) {
                        $xmlTransaction = XML::createTransactionWebXml($order);
                        $idOrder = $order['id_order'];
                        Log::write("Send request for order =  " . $idOrder . " - ", "info");
                        $response = $postOSIReq->wso_p015($xmlTransaction);
                        if (!isOkPostResult($response->getCode())) {
                            $isOkResponses = false;
                            Log::write("...PROBLEME AVEC " . $idOrder . "...", "ERROR");
                        } else {
                            $now = date('Y-m-d H:i:s');
                            Db::getInstance()->Execute('
								UPDATE `' . _DB_PREFIX_ . 'opensi_order` set transaction = "1", date_transaction = "' . $now . '" WHERE id_order = "' . $idOrder . '";
							');
                        }
                    }
                }
            } else {
                Log::write("No request to send", "info");
            }
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
            /*
             * WSO-P025
             * POST /client/web/$code_site_web$/$login$
             */
        /*
         * WSO-P025
         * POST /client/web/$code_site_web$/$login$
         */
        case "WSO-P025":
            Log::write("###### Do request " . $wsName . " - action=update_client_web ######", "info");
            $editCustomers = $dao->getLastUpdateCustomers($dateFrom, $dateTo);
            $isOkResponses = true;
            if ($editCustomers) {
                foreach ($editCustomers as $customer) {
                    $xmlCustomer = XML::createCustomerXml($customer);
                    $login = $customer["id_customer"];
                    Log::write("Send request for login =  "******" - ", "info");
                    $response = $postOSIReq->wso_p025($xmlCustomer, $login);
                    if (!isOkPostResult($response->getCode())) {
                        $isOkResponses = false;
                    }
                }
            } else {
                Log::write("No request to send", "info");
            }
            if ($isOkResponses && !ForceRequest::isForcedRequest()) {
                Configuration::updateValue($CONF_LastrequestLbl . $wsName, Scheduler::getTimeOnInit());
            }
            Log::write("End request  " . $wsName . " ------<br /><br />", "info");
            break;
    }
}