Browse Source

pepepepe! King of monsters!

master
Mikhail Grebenkin 4 years ago
parent
commit
72f9491787
2 changed files with 27 additions and 33 deletions
  1. +20
    -28
      redmine.php
  2. +7
    -5
      tester.php

+ 20
- 28
redmine.php View File

@ -21,11 +21,11 @@ class class_redmine {
$upload_url = $this->redmine_url.'uploads.json?key='.$this->redmine_key; $upload_url = $this->redmine_url.'uploads.json?key='.$this->redmine_key;
$request['type'] = 'post'; $request['type'] = 'post';
$request['content_type'] = 'application/octet-stream'; $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 $issue_id numeric id of issue to attach file
* @param string $filename name of file * @param string $filename name of file
@ -56,11 +56,11 @@ class class_redmine {
return file_get_contents($file_url); return file_get_contents($file_url);
} else { } else {
$at_url = $this->redmine_url.'attachments/'.$attachment_id.'.json?key='.$this->redmine_key; $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) { if (!$at_descr) {
return null; return null;
} }
var_dump($at_descr);
$file_url = $this->redmine_url.'attachments/download/'. $file_url = $this->redmine_url.'attachments/download/'.
$attachment_id.'/'.$at_descr->attachment->filename.'?key='.$this->redmine_key; $attachment_id.'/'.$at_descr->attachment->filename.'?key='.$this->redmine_key;
return file_get_contents($file_url); return file_get_contents($file_url);
@ -70,7 +70,7 @@ class class_redmine {
/** /**
* Create issue * 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 * @return mixed $issue - new data
*/ */
function create_issue($post_data) { function create_issue($post_data) {
@ -86,12 +86,13 @@ class class_redmine {
* @param string $issue_id numeric issue id * @param string $issue_id numeric issue id
* @param string $project_id numeric project id * @param string $project_id numeric project id
* @param array $inc array of string with options to include. Example: array( 0 => "journals", 1 => "attachments" ); * @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()) { function get_issue(string $issue_id='',string $project_id='', array $inc=array()) {
if (count($inc) > 0) { if (count($inc) > 0) {
$inc = implode(",", $inc); $inc = implode(",", $inc);
$inc = '&include='.$inc; $inc = '&include='.$inc;
var_dump($inc);
} else { } else {
$inc = ''; $inc = '';
} }
@ -106,22 +107,21 @@ class class_redmine {
} }
/** /**
* get issue * attach to issue
* *
* @param string $issue_id digits only issue id * @param string $issue_id digits only issue id
* @param string $upload_token digits only project id * @param string $upload_token digits only project id
* @param string $upload_token * @param string $upload_token
* @param array $inc array of string with options to include. Example: array( 0 => "journals", 1 => "attachments" ); * @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) { 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; $issue_url = $this->redmine_url.'issues/'.$issue_id.'.json?key='.$this->redmine_key;
$update = array( "issue" => array( $update = array( "issue" => array( "uploads"=> array( 0 => array("token" => $upload_token,
"uploads"=> array( 0 => array("token" => $upload_token, "filename" => $filename,
"filename" => $filename, "content_type"=> $filetype )
"content_type"=> $filetype) )
), )
)
); );
$request['type'] = 'put'; $request['type'] = 'put';
$request['content_type'] = 'application/json'; $request['content_type'] = 'application/json';
@ -204,27 +204,18 @@ class class_redmine {
return $this->curl_redmine($contact_url, $request , $post_data); 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_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 = "<?xml version=\"1.0\"?> $issue_xml = "<?xml version=\"1.0\"?>
<ticket> <ticket>
<issue> <issue>
<project_id></project_id> <project_id>14</project_id>
<tracker_id>3</tracker_id> <tracker_id>3</tracker_id>
<subject>$subject</subject> <subject>$subject</subject>
<description>$description</description> <description>$description</description>
</issue> </issue>
<contact> <contact>
<id>$contact_id</id> <email>$contact_email</email>
</contact> </contact>
</ticket>"; </ticket>";
$request['type'] = 'post'; $request['type'] = 'post';
@ -283,10 +274,11 @@ class class_redmine {
//Execute the action to login //Execute the action to login
$postResult = curl_exec($ch); $postResult = curl_exec($ch);
echo(curl_getinfo($ch, CURLINFO_HTTP_CODE)); // echo(curl_getinfo($ch, CURLINFO_HTTP_CODE));
// for debug purposes // for debug purposes
// if($postResult == false){ return $info = curl_getinfo($ch);} // 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; return $response;
} }


+ 7
- 5
tester.php View File

@ -49,12 +49,14 @@ $test_contact = array("contact" => array("first_name" => "Test testing",
//$res = $obj_redmine->get_contact_id("3373", true); //$res = $obj_redmine->get_contact_id("3373", true);
//var_dump($res); //var_dump($res);
$inc=array(0 => "contacts"); //$inc[]= "contacts";
$res = $obj_redmine->get_issue($issue_id="10442", '', $inc); //$inc[]= "relations";
//var_dump($res); //$res = $obj_redmine->get_issue($issue_id="11380", "",$inc=$inc);
$res = $obj_redmine->create_ticket("3373", "One more test", "test test one more"); $res = $obj_redmine->get_contact_id("3373", true);
var_dump($res); 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"); //$filecontent = file_get_contents("screenshot.png");
//$token = $obj_redmine->get_upload_token($filecontent); //$token = $obj_redmine->get_upload_token($filecontent);


|||||||
x
 
000:0
Loading…
Cancel
Save

Powered by TurnKey Linux.