예제 #1
0
 /**
  * @see parent
  */
 public function onFlush($iterator)
 {
     $now = Mage::getSingleton('core/date')->gmtDate();
     try {
         foreach ($iterator as $result) {
             $queueRow = $this->_queueEntry($result->getOriginal()->getQueueRow());
             $item = $result->getItem();
             if ($item->getIsError()) {
                 $queueRow->setBrontoImported(null)->setBrontoSuppressed("{$item->getErrorCode()}: {$item->getErrorString()}");
                 $this->_result->incrementError();
             } else {
                 $queueRow->setBrontoImported($now)->setBrontoSuppressed(null);
                 $this->_result->incrementSuccess();
             }
             $queueRow->save();
             $this->_result->incrementTotal();
         }
         $this->_flushLogs($iterator->getOperation()->getApi());
     } catch (InvalidArgumentException $iae) {
         Mage::helper($this->_helper)->writeDebug("Client error: {$iae->getMessage()}");
     } catch (Exception $e) {
         $request = $iterator->getRequest();
         $requestData = $request->getData();
         $objects = $requestData[$request->getKey()];
         switch ($e->getCode()) {
             case 107:
                 foreach ($objects as $object) {
                     if (is_array($object) && !$object instanceof Bronto_Object) {
                         $object = new Bronto_Object($object);
                     }
                     $queueRow = $this->_queueEntry($object->getQueueRow());
                     try {
                         $iterator->getOperation()->getApi()->execute(new Bronto_Object(array('method' => $request->getMethod(), 'data' => array($request->getKey() => array($object->toArray())), 'hasUpdates' => true)));
                         $queueRow->setBrontoImported($now)->setBrontoSuppressed(null);
                         $this->_result->incrementSuccess();
                     } catch (Exception $e) {
                         $queueRow->setBrontoImported(null)->setBrontoSuppressed("Failed to process contact.");
                         $this->_result->incrementError();
                     }
                     $queueRow->save();
                     $this->_result->incrementTotal();
                     $this->_flushLogs($iterator->getOperation()->getApi());
                 }
                 break;
             default:
                 if ($e->getCode() > 200) {
                     foreach ($objects as $object) {
                         if (is_array($object) && !$object instanceof Bronto_Object) {
                             $object = new Bronto_Object($object);
                         }
                         $this->_queueEntry($object->getQueueRow())->setBrontoImported(null)->setBrontoSuppressed($e->getMessage())->save();
                         $this->_result->incrementError();
                         $this->_result->incrementTotal();
                     }
                 }
                 Mage::helper($this->_helper)->writeError($e);
                 $this->_flushLogs($iterator->getOperation()->getApi());
         }
     }
 }
예제 #2
0
 /**
  * Create a request builder with a method, uri, and options
  *
  * @param string $method
  * @param string $uri
  * @param Bronto_Object $options
  * @param Bronto_Resource_Proxy $curl
  */
 public function __construct($method, $uri, $options, $curl = null)
 {
     $this->_uri = $uri;
     $this->_method = $method;
     $this->_options = new Bronto_Object($options->toArray());
     if (is_null($curl)) {
         $curl = new Bronto_Resource_Proxy("curl_");
     }
     $this->_curl = $curl;
 }
예제 #3
0
 /**
  * Convenience method for adding/setting field values for contact
  *
  * @param Bronto_Object|string $fieldId
  * @param mixed $content
  * @return Bronto_Api_Model_Contact
  */
 public function addField($fieldId, $content = null)
 {
     if (!array_key_exists('fields', $this->_data)) {
         $this->_set('fields', array());
     }
     if ($fieldId instanceof Bronto_Object) {
         $data = $fieldId->toArray();
     } else {
         $data = array('fieldId' => $fieldId, 'content' => $content);
     }
     $data['content'] = $this->_convert($data['fieldId'], $data['content']);
     if (array_key_exists($data['fieldId'], $this->_fieldIdToIndex)) {
         $this->_data['fields'][$this->_fieldIdToIndex[$data['fieldId']]] = $data;
     } else {
         $this->_fieldIdToIndex[$data['fieldId']] = array_push($this->_data['fields'], $data) - 1;
     }
     return $this;
 }
예제 #4
0
 /**
  * Adds field options to the field as a chainable property
  *
  * @param Bronto_Object|string $value
  * @param mixed $label
  * @param boolean $isDefault
  * @return Bronto_Api_Model_Field
  */
 public function addOption($value, $label = null, $isDefault = false)
 {
     if (!array_key_exists('options', $this->_data)) {
         $this->_data['options'] = array();
     }
     if ($value instanceof Bronto_Object) {
         extract($value->toArray());
     }
     if (is_bool($label)) {
         $isDefault = $label;
         $label = null;
     }
     if (is_null($label)) {
         $label = (string) $value;
     }
     if ($isDefault) {
         foreach ($this->_data['options'] as &$option) {
             $option['isDefault'] = false;
         }
     }
     $this->_data['options'][] = array('value' => $value, 'label' => $label, 'isDefault' => $isDefault);
     return $this;
 }