예제 #1
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();
 }
예제 #2
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();
 }