Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
ed159f8a
Commit
ed159f8a
authored
12 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Rename TicketController to TicketApiController
Add special case and helper method to process emails
parent
28cf0332
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/urls.conf.php
+3
-3
3 additions, 3 deletions
api/urls.conf.php
include/api.tickets.php
+51
-35
51 additions, 35 deletions
include/api.tickets.php
with
54 additions
and
38 deletions
api/urls.conf.php
+
3
−
3
View file @
ed159f8a
<?php
# What about patterns("api
/
ticket.php:TicketController", ...) since if the
# What about patterns("api
.
ticket
s
.php:Ticket
Api
Controller", ...) since if the
# class is given as the prefix, it isn't defined in more than one file. This
# would allow for speficying imports only if an item is defined in a
# different class (with the array("class", "method") syntax)
return
patterns
(
"
api.ticket.php:TicketController
"
,
url_post
(
"^/tickets\.(?P<format>xml|json)$"
,
"
create
"
)
return
patterns
(
'
api.ticket
s
.php:Ticket
Api
Controller
'
,
url_post
(
"^/tickets\.(?P<format>xml|json
|email
)$"
,
'
create
'
)
);
?>
This diff is collapsed.
Click to expand it.
include/api.tickets.php
+
51
−
35
View file @
ed159f8a
<?php
include_once
"include/
class.api.php
"
;
include_once
"include/
class.ticket.php
"
;
include_once
INCLUDE_DIR
.
'
class.api.php
'
;
include_once
INCLUDE_DIR
.
'
class.ticket.php
'
;
class
TicketController
extends
ApiController
{
class
Ticket
Api
Controller
extends
ApiController
{
# Supported arguments -- anything else is an error. These items will be
# inspected _after_ the fixup() method of the ApiXxxDataParser classes
...
...
@@ -26,53 +26,69 @@ class TicketController extends ApiController {
function
create
(
$format
)
{
if
(
!
(
$key
=
$this
->
get
ApiKey
())
||
!
$key
->
canCreateTickets
())
Http
::
response
(
401
,
'API key not authorized'
);
if
(
!
(
$key
=
$this
->
require
ApiKey
())
||
!
$key
->
canCreateTickets
())
return
$this
->
exerr
(
401
,
'API key not authorized'
);
# Parse request body
$data
=
$this
->
getRequest
(
$format
);
if
(
$format
==
"xml"
)
$data
=
$data
[
"ticket"
];
$ticket
=
null
;
if
(
!
strcasecmp
(
$format
,
'email'
))
{
# Handle remote piped emails - could be a reply...etc.
$ticket
=
$this
->
processEmail
();
}
else
{
# Parse request body
$ticket
=
$this
->
createTicket
(
$this
->
getRequest
(
$format
));
}
if
(
!
$ticket
)
return
$this
->
exerr
(
500
,
"Unable to create new ticket: unknown error"
);
$this
->
response
(
201
,
$ticket
->
getExtId
());
}
/* private helper functions */
function
createTicket
(
$data
)
{
# Pull off some meta-data
$alert
=
$data
[
'alert'
]
?
$data
[
'alert'
]
:
true
;
$alert
=
$data
[
'alert'
]
?
$data
[
'alert'
]
:
true
;
$autorespond
=
$data
[
'autorespond'
]
?
$data
[
'autorespond'
]
:
true
;
$source
=
$data
[
'source'
]
?
$data
[
'source'
]
:
'API'
;
$attachments
=
$data
[
'attachments'
]
?
$data
[
'attachments'
]
:
array
();
# TODO: Handle attachment encoding (base64)
foreach
(
$attachments
as
$filename
=>&
$info
)
{
if
(
$info
[
"encoding"
]
==
"base64"
)
{
# XXX: May fail on large inputs. See
# http://us.php.net/manual/en/function.base64-decode.php#105512
if
(
!
(
$info
[
"data"
]
=
base64_decode
(
$info
[
"data"
],
true
)))
Http
::
response
(
400
,
sprintf
(
"%s: Poorly encoded base64 data"
,
$info
[
'name'
]));
}
$info
[
'size'
]
=
strlen
(
$info
[
'data'
]);
}
$data
[
'source'
]
=
$data
[
'source'
]
?
$data
[
'source'
]
:
'API'
;
# Create the ticket with the data (attempt to anyway)
$errors
=
array
();
$ticket
=
Ticket
::
create
(
$data
,
$errors
,
$source
,
$autorespond
,
$alert
);
$ticket
=
Ticket
::
create
(
$data
,
$errors
,
$data
[
'source'
],
$autorespond
,
$alert
);
# Return errors (?)
if
(
count
(
$errors
))
{
Http
::
response
(
400
,
"Unable to create new ticket: validation errors:
\n
"
.
Format
::
array_implode
(
": "
,
"
\n
"
,
$errors
));
if
(
isset
(
$errors
[
'errno'
])
&&
$errors
[
'errno'
]
==
403
)
return
$this
->
exerr
(
403
,
'Ticket denied'
);
else
return
$this
->
exerr
(
400
,
"Unable to create new ticket: validation errors:
\n
"
.
Format
::
array_implode
(
": "
,
"
\n
"
,
$errors
)
);
}
elseif
(
!
$ticket
)
{
Http
::
response
(
500
,
"Unable to create new ticket: unknown error"
);
return
$this
->
exerr
(
500
,
"Unable to create new ticket: unknown error"
);
}
# Save attachment(s)
foreach
(
$
attachments
as
&
$info
)
$ticket
->
save
Attachment
(
$
info
,
$ticket
->
getLastMsgId
(),
"M"
);
if
(
$data
[
'
attachments
'
]
)
$ticket
->
import
Attachment
s
(
$
data
[
'attachments'
]
,
$ticket
->
getLastMsgId
(),
'M'
);
# All done. Return HTTP/201 --> Created
Http
::
response
(
201
,
$ticket
->
getExtId
());
return
$ticket
;
}
function
processEmail
()
{
$data
=
$this
->
getEmailRequest
();
if
(
$data
[
'ticketId'
]
&&
(
$ticket
=
Ticket
::
lookup
(
$data
[
'ticketId'
])))
{
if
((
$msgid
=
$ticket
->
postMessage
(
$data
,
'Email'
)))
return
$ticket
;
}
return
$this
->
createTicket
(
$data
);
}
}
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment