Example #1
0
 public function testChanged()
 {
     $this->assertEquals(false, $this->item->getChanged());
     $this->item->setChanged(true);
     $this->assertEquals(true, $this->item->getChanged());
 }
Example #2
0
 /**
  * Insert or update record
  *
  * @param object $entity   New/updated entity
  * @param bool   $realtime [optional] Perform immediate insert/update to
  *                              search attributes table(s). True by default.
  * @param bool   $needToCompute
  * @return Item Index item id on success, false otherwise
  */
 public function save($entity, $realtime = true, $needToCompute = false)
 {
     $data = $this->mapper->mapObject($entity);
     if (empty($data)) {
         return null;
     }
     $name = get_class($entity);
     $entityMeta = $this->em->getClassMetadata(get_class($entity));
     $identifierField = $entityMeta->getSingleIdentifierFieldName($entityMeta);
     $id = $entityMeta->getReflectionProperty($identifierField)->getValue($entity);
     $item = null;
     if ($id) {
         $item = $this->getIndexRepo()->findOneBy(array('entity' => $name, 'recordId' => $id));
     }
     if (!$item) {
         $item = new Item();
         $config = $this->mapper->getEntityConfig($name);
         $alias = $config ? $config['alias'] : $name;
         $item->setEntity($name)->setRecordId($id)->setAlias($alias);
     }
     $item->setChanged(!$realtime);
     if ($realtime) {
         $item->setTitle($this->getEntityTitle($entity))->saveItemData($data);
     } else {
         $this->reindexJob();
     }
     $this->em->persist($item);
     if ($needToCompute) {
         $this->computeSet($item);
     }
     return $item;
 }