Ejemplo n.º 1
0
 protected function doDelete(RecordInterface $record, Version $version)
 {
     $this->testCase->assertEquals(8, $this->pathParameters->getProperty('fooId'));
     $this->testCase->assertEmpty($this->pathParameters->getProperty('bar'));
     $this->testCase->assertEquals(1, $record->getId());
     return array('success' => true, 'message' => 'You have successful delete a record');
 }
Ejemplo n.º 2
0
 /**
  * Method wich can map all fields of an record to an arbitary class by
  * calling the fitting setter methods if available
  *
  * @param \PSX\Data\RecordInterface $source
  * @param object $destination
  * @param array $rules
  */
 public static function map(RecordInterface $source, $destination, array $rules)
 {
     if (!is_object($destination)) {
         throw new InvalidArgumentException('Destination must be an object');
     }
     $data = $source->getRecordInfo()->getData();
     foreach ($data as $key => $value) {
         // convert to camelcase if underscore is in name
         if (strpos($key, '_') !== false) {
             $key = implode('', array_map('ucfirst', explode('_', $key)));
         }
         $method = null;
         if (isset($rules[$key])) {
             if (is_string($rules[$key])) {
                 $method = 'set' . ucfirst($rules[$key]);
             } elseif ($rules[$key] instanceof Rule) {
                 $method = 'set' . ucfirst($rules[$key]->getName());
                 $value = $rules[$key]->getValue($value, $data);
             }
         } else {
             $method = 'set' . ucfirst($key);
         }
         if (is_callable(array($destination, $method))) {
             $destination->{$method}($value);
         }
     }
 }
Ejemplo n.º 3
0
Archivo: Soap.php Proyecto: seytar/psx
 public function write(RecordInterface $record)
 {
     $xmlWriter = new XMLWriter();
     $xmlWriter->openMemory();
     $xmlWriter->setIndent(true);
     $xmlWriter->startDocument('1.0', 'UTF-8');
     $xmlWriter->startElement('soap:Envelope');
     $xmlWriter->writeAttribute('xmlns:soap', 'http://schemas.xmlsoap.org/soap/envelope/');
     if ($record instanceof ExceptionRecord) {
         $xmlWriter->startElement('soap:Body');
         $xmlWriter->startElement('soap:Fault');
         $xmlWriter->writeElement('faultcode', 'soap:Server');
         $xmlWriter->writeElement('faultstring', $record->getMessage());
         if ($record->getTrace()) {
             $xmlWriter->startElement('detail');
             $graph = new GraphTraverser();
             $graph->traverse($record, new Visitor\XmlWriterVisitor($xmlWriter, $this->namespace));
             $xmlWriter->endElement();
         }
         $xmlWriter->endElement();
         $xmlWriter->endElement();
     } else {
         $xmlWriter->startElement('soap:Body');
         $record = new Record($this->requestMethod . 'Response', $record->getRecordInfo()->getFields());
         $graph = new GraphTraverser();
         $graph->traverse($record, new Visitor\XmlWriterVisitor($xmlWriter, $this->namespace));
         $xmlWriter->endElement();
     }
     $xmlWriter->endElement();
     $xmlWriter->endDocument();
     return $xmlWriter->outputMemory();
 }
Ejemplo n.º 4
0
 protected function sendSignedRequest($type, RecordInterface $record = null)
 {
     $url = new Url($this->getEndpoint());
     $body = $record !== null ? Json::encode($record->getFields()) : null;
     $header = array('Content-Type' => 'application/json', 'Accept' => 'application/json');
     return $this->signedRequest($type, $url, $header, $body);
 }
Ejemplo n.º 5
0
 /**
  * Generates an entity definition from the given $record class 
  *
  * @param PSX\Data\RecordInterface $record
  */
 public function addEntityType(RecordInterface $record)
 {
     $this->writer->startElement('EntityType');
     $this->writer->writeAttribute('Name', $record->getRecordInfo()->getName());
     $this->buildEntity(new ReflectionClass($record), true);
     $this->buildComplexTypes();
     $this->writer->endElement();
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 /**
  * Inserts an record for approval
  *
  * @param integer $type
  * @param PSX_Data_RecordInterface $record
  * @return void
  */
 public function approveRecord($type, RecordInterface $record)
 {
     $type = Record::getType($type);
     if ($type !== false) {
         $date = new DateTime('NOW', $this->registry['core.default_timezone']);
         $this->sql->insert($this->registry['table.core_approval_record'], array('userId' => $this->user->id, 'type' => $type, 'table' => $this->table->getName(), 'record' => serialize($record->getFields()), 'date' => $date->format(DateTime::SQL)));
     } else {
         throw new Exception('Invalid approve record type');
     }
 }
Ejemplo n.º 8
0
 public function delete(RecordInterface $record)
 {
     if ($record->hasFields('id')) {
         $con = new Condition(array('id', '=', $record->id));
         $this->table->delete($con);
         $this->notify(RecordAbstract::DELETE, $record);
         return $record;
     } else {
         throw new Exception('Missing field in record');
     }
 }
Ejemplo n.º 9
0
 public function delete(RecordInterface $record)
 {
     if ($record->hasFields('id')) {
         // move all friends to uncategorized
         $con = new Condition();
         $con->add('userId', '=', $this->user->getId());
         $con->add('groupId', '=', $record->id);
         $this->sql->update($this->registry['table.user_friend'], array('groupId' => 0), $con);
         $con = new Condition(array('id', '=', $record->id));
         $this->table->delete($con);
         $this->notify(RecordAbstract::DELETE, $record);
         return $record;
     } else {
         throw new Exception('Missing field in record');
     }
 }
Ejemplo n.º 10
0
Archivo: Rss.php Proyecto: seytar/psx
 public function write(RecordInterface $record)
 {
     if ($record instanceof RssRecord) {
         $writer = new Writer($record->getTitle(), $record->getLink(), $record->getDescription());
         $this->buildChannel($record, $writer);
         foreach ($record as $row) {
             $item = $writer->createItem();
             $this->buildItem($row, $item);
             $item->close();
         }
         return $writer->toString();
     } elseif ($record instanceof Item) {
         $writer = new Writer\Item();
         $this->buildItem($record, $writer);
         return $writer->toString();
     } else {
         throw new InvalidArgumentException('Record must be an PSX\\Rss or PSX\\Rss\\Item record');
     }
 }
Ejemplo n.º 11
0
 protected function getDetails(RecordInterface $element)
 {
     if ($element instanceof Form\Element\Action) {
         return '';
     } elseif ($element instanceof Form\Element\Connection) {
         return '';
     } elseif ($element instanceof Form\Element\Input) {
         return $element->getType();
     } elseif ($element instanceof Form\Element\Select) {
         $options = [];
         foreach ($element->getOptions() as $option) {
             $options[] = $option['key'] . ': ' . $option['value'];
         }
         return implode(', ', $options);
     } elseif ($element instanceof Form\Element\TextArea) {
         return $element->getMode();
     } else {
         return '';
     }
 }
Ejemplo n.º 12
0
 public function getVisitorMock(RecordInterface $record)
 {
     $visitor = $this->getMock('PSX\\Data\\Record\\VisitorInterface', array('visitObjectStart', 'visitObjectEnd', 'visitObjectValueStart', 'visitObjectValueEnd', 'visitArrayStart', 'visitArrayEnd', 'visitArrayValueStart', 'visitArrayValueEnd', 'visitValue'));
     $visitor->expects($this->at(0))->method('visitObjectStart')->with($this->equalTo('record'));
     $visitor->expects($this->at(1))->method('visitObjectValueStart')->with($this->equalTo('id'), $this->equalTo(1));
     $visitor->expects($this->at(2))->method('visitValue')->with($this->equalTo(1));
     $visitor->expects($this->at(4))->method('visitObjectValueStart')->with($this->equalTo('title'), $this->equalTo('foobar'));
     $visitor->expects($this->at(5))->method('visitValue')->with($this->equalTo('foobar'));
     $visitor->expects($this->at(7))->method('visitObjectValueStart')->with($this->equalTo('active'), $this->equalTo(true));
     $visitor->expects($this->at(8))->method('visitValue')->with($this->equalTo(true));
     $visitor->expects($this->at(10))->method('visitObjectValueStart')->with($this->equalTo('disabled'), $this->equalTo(false));
     $visitor->expects($this->at(11))->method('visitValue')->with($this->equalTo(false));
     $visitor->expects($this->at(13))->method('visitObjectValueStart')->with($this->equalTo('rating'), $this->equalTo(12.45));
     $visitor->expects($this->at(14))->method('visitValue')->with($this->equalTo(12.45));
     $visitor->expects($this->at(16))->method('visitObjectValueStart')->with($this->equalTo('date'), $this->equalTo(new \DateTime('2014-01-01T12:34:47+01:00')));
     $visitor->expects($this->at(17))->method('visitValue')->with($this->equalTo(new \DateTime('2014-01-01T12:34:47+01:00')));
     $visitor->expects($this->at(19))->method('visitObjectValueStart')->with($this->equalTo('href'), $this->equalTo(new Uri('http://foo.com')));
     $visitor->expects($this->at(20))->method('visitValue')->with($this->equalTo(new Uri('http://foo.com')));
     // person
     $visitor->expects($this->at(22))->method('visitObjectValueStart')->with($this->equalTo('person'), $this->equalTo($record->getPerson()));
     $visitor->expects($this->at(23))->method('visitObjectStart')->with($this->equalTo('person'));
     $visitor->expects($this->at(24))->method('visitObjectValueStart')->with($this->equalTo('title'), $this->equalTo('Foo'));
     $visitor->expects($this->at(25))->method('visitValue')->with($this->equalTo('Foo'));
     // category
     $visitor->expects($this->at(29))->method('visitObjectValueStart')->with($this->equalTo('category'), $this->equalTo($record->getCategory()));
     $visitor->expects($this->at(30))->method('visitObjectStart')->with($this->equalTo('category'));
     $visitor->expects($this->at(31))->method('visitObjectValueStart')->with($this->equalTo('general'), $this->equalTo($record->getCategory()->getGeneral()));
     $visitor->expects($this->at(32))->method('visitObjectStart')->with($this->equalTo('category'));
     $visitor->expects($this->at(33))->method('visitObjectValueStart')->with($this->equalTo('news'), $this->equalTo($record->getCategory()->getGeneral()->getNews()));
     $visitor->expects($this->at(34))->method('visitObjectStart')->with($this->equalTo('category'));
     $visitor->expects($this->at(35))->method('visitObjectValueStart')->with($this->equalTo('technic'), $this->equalTo('Foo'));
     $visitor->expects($this->at(36))->method('visitValue')->with($this->equalTo('Foo'));
     // tags
     $visitor->expects($this->at(44))->method('visitObjectValueStart')->with($this->equalTo('tags'), $this->equalTo($record->getTags()));
     $visitor->expects($this->at(46))->method('visitArrayValueStart')->with($this->equalTo('bar'));
     $visitor->expects($this->at(47))->method('visitValue')->with($this->equalTo('bar'));
     $visitor->expects($this->at(49))->method('visitArrayValueStart')->with($this->equalTo('foo'));
     $visitor->expects($this->at(50))->method('visitValue')->with($this->equalTo('foo'));
     $visitor->expects($this->at(52))->method('visitArrayValueStart')->with($this->equalTo('test'));
     $visitor->expects($this->at(53))->method('visitValue')->with($this->equalTo('test'));
     // entry
     $visitor->expects($this->at(57))->method('visitObjectValueStart')->with($this->equalTo('entry'), $this->equalTo($record->getEntry()));
     $visitor->expects($this->at(59))->method('visitArrayValueStart')->with($this->equalTo($record->getEntry()[0]));
     $visitor->expects($this->at(60))->method('visitObjectStart')->with($this->equalTo('entry'));
     $visitor->expects($this->at(61))->method('visitObjectValueStart')->with($this->equalTo('title'), $this->equalTo($record->getEntry()[0]->getTitle()));
     $visitor->expects($this->at(62))->method('visitValue')->with($this->equalTo($record->getEntry()[0]->getTitle()));
     $visitor->expects($this->at(66))->method('visitArrayValueStart')->with($this->equalTo($record->getEntry()[1]));
     $visitor->expects($this->at(67))->method('visitObjectStart')->with($this->equalTo('entry'));
     $visitor->expects($this->at(68))->method('visitObjectValueStart')->with($this->equalTo('title'), $this->equalTo($record->getEntry()[1]->getTitle()));
     $visitor->expects($this->at(69))->method('visitValue')->with($this->equalTo($record->getEntry()[1]->getTitle()));
     return $visitor;
 }
Ejemplo n.º 13
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->create(array('methods' => $record->getMethods(), 'path' => $record->getPath(), 'controller' => 'Fusio\\Impl\\Controller\\SchemaApiController', 'config' => $record->getConfig()));
     // get last insert id
     $routeId = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->getLastInsertId();
     // insert dependency links
     $this->routesDependencyManager->insertDependencyLinks($routeId, $record->getConfig());
     // lock dependencies
     $this->routesDependencyManager->lockExistingDependencies($routeId);
     return array('success' => true, 'message' => 'Route successful created');
 }
Ejemplo n.º 14
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $scopeTable = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Scope');
     $scopeTable->create(array('name' => $record->getName()));
     // insert routes
     $scopeId = $scopeTable->getLastInsertId();
     $this->insertRoutes($scopeId, $record->getRoutes());
     return array('success' => true, 'message' => 'Scope successful created');
 }
Ejemplo n.º 15
0
 /**
  * Returns the PUT response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doUpdate(RecordInterface $record, Version $version)
 {
     // we can only change the password through the backend app
     if ($this->appId != 1) {
         throw new StatusCode\BadRequestException('Changing the password is only possible through the backend app');
     }
     // check verify password
     if ($record->getNewPassword() != $record->getVerifyPassword()) {
         throw new StatusCode\BadRequestException('New password does not match the verify password');
     }
     // change password
     $result = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\User')->changePassword($this->userId, $record->getOldPassword(), $record->getNewPassword());
     if ($result) {
         return array('success' => true, 'message' => 'Password successful changed');
     } else {
         throw new StatusCode\BadRequestException('Changing password failed');
     }
 }
Ejemplo n.º 16
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $schemaTable = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Schema');
     $schemaTable->create(array('status' => Schema::STATUS_ACTIVE, 'name' => $record->getName(), 'source' => $record->getSource(), 'cache' => $this->schemaParser->parse($record->getSource(), $record->getName())));
     return array('success' => true, 'message' => 'Schema successful created');
 }
Ejemplo n.º 17
0
 protected function doDelete(RecordInterface $record, Version $version)
 {
     $table = $this->getTable();
     $data = $table->get($record->getRecordInfo()->getField($table->getPrimaryKey()));
     if (empty($data)) {
         throw new StatusCode\NotFoundException('Record not found');
     }
     $table->delete($record);
     return array('success' => true, 'message' => sprintf('%s successful deleted', ucfirst($table->getDisplayName())));
 }
Ejemplo n.º 18
0
 /**
  * Checks whether the data we received as post is converted to the right
  * types
  *
  * @param \PHPUnit_Framework_TestCase $testCase
  * @param \PSX\Data\RecordInterface $record
  */
 public static function assertRecord(\PHPUnit_Framework_TestCase $testCase, RecordInterface $record)
 {
     $testCase->assertInternalType('array', $record->getArray());
     $testCase->assertEquals(1, count($record->getArray()));
     $testCase->assertEquals(['bar'], $record->getArray());
     $testCase->assertInternalType('array', $record->getArrayComplex());
     $testCase->assertEquals(2, count($record->getArrayComplex()));
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayComplex()[0]);
     $testCase->assertEquals(['foo' => 'bar'], $record->getArrayComplex()[0]->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayComplex()[1]);
     $testCase->assertEquals(['foo' => 'foo'], $record->getArrayComplex()[1]->getRecordInfo()->getFields());
     $testCase->assertInternalType('array', $record->getArrayChoice());
     $testCase->assertEquals(3, count($record->getArrayChoice()));
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayChoice()[0]);
     $testCase->assertEquals(['foo' => 'baz'], $record->getArrayChoice()[0]->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayChoice()[1]);
     $testCase->assertEquals(['bar' => 'bar'], $record->getArrayChoice()[1]->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayChoice()[2]);
     $testCase->assertEquals(['foo' => 'foo'], $record->getArrayChoice()[2]->getRecordInfo()->getFields());
     $testCase->assertInternalType('boolean', $record->getBoolean());
     $testCase->assertEquals(true, $record->getBoolean());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getChoice());
     $testCase->assertEquals(['foo' => 'bar'], $record->getComplex()->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getComplex());
     $testCase->assertEquals(['foo' => 'bar'], $record->getComplex()->getRecordInfo()->getFields());
     $testCase->assertInstanceOf('PSX\\DateTime\\Date', $record->getDate());
     $testCase->assertEquals('2015-05-01', $record->getDate()->format('Y-m-d'));
     $testCase->assertInstanceOf('PSX\\DateTime', $record->getDateTime());
     $testCase->assertEquals('2015-05-01T13:37:14Z', $record->getDateTime()->format('Y-m-d\\TH:i:s\\Z'));
     $testCase->assertInstanceOf('PSX\\DateTime\\Duration', $record->getDuration());
     $testCase->assertEquals('000100000000', $record->getDuration()->format('%Y%M%D%H%I%S'));
     $testCase->assertInternalType('float', $record->getFloat());
     $testCase->assertEquals(13.37, $record->getFloat());
     $testCase->assertInternalType('integer', $record->getInteger());
     $testCase->assertEquals(7, $record->getInteger());
     $testCase->assertInternalType('string', $record->getString());
     $testCase->assertEquals('bar', $record->getString());
     $testCase->assertInstanceOf('PSX\\DateTime\\Time', $record->getTime());
     $testCase->assertEquals('13:37:14', $record->getTime()->format('H:i:s'));
 }
Ejemplo n.º 19
0
 private function substituteVars(RecordInterface $record, $content, $url = null)
 {
     // object fields
     if ($url !== null && strpos($content, '{object.url') !== false) {
         $content = str_replace('{object.url}', $url, $content);
     }
     // user fields
     if (strpos($content, '{user.') !== false) {
         $fields = array('id', 'name', 'profileUrl', 'lastSeen', 'date');
         foreach ($fields as $v) {
             $key = '{user.' . $v . '}';
             if (strpos($content, $key) !== false) {
                 $value = call_user_func(array($this->user, 'get' . ucfirst($v)));
                 $content = str_replace($key, $value, $content);
             }
         }
     }
     // record fields
     if (strpos($content, '{record.') !== false) {
         $fields = $record->getData();
         foreach ($fields as $k => $v) {
             $key = '{record.' . $k . '}';
             if (strpos($content, $key) !== false) {
                 $content = str_replace($key, $v, $content);
             }
         }
     }
     return $content;
 }
Ejemplo n.º 20
0
 public function delete(RecordInterface $record)
 {
     if ($record->hasFields('id')) {
         $con = new Condition(array('id', '=', $record->id));
         $this->table->delete($con);
         $this->notify(RecordAbstract::DELETE, $record);
         // delete assigned gadgets
         $handler = $this->hm->getHandler('AmunService\\Content\\Page\\Gadget', $this->user);
         $con = new Condition(array('pageId', '=', $record->id));
         $oldGadgets = $this->hm->getTable('AmunService\\Content\\Page\\Gadget')->getCol('id', $con);
         foreach ($oldGadgets as $id) {
             $gadgetRecord = $handler->getRecord();
             $gadgetRecord->id = $id;
             $handler->delete($gadgetRecord);
         }
         return $record;
     } else {
         throw new Exception('Missing field in record');
     }
 }
Ejemplo n.º 21
0
 /**
  * Returns the POST response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doCreate(RecordInterface $record, Version $version)
 {
     $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Action')->create(array('status' => Action::STATUS_ACTIVE, 'name' => $record->getName(), 'class' => $record->getClass(), 'config' => $record->getConfig()->getRecordInfo()->getData(), 'date' => new \DateTime()));
     return array('success' => true, 'message' => 'Action successful created');
 }
Ejemplo n.º 22
0
 /**
  * Returns the PUT response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doUpdate(RecordInterface $record, Version $version)
 {
     $appId = (int) $this->getUriFragment('app_id');
     $app = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\App')->get($appId);
     if (!empty($app)) {
         $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\App')->update(array('id' => $app->getId(), 'status' => $record->getStatus(), 'name' => $record->getName(), 'url' => $record->getUrl()));
         $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\App\\Scope')->deleteAllFromApp($appId);
         $scopes = $record->getScopes();
         if (!empty($scopes) && is_array($scopes)) {
             $this->insertScopes($appId, $scopes);
         }
         return array('success' => true, 'message' => 'App successful updated');
     } else {
         throw new StatusCode\NotFoundException('Could not find app');
     }
 }
Ejemplo n.º 23
0
 /**
  * If the status of the friendhip request is "REQUEST" then we look whether
  * the user wich receives the friendship request is a remote user. If its a
  * remote user we send an notification to the website that the user has
  * received a friendship request. If the status is "NORMAL" the request was
  * accepted. If the user who has made the request was an remote user we send
  * and notification to the website that the request was accepted.
  *
  * @param RecordInterface $record
  * @return void
  */
 protected function handleRemoteSubscription(RecordInterface $record)
 {
     $cred = null;
     switch ($record->status) {
         // a remote user wants to request a user as friend. We must notify
         // the remote website about the friendship request
         case Record::REQUEST:
             if ($record->getUser()->getStatus() == Account\Record::REMOTE) {
                 $url = new Url($record->getUser()->getHost()->url);
                 $mode = Relation::REQUEST;
                 $host = $this->base->getHost();
                 $name = $record->getFriend()->name;
                 $cred = $record->getUser()->getRemoteCredentials();
             }
             break;
             // a user accepted a friendship request where the initiator was an
             // remote user we must inform the remote website that the request
             // was accepted
         // a user accepted a friendship request where the initiator was an
         // remote user we must inform the remote website that the request
         // was accepted
         case Record::NORMAL:
             if ($record->getFriend()->getStatus() == Account\Record::REMOTE) {
                 $url = new Url($record->getFriend()->getHost()->url);
                 $mode = Relation::ACCEPT;
                 $host = $this->base->getHost();
                 $name = $record->getUser()->name;
                 $cred = $record->getFriend()->getRemoteCredentials();
             }
             break;
     }
     if ($cred instanceof Consumer) {
         $http = new Http();
         $relation = new Relation($http, $cred);
         $relation->request($url, $mode, $host, $name);
     }
 }
