From 72f949178733e76bb0884a17625fc0c80d5e63e1 Mon Sep 17 00:00:00 2001 From: Mikhail Grebenkin Date: Wed, 19 Aug 2020 14:28:10 +0300 Subject: [PATCH] pepepepe! King of monsters! --- redmine.php | 48 ++++++++++++++++++++---------------------------- tester.php | 12 +++++++----- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/redmine.php b/redmine.php index f6e3b0f..429e09b 100644 --- a/redmine.php +++ b/redmine.php @@ -21,11 +21,11 @@ class class_redmine { $upload_url = $this->redmine_url.'uploads.json?key='.$this->redmine_key; $request['type'] = 'post'; $request['content_type'] = 'application/octet-stream'; - return $token = $this->curl_redmine($upload_url,$request,$filecontent); + return $this->curl_redmine($upload_url,$request,$filecontent); } /** - * Uploads an attachment, attaches it to an issue and returns updated issue + * Uploads an attachment, attaches it to an issue and returns json-decoded updated issue * * @param string $issue_id numeric id of issue to attach file * @param string $filename name of file @@ -56,11 +56,11 @@ class class_redmine { return file_get_contents($file_url); } else { $at_url = $this->redmine_url.'attachments/'.$attachment_id.'.json?key='.$this->redmine_key; - $at_descr = $this->curl_redmine($at_url); + $api_resp = $this->curl_redmine($at_url); + $at_descr = $api_resp[0]; if (!$at_descr) { return null; } - var_dump($at_descr); $file_url = $this->redmine_url.'attachments/download/'. $attachment_id.'/'.$at_descr->attachment->filename.'?key='.$this->redmine_key; return file_get_contents($file_url); @@ -70,7 +70,7 @@ class class_redmine { /** * Create issue * - * @param $post_data - string to post to redmine (need to update) + * @param $post_data - string to post to redmine (needs to update) * @return mixed $issue - new data */ function create_issue($post_data) { @@ -86,12 +86,13 @@ class class_redmine { * @param string $issue_id numeric issue id * @param string $project_id numeric project id * @param array $inc array of string with options to include. Example: array( 0 => "journals", 1 => "attachments" ); - * @return mixed $issue - new data + * @return mixed $issue - json data of issue */ function get_issue(string $issue_id='',string $project_id='', array $inc=array()) { if (count($inc) > 0) { $inc = implode(",", $inc); $inc = '&include='.$inc; + var_dump($inc); } else { $inc = ''; } @@ -106,22 +107,21 @@ class class_redmine { } /** - * get issue + * attach to issue * * @param string $issue_id digits only issue id * @param string $upload_token digits only project id * @param string $upload_token * @param array $inc array of string with options to include. Example: array( 0 => "journals", 1 => "attachments" ); - * @return mixed $issue - new data + * @return array 0 => http responce; 1 => issue - new data */ function attach_to_issue(string $issue_id,string $upload_token, string $filename, string $filetype) { $issue_url = $this->redmine_url.'issues/'.$issue_id.'.json?key='.$this->redmine_key; - $update = array( "issue" => array( - "uploads"=> array( 0 => array("token" => $upload_token, - "filename" => $filename, - "content_type"=> $filetype) - ), - ) + $update = array( "issue" => array( "uploads"=> array( 0 => array("token" => $upload_token, + "filename" => $filename, + "content_type"=> $filetype ) + ) + ) ); $request['type'] = 'put'; $request['content_type'] = 'application/json'; @@ -204,27 +204,18 @@ class class_redmine { return $this->curl_redmine($contact_url, $request , $post_data); } - function create_ticket(string $contact_id, string $subject, string $description) { + function create_ticket(string $contact_email, string $subject, string $description) { $issue_url = $this->redmine_url."helpdesk/create_ticket.xml?key=".$this->redmine_key; - $issue = array( "ticket" => array ( - "issue" => array( - "project_id" => "xtesx", - "tracker_id" => "3", - "subject" => $subject, - "description"=> $description, - ), - "contact" => array ("id" => $contact_id), - )); $issue_xml = " - + 14 3 $subject $description - $contact_id + $contact_email "; $request['type'] = 'post'; @@ -283,10 +274,11 @@ class class_redmine { //Execute the action to login $postResult = curl_exec($ch); - echo(curl_getinfo($ch, CURLINFO_HTTP_CODE)); + // echo(curl_getinfo($ch, CURLINFO_HTTP_CODE)); // for debug purposes // if($postResult == false){ return $info = curl_getinfo($ch);} - $response = json_decode($postResult); + $response = array( 0 => curl_getinfo($ch, CURLINFO_HTTP_CODE), + 1 => json_decode($postResult)); return $response; } diff --git a/tester.php b/tester.php index 432d75a..2617515 100644 --- a/tester.php +++ b/tester.php @@ -49,12 +49,14 @@ $test_contact = array("contact" => array("first_name" => "Test testing", //$res = $obj_redmine->get_contact_id("3373", true); //var_dump($res); -$inc=array(0 => "contacts"); -$res = $obj_redmine->get_issue($issue_id="10442", '', $inc); -//var_dump($res); -$res = $obj_redmine->create_ticket("3373", "One more test", "test test one more"); - +//$inc[]= "contacts"; +//$inc[]= "relations"; +//$res = $obj_redmine->get_issue($issue_id="11380", "",$inc=$inc); +$res = $obj_redmine->get_contact_id("3373", true); var_dump($res); +// $res = $obj_redmine->create_ticket("besco@yabesco.ru", "One more test", "test test one more"); + +// var_dump($res); //$filecontent = file_get_contents("screenshot.png"); //$token = $obj_redmine->get_upload_token($filecontent);