[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/chatlog/conduit/ -> ChatLogRecordConduitAPIMethod.php (source)

   1  <?php
   2  
   3  final class ChatLogRecordConduitAPIMethod extends ChatLogConduitAPIMethod {
   4  
   5    public function getAPIMethodName() {
   6      return 'chatlog.record';
   7    }
   8  
   9    public function getMethodStatus() {
  10      return self::METHOD_STATUS_UNSTABLE;
  11    }
  12  
  13    public function getMethodDescription() {
  14      return 'Record chatter.';
  15    }
  16  
  17    public function defineParamTypes() {
  18      return array(
  19        'logs' => 'required list<dict>',
  20      );
  21    }
  22  
  23    public function defineReturnType() {
  24      return 'list<id>';
  25    }
  26  
  27    public function defineErrorTypes() {
  28      return array();
  29    }
  30  
  31    protected function execute(ConduitAPIRequest $request) {
  32      $logs = $request->getValue('logs');
  33      if (!is_array($logs)) {
  34        $logs = array();
  35      }
  36  
  37      $template = new PhabricatorChatLogEvent();
  38      $template->setLoggedByPHID($request->getUser()->getPHID());
  39  
  40      $objs = array();
  41      foreach ($logs as $log) {
  42        $channel_name = idx($log, 'channel');
  43        $service_name = idx($log, 'serviceName');
  44        $service_type = idx($log, 'serviceType');
  45  
  46        $channel = id(new PhabricatorChatLogChannel())->loadOneWhere(
  47          'channelName = %s AND serviceName = %s AND serviceType = %s',
  48          $channel_name,
  49          $service_name,
  50          $service_type);
  51  
  52        if (!$channel) {
  53          $channel = id(new PhabricatorChatLogChannel())
  54            ->setChannelName($channel_name)
  55            ->setserviceName($service_name)
  56            ->setServiceType($service_type)
  57            ->setViewPolicy(PhabricatorPolicies::POLICY_USER)
  58            ->setEditPolicy(PhabricatorPolicies::POLICY_USER)
  59            ->save();
  60        }
  61  
  62        $obj = clone $template;
  63        $obj->setChannelID($channel->getID());
  64        $obj->setType(idx($log, 'type'));
  65        $obj->setAuthor(idx($log, 'author'));
  66        $obj->setEpoch(idx($log, 'epoch'));
  67        $obj->setMessage(idx($log, 'message'));
  68        $obj->save();
  69  
  70        $objs[] = $obj;
  71      }
  72  
  73      return array_values(mpull($objs, 'getID'));
  74    }
  75  
  76  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1