예제 #1
0
 /**
  * @param SavableModelInterface $model
  * @throws CouldNotPersistException
  */
 public function persist(SavableModelInterface $model)
 {
     $params = ['index' => $this->index, 'type' => $this->type];
     if ($model->getId()) {
         $params['body'] = ['doc' => $model->toArray()];
         $params['id'] = $model->getId();
         $this->client->update($params);
         $model->markAsStored();
         return;
     }
     $params['body'] = $model->toArray();
     $response = $this->client->index($params);
     $model->id = $response['_id'];
     $model->markAsStored();
 }
예제 #2
0
 /**
  * @param SavableModelInterface $model
  * @throws CouldNotPersistException
  */
 public function persist(SavableModelInterface $model)
 {
     $update = $this->solrClient->createUpdate();
     $doc = $update->createDocument();
     foreach ($model->getFields() as $field) {
         $doc->{$field} = $model->{$field};
     }
     $doc->id = $model->getId();
     $update->addDocument($doc);
     $update->addCommit();
     $result = $this->solrClient->update($update);
     if ($result->getStatus() != 0) {
         throw new CouldNotPersistException('Model cannot persists: ' . $result->getResponse()->getStatusMessage());
     }
     $model->markAsStored();
 }
예제 #3
0
 /**
  * @param SavableModelInterface $model
  */
 public function persist(SavableModelInterface $model)
 {
     if ($model->isDirty()) {
         $model->markAsStored();
     }
 }
예제 #4
0
 /**
  * @param SavableModelInterface $model
  * @return void
  */
 public function purge(SavableModelInterface $model)
 {
     $this->collection->deleteOne(array('id' => $model->getId()));
     $model->markAsStored();
 }
예제 #5
0
 /**
  * @param SavableModelInterface $model
  * @return string
  */
 public function update(SavableModelInterface $model)
 {
     $bindData = array();
     $index = 0;
     $update = '';
     $data = $model->toArray();
     $fields = $model->getFields();
     foreach ($fields as $field) {
         $bindKey = 'data' . $index++;
         $bindData[$bindKey] = $data[$field];
         $update .= $field . ' = :' . $bindKey . ', ';
     }
     $update = substr($update, 0, -2);
     $bindData['whereId'] = $model->getId();
     $query = $this->pdo->prepare('update ' . $this->table . ' set ' . $update . ' where id = :whereId ');
     $query->execute($bindData);
     $query->closeCursor();
     $model->markAsStored();
 }