/**
  * Update schemas of collection issue and issueActivity.
  */
 public function actionMigrate()
 {
     echo "Begin to update collection issue\n";
     // Update collection issue
     $issues = Issue::find()->all();
     foreach ($issues as &$issue) {
         $creator = $issue->creator;
         if (!$creator instanceof \mongoId) {
             $issue->creator = new \MongoId($creator['id']);
         }
         if (!isset($issue->origin)) {
             $issue->origin = IssueUser::HELPDESK;
         }
         if (!empty($issue->assignee)) {
             $assignee = $issue->assignee;
             if (!$assignee instanceof \MongoId) {
                 $issue->assignee = new \MongoId($assignee['id']);
             }
         }
         $issue->update();
     }
     echo "Successfully updated collection issue.\n";
     echo "Begin to update collection issueActivity\n";
     // Update collection issueActivity
     $issueActivities = IssueActivity::find()->all();
     foreach ($issueActivities as $activity) {
         $creator = $activity->creator;
         if (!$creator instanceof \mongoId) {
             $activity->creator = new \MongoId($creator['id']);
         }
         $activity->save();
     }
     echo "Successfully updated collection issueActivity.\n";
     echo "Complete migration.\n";
 }
 /**
  * Comments a help desk issue.
  *
  * <b>Request Type</b>: POST<br/><br/>
  * <b>Request Endpoint</b>:http://{server-domain}/api/chat/issue/comment/{id}<br/><br/>
  * <b>Content-type</b>: application/json<br/><br/>
  * <b>Summary</b>: This api is used for help desk to comment an issue.
  * <br/><br/>
  *
  * <b>Request Params</b>:<br/>
  *     accesstoken: string, the access token<br/>
  *     description: string, the issue's comment<br/>
  *     <br/><br/>
  *
  * <b>Response Params:</b><br/>
  *     return new comment activity, if success, ortherwise, throw an invalid parameters exception.<br/>
  *     <br/><br/>
  *
  * <b>Request Example:</b><br/>
  * <pre>
  * {
  *     "accesstoken" : "eeaa31a8-1d55-247e-70a2-bc9af23918ec",
  *     "id": "55c446c60faf303f0b8b456a",
  *     "description": "This is a comment from help desk."
  * }
  * </pre>
  * <br/><br/>
  *
  * <b>Response Example</b>:<br/>
  * <pre>
  * {
  *     "id": "55c446c60faf303f0b8b456a",
  *     "description": "This is a comment from help desk.",
  *     "action": comment,
  *     "creator": {
  *         "id": "55c446c60faf303f0b8b456a",
  *         "name": "byronzhang",
  *         "email": "*****@*****.**"
  *         "avatar": "http://vincenthou.qiniudn.com/52a82080e78c991bc0ca3d3a.png"
  *         ...
  *     },
  *     "createdAt": 1439116638254,
  *    "issueId": "55c446c60faf303f0b8b4fe3"
  *
  * }
  * </pre>
  */
 public function actionComment($id)
 {
     $issue = Issue::findByPk($id);
     if (empty($issue)) {
         throw new InvalidParameterException(['issue' => Yii::t('issue', 'issue_id_does_not_exist')]);
     } else {
         $params = $this->getParams();
         if (!isset($params['description']) || empty($params['description'])) {
             throw new InvalidParameterException(['issue' => Yii::t('issue', 'comment_can_not_be_empty')]);
         } else {
             $description = $params['description'];
             unset($issue->status);
             $issueActivity = $this->_createActivity($issue, $description);
             $issueActivity->creator = $issueActivity->creatorDetail;
             $data = $issueActivity->toArray();
             $this->_sendTuisongbaoEvent($params, Issue::EVENT_COMMENT_ISSUE, $data, $issue->accountId);
             return $data;
         }
     }
 }