public function publish(Client $client, $actionType, TableInterface $table, RecordInterface $record) { $con = new Condition(array('id', '=', $record->id)); $row = $table->getRow(array('id', 'pageId', 'userId', 'urlTitle', 'title', 'text'), $con); $index = $client->getIndex('amun'); $type = $index->getType('page'); $id = $row['pageId'] . '-' . $record->id; try { $document = $type->getDocument($id); if ($actionType == RecordAbstract::INSERT || $actionType == RecordAbstract::UPDATE) { // get referring page $handler = $this->hm->getHandler('AmunService\\Content\\Page'); $page = $handler->get($row['pageId'], array('id', 'path', 'urlTitle', 'title')); $data = array('id' => $id, 'userId' => $row['userId'], 'path' => $page['path'] . '/view/' . $row['id'] . '/' . $row['urlTitle'], 'title' => $row['title'], 'content' => $row['text'], 'date' => time()); $type->updateDocument(new Document($id, $data)); } else { if ($actionType == RecordAbstract::DELETE) { $type->deleteDocument($document); } } } catch (NotFoundException $e) { if ($actionType == RecordAbstract::INSERT || $actionType == RecordAbstract::UPDATE) { // get referring page $handler = $this->hm->getHandler('AmunService\\Content\\Page'); $page = $handler->get($row['pageId'], array('id', 'path', 'urlTitle', 'title')); $data = array('id' => $id, 'userId' => $row['userId'], 'path' => $page['path'] . '/view/' . $row['id'] . '/' . $row['urlTitle'], 'title' => $row['title'], 'content' => $row['text'], 'date' => time()); $type->addDocument(new Document($id, $data)); } else { if ($actionType == RecordAbstract::DELETE) { // is already deleted } } } $type->getIndex()->refresh(); }
public function __construct(TableInterface $table, $zeroAllowed = false) { $this->table = $table; $this->sql = $table->getRegistry()->getSql(); $this->registry = $table->getRegistry(); $this->zeroAllowed = $zeroAllowed; }
public function notify($type, TableInterface $table, RecordInterface $record) { $message = Json::encode($record->getData()); $headers = array('amun-table' => $table->getName(), 'amun-type' => $type, 'amun-user-id' => $this->user->id); $stomp = new Stomp($this->registry['stomp.broker'], $this->registry['stomp.user'], $this->registry['stomp.pw']); $stomp->send($this->registry['stomp.destination'], $message, $headers); unset($stomp); }
public function notify($type, TableInterface $table, RecordInterface $record) { $handler = $this->hm->getHandler('AmunService\\Log', $this->user); $log = $handler->getRecord(); $log->setRefId(isset($record->id) ? $record->id : 0); $log->setType(RecordAbstract::getType($type)); $log->setTable($table->getName()); $handler->create($log); }
private function handleDefault($type, TableInterface $table, RecordInterface $record) { // get template message $sql = <<<SQL SELECT \t`template`.`verb`, \t`template`.`path`, \t`template`.`summary` FROM \t{$this->registry['table.user_activity_template']} `template` WHERE \t`template`.`table` = ? AND \t`template`.`type` = ? SQL; $row = $this->sql->getRow($sql, array($table->getName(), RecordAbstract::getType($type))); if (!empty($row)) { // get object $className = $this->registry->getClassNameFromTable($table->getName()); $handler = $this->hm->getHandler($className, $this->user); $object = $handler->get($record->id, array(), Sql::FETCH_OBJECT); // build object url if (isset($object->pagePath) && !empty($row['path'])) { $url = $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . $object->pagePath . '/' . $row['path']; $url = $this->substituteVars($object, $url); } else { $url = '#'; } // get activity stream object. If the record does not support jas // an exception is thrown $jas = null; try { $jas = $object->export(new WriterResult(WriterInterface::JAS, new Writer\Jas())); } catch (\Exception $e) { } // insert activity $handler = $this->hm->getHandler('AmunService\\User\\Activity', $this->user); $activity = $handler->getRecord(); $activity->verb = $row['verb']; $activity->object = $jas instanceof ActivityStream\Activity ? json_encode($jas->getData()) : null; $activity->summary = $this->substituteVars($object, $row['summary'], $url); $handler->create($activity); } }