Ejemplo n.º 24
0
 /**
  * Returns the PUT response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doUpdate(RecordInterface $record, Version $version)
 {
     $routeId = (int) $this->getUriFragment('route_id');
     $route = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->get($routeId);
     if (!empty($route)) {
         $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Routes')->update(array('id' => $route->getId(), 'methods' => $record->getMethods(), 'path' => $record->getPath(), 'controller' => 'Fusio\\Impl\\Controller\\SchemaApiController', 'config' => $record->getConfig()));
         // remove all dependency links
         $this->routesDependencyManager->removeExistingDependencyLinks($route->getId());
         // unlock dependencies
         $this->routesDependencyManager->unlockExistingDependencies($route->getId());
         // insert dependency links
         $this->routesDependencyManager->insertDependencyLinks($route->getId(), $record->getConfig());
         // lock dependencies
         $this->routesDependencyManager->lockExistingDependencies($route->getId());
         return array('success' => true, 'message' => 'Routes successful updated');
     } else {
         throw new StatusCode\NotFoundException('Could not find route');
     }
 }
Ejemplo n.º 25
0
 /**
  * Returns the PUT response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doUpdate(RecordInterface $record, Version $version)
 {
     $userId = (int) $this->getUriFragment('user_id');
     $user = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\User')->get($userId);
     if (!empty($user)) {
         $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\User')->update(array('id' => $user['id'], 'status' => $record->getStatus(), 'name' => $record->getName()));
         $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\User\\Scope')->deleteAllFromUser($user['id']);
         $this->insertScopes($user['id'], $record->getScopes());
         return array('success' => true, 'message' => 'User successful updated');
     } else {
         throw new StatusCode\NotFoundException('Could not find user');
     }
 }
Ejemplo n.º 26
0
 protected function doDelete(RecordInterface $record, Version $version)
 {
     $this->testCase->assertEquals(1, $record->getId());
     return array('success' => true, 'message' => 'You have successful delete a record');
 }
Ejemplo n.º 27
0
 /**
  * Merges data from two record into a new record. The right record
  * overwrites values from the left record
  *
  * @param \PSX\Data\RecordInterface $left
  * @param \PSX\Data\RecordInterface $right
  * @return \PSX\Data\RecordInterface
  */
 public static function merge(RecordInterface $left, RecordInterface $right)
 {
     return new Object(array_merge($left->getRecordInfo()->getData(), $right->getRecordInfo()->getData()));
 }
