mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-30 17:25:11 +02:00
commit
fb7693d77e
@ -50,7 +50,6 @@ class CreateController extends Controller {
|
||||
|
||||
$ticket = new Ticket();
|
||||
$ticket->setProperties(array(
|
||||
'ticketId' => '',
|
||||
'title' => $this->title,
|
||||
'content' => $this->content,
|
||||
'language' => $this->language,
|
||||
|
@ -10,4 +10,7 @@ class Hashing {
|
||||
public static function generateRandomToken() {
|
||||
return md5(uniqid(rand()));
|
||||
}
|
||||
public static function getRandomTicketNumber($min,$max) {
|
||||
return rand($min,$max);
|
||||
}
|
||||
}
|
@ -16,6 +16,9 @@ abstract class DataStore {
|
||||
|
||||
return ($bean) ? new static($bean) : new NullDataStore();
|
||||
}
|
||||
public static function count() {
|
||||
return RedBean::count(static::TABLE);
|
||||
}
|
||||
|
||||
private static function validateProp($propToValidate) {
|
||||
$validProp = false;
|
||||
|
@ -26,18 +26,35 @@ class Ticket extends DataStore {
|
||||
public static function getTicket($value, $property = 'id') {
|
||||
return parent::getDataStore($value, $property);
|
||||
}
|
||||
|
||||
|
||||
public function getDefaultProps() {
|
||||
return array(
|
||||
'owner' => null
|
||||
'owner' => null,
|
||||
'ticketNumber' => $this->generateUniqueTicketNumber()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function store() {
|
||||
parent::store();
|
||||
|
||||
|
||||
if ($this->author instanceof User) {
|
||||
$this->author->store();
|
||||
}
|
||||
}
|
||||
}
|
||||
public function generateUniqueTicketNumber() {
|
||||
$ticketQuantity = Ticket::count('ticket');
|
||||
$minValue = 100000;
|
||||
$maxValue = 999999;
|
||||
|
||||
if ($ticketQuantity === 0) {
|
||||
$ticketNumber = Hashing::getRandomTicketNumber($minValue, $maxValue);
|
||||
} else {
|
||||
$firstTicketNumber = Ticket::getTicket(1)->ticketNumber;
|
||||
$gap = 176611;
|
||||
|
||||
$ticketNumber = ($firstTicketNumber - $minValue + $ticketQuantity * $gap) % ($maxValue - $minValue + 1) + $minValue;
|
||||
}
|
||||
|
||||
return $ticketNumber;
|
||||
}
|
||||
}
|
||||
|
@ -108,8 +108,42 @@ describe '/ticket/create' do
|
||||
(ticket['closed']).should.equal('0')
|
||||
(ticket['department_id']).should.equal('1')
|
||||
(ticket['author_id']).should.equal($csrf_userid)
|
||||
(ticket['ticket_number'].size).should.equal(6)
|
||||
|
||||
ticket_user_relation = $database.getRow('ticket_user','1','ticket_id')
|
||||
(ticket_user_relation['user_id']).should.equal($csrf_userid)
|
||||
end
|
||||
|
||||
it 'should set correct ticket number' do
|
||||
result = request('/ticket/create',{
|
||||
title: 'Winter is coming1',
|
||||
content: 'The north remembers',
|
||||
departmentId: 1,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
result = request('/ticket/create',{
|
||||
title: 'Winter is coming2',
|
||||
content: 'The north remembers',
|
||||
departmentId: 1,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
result = request('/ticket/create',{
|
||||
title: 'Winter is coming3',
|
||||
content: 'The north remembers',
|
||||
departmentId: 1,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
ticket0 = $database.getRow('ticket','Winter is coming','title')['ticket_number'].to_i
|
||||
ticket1 = $database.getRow('ticket','Winter is coming1','title')['ticket_number'].to_i
|
||||
ticket2 = $database.getRow('ticket','Winter is coming2','title')['ticket_number'].to_i
|
||||
ticket3 = $database.getRow('ticket','Winter is coming3','title')['ticket_number'].to_i
|
||||
|
||||
(ticket1).should.equal((ticket0 - 100000 + 1 * 176611) % 900000 + 100000)
|
||||
(ticket2).should.equal((ticket0 - 100000 + 2 * 176611) % 900000 + 100000)
|
||||
(ticket3).should.equal((ticket0 - 100000 + 3 * 176611) % 900000 + 100000)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user