/**
  * @param      $sObjectType
  * @param      $id
  * @param bool $refresh
  *
  * @return array|bool|mixed|\Phpforce\SoapClient\Result\SObject[]|\Traversable|void
  */
 public function get($sObjectType, $id, $refresh = false)
 {
     $fields = false;
     $object = false;
     if (!$refresh) {
         $object = $this->memcached->get('salesforce.object.' . $id);
     }
     if (!$object) {
         // Get fields from memcache
         if (!$refresh) {
             $fields = $this->memcached->get('salesforce.objectFields.' . $sObjectType);
         }
         try {
             // If no data, ask Salesforce and save to memcached.
             if (!$fields) {
                 $obj = $this->soapClient->call('describeSObject', array('sObjectType' => $sObjectType));
                 $fields = array();
                 foreach ($obj->getFields() as $field) {
                     $fields[] = $field->getName();
                 }
                 $this->memcached->set('salesforce.objectFields.' . $sObjectType, $fields, $this->memcached_ttl);
             }
             // TODO: Log Salesforce Query and Result
             $object = $this->soapClient->retrieve($fields, array($id), $sObjectType);
             $object = $object[0];
             // Set Memcached
             $this->memcached->set('salesforce.object.' . $id, $object, $this->memcached_ttl);
         } catch (\Exception $e) {
         }
     }
     return $object;
 }
예제 #2
0
 /**
  * Flushes all queue changes to the server.
  *
  * @param \SplQueue $queue
  */
 public function flush(\SplQueue $queue)
 {
     if ($this->locked) {
         $this->memcache->delete('queue.manager');
         $this->memcache->set('queue.manager', serialize($queue));
         $this->locked = false;
         $this->memcache->delete('queue.manager.lock');
     } else {
         $this->eventDispatcher->dispatch('queue.manager.flushed', new ManagerFlushedEvent(ManagerFlushedEvent::STATUS_FLUSH_FAILED_NOLOCK));
     }
 }