Ejemplo n.º 1
0
 public function createIssue(IncidentInterface $incident)
 {
     $description = 'Se nos informó que el host %s fue detectado en un incidente del tipo "%s".';
     $uploadFile = array();
     if (file_exists($this->evidence_directory . $incident->getEvidenceFilePath(true))) {
         $upload = json_decode($this->getClient()->api('attachment')->upload(file_get_contents($this->evidence_directory . $incident->getEvidenceFilePath(true))));
         $uploadFile = array(array('token' => $upload->upload->token, 'filename' => $incident->getEvidenceFilePath(), 'description' => 'Evidence file: ' . $incident->getEvidenceFilePath(), 'content_type' => mime_content_type($this->evidence_directory . $incident->getEvidenceFilePath(true))));
     }
     $issue = $this->getClient()->api('issue')->create(array('project_id' => $this->project_id, 'subject' => sprintf('Host %s en incidente "%s"', $incident->getHostAddress(), $incident->getType()), 'description' => sprintf($description, $incident->getHostAddress(), $incident->getType()), 'category_id' => $this->getClient()->api('issue_category')->getIdByName($this->project_id, $incident->getType()->getName()), 'tracker_id' => $this->getClient()->api('tracker')->getIdByName($this->tracker_name), 'watcher_user_ids' => $this->getClient()->api('user')->getIdByUsername('cert'), 'uploads' => $uploadFile));
     $incident->setRedmineIssue($issue);
     return $issue;
 }
 public function uploadEvidenceFile(IncidentInterface $incident)
 {
     //        if (null === $incident->getEvidenceFile()) {
     //            return;
     //        }
     // if there is an error when moving the file, an exception will
     // be automatically thrown by move(). This will properly prevent
     // the entity from being persisted to the database on error
     $uploadDir = $this->getUploadDirectory() . $incident->getEvidenceSubDirectory();
     if (!file_exists($uploadDir)) {
         if (!mkdir($uploadDir, 0777, true)) {
             die('Failed to create folders...');
         }
     }
     if ($incident->getEvidenceFile()) {
         $incident->getEvidenceFile()->move($uploadDir, $incident->getEvidenceFilePath());
     }
     // check if we have an old image
     //        if ($incident->getEvidenceFileTemp()) {
     //            // delete the old image
     //            unlink($this->getUploadDirectory() . $incident->getEvidenceFileTemp());
     //            // clear the temp image path
     //            $incident->setEvidenceFileTemp(null);
     //        }
 }