Ejemplo n.º 28
0
 public function delete(RecordInterface $record)
 {
     if ($record->hasFields('id')) {
         $con = new Condition(array('id', '=', $record->id));
         $this->table->delete($con);
         $con = new Condition(array('accessId', '=', $record->id));
         $this->hm->getTable('AmunService\\Oauth\\Access\\Right')->delete($con);
         $this->notify(RecordAbstract::DELETE, $record);
         return $record;
     } else {
         throw new Exception('Missing field in record');
     }
 }
Ejemplo n.º 29
0
 /**
  * Returns the PUT response
  *
  * @param \PSX\Data\RecordInterface $record
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doUpdate(RecordInterface $record, Version $version)
 {
     $connectionId = (int) $this->getUriFragment('connection_id');
     $connection = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Connection')->get($connectionId);
     if (!empty($connection)) {
         $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Connection')->update(array('id' => $connection->getId(), 'name' => $record->getName(), 'class' => $record->getClass(), 'config' => $record->getConfig()->getRecordInfo()->getData()));
         return array('success' => true, 'message' => 'Connection successful updated');
     } else {
         throw new StatusCode\NotFoundException('Could not find connection');
     }
 }
Ejemplo n.º 30
0
 public function delete(RecordInterface $record)
 {
     if ($record->hasFields('id')) {
         $con = new Condition(array('serviceId', '=', $record->id));
         // check whether page exists wich uses this service
         if ($this->sql->count($this->registry['table.content_page'], $con) > 0) {
             throw new Exception('Page exists wich uses this service');
         }
         // check whether services exist wich depend on this service
         // @todo
         $con = new Condition(array('id', '=', $record->id));
         $this->table->delete($con);
         $this->notify(RecordAbstract::DELETE, $record);
         return $record;
     } else {
         throw new Exception('Missing field in record');
     }
 }