/**
  * Method to update data for an issue from GitHub
  *
  * @param   integer  $id  The comment ID
  *
  * @return  boolean  True on success
  *
  * @since   1.0
  */
 protected function updateComment($id)
 {
     // Try to render the comment with GitHub markdown
     $parsedText = $this->parseText($this->hookData->comment->body);
     // Only update fields that may have changed, there's no API endpoint to show that so make some guesses
     $data = array();
     $data['activities_id'] = $id;
     $data['text'] = $parsedText;
     $data['text_raw'] = $this->hookData->comment->body;
     try {
         $table = new ActivitiesTable($this->db);
         $table->load(array('activities_id' => $id));
         $table->save($data);
     } catch (\Exception $e) {
         $this->logger->error('Error updating the database for comment ' . $id . ':' . $e->getMessage());
         $this->getContainer()->get('app')->close();
     }
     $this->triggerEvent('onCommentAfterUpdate', $table);
     // Store was successful, update status
     $this->logger->info(sprintf('Updated comment %s/%s #%d to the tracker.', $this->project->gh_user, $this->project->gh_project, $id));
     return true;
 }
Beispiel #2
0
 /**
  * Compute the changes.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  */
 private function processChanges()
 {
     $changes = array();
     foreach ($this as $fName => $field) {
         if (!$this->{$fName} && !$this->oldObject->{$fName}) {
             // Both values are "empty"
             continue;
         }
         if ($this->{$fName} != $this->oldObject->{$fName}) {
             $change = new \stdClass();
             $change->name = $fName;
             $change->old = $this->oldObject->{$fName};
             $change->new = $this->{$fName};
             switch ($fName) {
                 case 'modified_date':
                 case 'modified_by':
                     // Expected change ;)
                     break;
                 case 'description':
                     // Do nothing
                     break;
                 default:
                     $changes[] = $change;
                     break;
             }
         }
     }
     if ($changes) {
         $data = array();
         $data['event'] = 'change';
         $data['created_date'] = $this->modified_date;
         $data['user'] = $this->modified_by;
         $data['issue_number'] = (int) $this->issue_number;
         $data['project_id'] = (int) $this->project_id;
         $data['text'] = json_encode($changes);
         $table = new ActivitiesTable($this->db);
         $table->save($data);
     }
     return $this;
 }
 /**
  * Add a new event and store it to the database.
  *
  * @param   string   $event       The event name.
  * @param   string   $dateTime    Date and time.
  * @param   string   $userName    User name.
  * @param   integer  $projectId   Project id.
  * @param   integer  $itemNumber  THE item number.
  * @param   integer  $commentId   The comment id
  * @param   string   $text        The parsed html comment text.
  * @param   string   $textRaw     The raw comment text.
  *
  * @return  $this
  *
  * @since   1.0
  */
 protected function addActivityEvent($event, $dateTime, $userName, $projectId, $itemNumber, $commentId = null, $text = '', $textRaw = '')
 {
     $data = array();
     $date = new Date($dateTime);
     $data['created_date'] = $date->format($this->db->getDateFormat());
     $data['event'] = $event;
     $data['user'] = $userName;
     $data['project_id'] = (int) $projectId;
     $data['issue_number'] = (int) $itemNumber;
     $data['gh_comment_id'] = (int) $commentId;
     $data['text'] = $text;
     $data['text_raw'] = $textRaw;
     try {
         $activity = new ActivitiesTable($this->db);
         $activity->save($data);
     } catch (\Exception $exception) {
         $this->logger->info(sprintf('Error storing %s activity to the database (ProjectId: %d, ItemNo: %d): %s', $event, $projectId, $itemNumber, $exception->getMessage()));
         $this->getContainer()->get('app')->close();
     }
     return $this;
 }
Beispiel #4
0
 /**
  * Process the change in category for issues.
  *
  * @param   array  $src  The source, should include: $src['issue_number'], the issue's number; $src['project_id'],
  *                       the issue's project id; $src['old'] and $src['new'] for old and new categories; $src['modified_by'],
  *                       modified username.
  *
  * @since   1.0
  *
  * @return  $this
  */
 private function processChanges(array $src)
 {
     $date = new Date();
     $date = $date->format($this->getDb()->getDateFormat());
     $change = new \stdClass();
     $change->name = 'category';
     $change->old = array();
     $change->new = array();
     foreach ($src['old'] as $key => $old) {
         $oldCategory = $this->getItem($old);
         $change->old[$key]['title'] = $oldCategory->title;
         $change->old[$key]['color'] = $oldCategory->color;
     }
     foreach ($src['new'] as $key => $new) {
         $newCategory = $this->getItem($new);
         $change->new[$key]['title'] = $newCategory->title;
         $change->new[$key]['color'] = $newCategory->color;
     }
     $data = array();
     $data['event'] = 'change';
     $data['created_date'] = $date;
     $data['user'] = $src['modified_by'];
     $data['issue_number'] = (int) $src['issue_number'];
     $data['project_id'] = (int) $src['project_id'];
     $data['text'] = json_encode(array($change));
     $table = new ActivitiesTable($this->getDb());
     $table->save($data);
     return $this;
 }