예제 #1
0
 /**
  * Called with magento cron
  * @return boolean
  * @assert () == true
  */
 public function runSync()
 {
     $helper = Mage::helper('unityreports');
     $helper->debug('*******NEW GLOBAL COUNTERS*******');
     try {
         //Check app status before syncing
         if (!$this->_appIsOk()) {
             $helper->debug('Endpoint is not receiving');
             return false;
         }
         //get a soap client
         $client = $this->_getClient();
         //get token
         $responseToken = json_decode($client->getToken($helper->getApiKey(), $helper->getApiSecret(), $helper->getLicenseKey()));
         if ($responseToken->code != 'OK') {
             $helper->debug('Cannot get a valid Token.' . $responseToken->msg);
             return false;
         }
         //send data
         $data = $this->_getData();
         $blob = Intelivemetrics_Unityreports_Model_Utils::prepareDataForSending($data);
         $client->post($responseToken->msg, array('type' => 'GLOBCOUNT', 'data' => $blob, 'license' => $helper->getLicenseKey()));
         return true;
     } catch (Exception $e) {
         $helper->debug($e, Zend_Log::ERR);
         $helper->debug('FILE: ' . __FILE__ . 'LINE: ' . __LINE__);
         return false;
     }
 }
예제 #2
0
 /**
  * Called with magento cron
  * @return boolean
  * @assert () == true
  */
 public function runSync()
 {
     $helper = Mage::helper('unityreports');
     $helper->debug('*******NEW PRODUCT COUNTERS*******');
     try {
         //Check app status before syncing
         if (!$this->_appIsOk()) {
             $helper->debug('Endpoint is not receiving');
             return false;
         }
         //get a soap client
         $client = $this->_getClient();
         //get token
         $responseToken = json_decode($client->getToken($helper->getApiKey(), $helper->getApiSecret(), $helper->getLicenseKey()));
         if ($responseToken->code != 'OK') {
             $helper->debug('Cannot get a valid Token.' . $responseToken->msg);
             return false;
         }
         //send data
         $data = $this->_getData();
         $blob = Intelivemetrics_Unityreports_Model_Utils::prepareDataForSending($data);
         $client->post($responseToken->msg, array('type' => 'COUNT', 'data' => $blob, 'license' => $helper->getLicenseKey()));
         $helper->debug('Ok - sent ' . count($data['products']['data']) . ' counters');
         //update last_sent_at
         $prodCountersTbl = Intelivemetrics_Unityreports_Model_Utils::getTableName('unityreports/product_counters');
         $query = "UPDATE {$prodCountersTbl} SET last_sent_at=NOW() WHERE last_updated_at>=last_sent_at OR last_sent_at IS NULL";
         Mage::getSingleton('unityreports/utils')->getDb()->query($query);
         Mage::getSingleton('unityreports/utils')->getDb()->closeConnection();
         return true;
     } catch (Exception $e) {
         $helper->debug($e, Zend_Log::ERR);
         $helper->debug('FILE: ' . __FILE__ . 'LINE: ' . __LINE__);
         return false;
     }
 }
예제 #3
0
 public function runSync()
 {
     $helper = Mage::helper('unityreports');
     if (!$helper->isActive()) {
         $helper->debug('Sync is deactivated');
         return false;
     }
     try {
         $client = $this->_getClient();
         //add some tracing
         if (function_exists('newrelic_add_custom_parameter')) {
             newrelic_add_custom_parameter(sync_type, self::ENTITY_TYPE);
             newrelic_add_custom_parameter(sync_max, Intelivemetrics_Unityreports_Model_Utils::getMaxItemsPerSync());
         }
         // get data
         $abcarts = $this->_getData(Intelivemetrics_Unityreports_Model_Utils::getMaxItemsPerSync());
         if (is_null($abcarts)) {
             return self::NOTHING_TO_SYNC;
         }
         //get token
         $response = json_decode($client->getToken($helper->getApiKey(), $helper->getApiSecret(), $helper->getLicenseKey()));
         if ($response->code != 'OK') {
             $helper->debug('Cannot get a valid Token.' . $response->msg);
             return false;
         }
         //see bellow, we don't mark them at this stage, but earlier
         $this->markSentItems($abcarts);
         //send data
         $blob = Intelivemetrics_Unityreports_Model_Utils::prepareDataForSending($abcarts);
         $client->post($response->msg, array('type' => 'SYNC', 'data' => $blob, 'license' => $helper->getLicenseKey(), 'entity' => self::ENTITY_TYPE));
         $helper->debug('Sending ' . count($abcarts) . ' ' . self::ENTITY_TYPE);
         return true;
     } catch (Exception $e) {
         $helper->debug($e, Zend_Log::ERR);
         $helper->debug('FILE: ' . __FILE__ . 'LINE: ' . __LINE__);
         return false;
     }
 }
예제 #4
0
 /**
  * Send action response to Endpoint
  * @param boolean $response (0:not done 1:done)
  * @param string $actionKey
  */
 protected function _sendResponse($response, $actionCode, $actionKey)
 {
     $helper = Mage::helper('unityreports');
     $client = $this->_getClient();
     try {
         //get token
         $responseToken = json_decode($client->getToken($helper->getApiKey(), $helper->getApiSecret(), $helper->getLicenseKey()));
         if ($responseToken->code != 'OK') {
             $helper->debug('Cannot get a valid Token.' . $responseToken->msg);
             return false;
         }
         $blob = Intelivemetrics_Unityreports_Model_Utils::prepareDataForSending(array('key' => $actionKey, 'code' => $actionCode, 'response' => $response['done'], 'info' => isset($response['info']) ? $response['info'] : null));
         $response = json_decode($client->post($responseToken->msg, array('type' => 'RESP', 'data' => $blob, 'license' => $helper->getLicenseKey())));
     } catch (Exception $ex) {
         $helper->debug($ex->getMessage(), Zend_Log::ERR);
         $helper->debug('FILE: ' . __FILE__ . 'LINE: ' . __LINE__);
     }
 }
예제 #5
0
 public function runSync()
 {
     $helper = Mage::helper('unityreports');
     if (!$helper->isActive()) {
         $helper->debug('Sync is deactivated');
         return false;
     }
     try {
         $client = $this->_getClient();
         //add some tracing
         if (function_exists('newrelic_add_custom_parameter')) {
             newrelic_add_custom_parameter('sync_type', $this->_getEntityType());
             newrelic_add_custom_parameter('sync_max', Intelivemetrics_Unityreports_Model_Utils::getMaxItemsPerSync());
         }
         //get data
         $data = $this->_getData(Intelivemetrics_Unityreports_Model_Utils::getMaxItemsPerSync());
         if (is_null($data)) {
             return self::NOTHING_TO_SYNC;
         }
         //get token
         $response = json_decode($client->getToken($helper->getApiKey(), $helper->getApiSecret(), $helper->getLicenseKey()));
         if ($response->code != 'OK') {
             $helper->debug('Cannot get a valid Token.' . $response->msg);
             return false;
         }
         $token = $response->msg;
         //send data
         $blob = Intelivemetrics_Unityreports_Model_Utils::prepareDataForSending($data);
         $response = json_decode($client->post($token, array('type' => 'SYNC', 'data' => $blob, 'license' => $helper->getLicenseKey(), 'entity' => $this->_getEntityType())));
         $helper->debug('Sending ' . count($data) . ' ' . $this->_getEntityType());
         //mark sent items
         if ($response->code == 'OK') {
             $this->markSentItems($data);
         }
         return true;
     } catch (Exception $e) {
         $helper->debug($e, Zend_Log::ERR);
         return false;
     }
 }