PHP code example of comoco / trac-client-php

1. Go to this page and download the library: Download comoco/trac-client-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

comoco / trac-client-php example snippets




use Comoco\TracClientPhp\Client as TracClient;

$api_url = "http://trac.local/login/jsonrpc";
$username = '<your username>';
$password = '<your password>';

$tracClient = new TracClient($api_url, $username, $password);
$ticket_id = $tracClient->createTicket('my first ticket', 'ticket content', [
    'owner' => 'bob',
    'cc' => 'alice, web',
    'priority' => 'minor'
]);
$tracClient->uploadAttachment($ticket_id, 'example.xml', 'is a example file', "/tmp/example.xml");
$tracClient->addComment($ticket_id, 'It is great!');
$tracClient->resolveTicket($ticket_id, 'ok', 'fixed')


$ticket_ids = $tracClient->getUserTicketIds('bob', ['accepted', 'assigned'], 50);

$ticket_id = 1;
$ticket_info = $tracClient->getTicketInfo($ticket_id);

$ticket_id = $tracClient->createTicket('my first ticket', 'it is a example ticket', [
    'owner' => 'bob',
    'cc' => 'alice, jack',
    'priority' => 'minor'
]);

$ticket_id = 1;
$tracClient->updateTicket($ticket_id, 'change ticket content', [
    'summary' => 'my first ticket v2',
    'description' => 'it is a example ticket v2',
    'cc' => 'alice, jack, ellen'
]);

$ticket_id = 1;
$tracClient->acceptTicket($ticket_id, 'accept the ticket');

$ticket_id = 1;
$tracClient->reassignUser($ticket_id, 'alice', 'assign ticket to alice');

$ticket_id = 1;
$tracClient->resolveTicket($ticket_id, 'close ticket', 'fixed');

$ticket_id = 1;
$tracClient->reopenTicket($ticket_id, 'reopen the ticket');

$ticket_id = 1;
$comments = $tracClient->getComments($ticket_id);

$ticket_id = 1;
$attachments = $tracClient->listAttachments($ticket_id);

$ticket_id = 1;
$filename = 'example.xml';
$description = 'demo xml';
$file_path = '/tmp/example.xml';
$tracClient->uploadAttachment($ticket_id, $filename, $description, $file_path)

$ticket_id = 1;
$filename = 'example.xml';
$save_path = '/tmp/example.xml';
$tracClient->downloadAttachment($ticket_id, $filename, $save_path)

$ticket_id = 1;
$filename = 'example.xml';
$tracClient->deleteAttachment($ticket_id, $filename)