Skip to content

Commit 6594f62

Browse files
ThomasAFinkAndrew Fink
and
Andrew Fink
authored
Hotfix Zms 2669 bug ticketprinter php memory (#477)
* limit one ticketprinter session per orga * fix unit test * fix unit test * fix unit test * fix unit test * change fixure * change fixure * add unit tests for ticketprinter in actions * add unit tests for ticketprinter in actions * add unit tests for ticketprinter in actions * add unit tests for ticketprinter in actions * add unit tests for ticketprinter in actions * add logging * fix zmsdb test * fix zmsdb test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * fix zmsapi test * change fixure * change fixure * change fixure * revert fixture * revert fixture * change fixure to scope * change fixure to scope * change fixure to scope * fix zmsapi and zmsdb unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests * fix zmstickprinter unit tests add logging * fix zmstickprinter unit tests add logging * fix zmstickprinter unit tests add logging * fix zmstickprinter unit tests add logging * fix zmstickprinter unit tests add logging * fix zmstickprinter exception unit tests * fix zmstickprinter exception unit tests * fix zmstickprinter exception unit tests * fix zmstickprinter exception unit tests * fix zmstickprinter exception unit tests * change fixure * fix zmstickprinter exception unit tests * fix zmstickprinter exception unit tests * fix zmstickprinter exception unit tests * remove tests * remove tests * remove tests --------- Co-authored-by: Andrew Fink <[email protected]>
1 parent 9839eac commit 6594f62

File tree

52 files changed

+145
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+145
-103
lines changed

.github/workflows/unit-tests.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
php_version: "8.0"
3838
- module: zmsstatistic
3939
php_version: "8.0"
40+
- module: zmsticketprinter
41+
php_version: "8.0"
4042

4143

4244
zmsapi-test:

zmsadmin/src/Zmsadmin/TicketprinterConfig.php

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public function readResponse(
6060
$departments->addEntity($department);
6161
}
6262

63+
error_log("hello");
64+
6365
return \BO\Slim\Render::withHtml(
6466
$response,
6567
'page/ticketprinterConfig.twig',

zmsadmin/tests/Zmsadmin/fixtures/GET_organisation_71_resolved3.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@
658658
{
659659
"enabled": "1",
660660
"reload": 30,
661-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
661+
"hash": "71abcdefghijklmnopqrstuvwxyz",
662662
"id": "1",
663663
"lastUpdate": "1477661416",
664664
"name": "Test Ticketprinter"

zmsadmin/tests/Zmsadmin/fixtures/GET_organisation_71_resolved5.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@
668668
{
669669
"enabled": "1",
670670
"reload": 30,
671-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
671+
"hash": "71abcdefghijklmnopqrstuvwxyz",
672672
"id": "1",
673673
"lastUpdate": "1477661416",
674674
"name": "Test Ticketprinter"

zmsadmin/tests/Zmsadmin/fixtures/GET_ownerlist.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@
21982198
{
21992199
"enabled": "1",
22002200
"reload": 30,
2201-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
2201+
"hash": "71abcdefghijklmnopqrstuvwxyz",
22022202
"id": "1",
22032203
"lastUpdate": "1477661416",
22042204
"name": "Test Ticketprinter"

zmsapi/src/Zmsapi/Helper/TicketprinterAccess.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function testTicketprinterIsProtectedEnabled($entity, $isProtectio
5353
}
5454

5555
public static function testTicketprinterValidHash($entity)
56-
{
56+
{
5757
if (isset($entity->id) &&
5858
$entity->id &&
5959
(new \BO\Zmsdb\Ticketprinter)->readByHash($entity->hash)->id != $entity->id) {

zmsapi/src/Zmsapi/OrganisationHash.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ public function readResponse(
2222
\Psr\Http\Message\ResponseInterface $response,
2323
array $args
2424
) {
25-
$ticketprinterName = Validator::param('name')->isString()->setDefault('')->getValue();
2625
\BO\Zmsdb\Connection\Select::getWriteConnection();
2726
$organisation = (new Query())->readEntity($args['id']);
2827
if (! $organisation) {
2928
throw new Exception\Organisation\OrganisationNotFound();
3029
}
30+
//$ticketprinterName = Validator::param('name')->isString()->setDefault('')->getValue();
31+
$ticketprinterName = "Ticket Printer for " . $organisation->name;
3132
$ticketprinter = (new Ticketprinter())->writeEntityWithHash($organisation->id, $ticketprinterName);
3233

3334
$message = Response\Message::create($request);

zmsapi/tests/Zmsapi/OrganisationHashTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public function testRendering()
1616

1717
public function testWithName()
1818
{
19-
$response = $this->render(['id' => 54], ['name' => 'unittest'], []); //Pankow
20-
$this->assertStringContainsString('"name":"unittest"', (string)$response->getBody());
19+
$response = $this->render(['id' => 54], ['name' => ''], []); //Pankow
20+
$this->assertStringContainsString('"name":"Ticket Printer for Pankow"', (string)$response->getBody());
2121
$this->assertTrue(200 == $response->getStatusCode());
2222
}
2323

zmsapi/tests/Zmsapi/TicketprinterGetTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class TicketprinterGetTest extends Base
88

99
public function testRendering()
1010
{
11-
$response = $this->render(['hash' => 'ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2'], [], []);
11+
$response = $this->render(['hash' => '71abcdefghijklmnopqrstuvwxyz'], [], []);
1212
$this->assertStringContainsString('ticketprinter.json', (string)$response->getBody());
1313
$this->assertTrue(200 == $response->getStatusCode());
1414
}
@@ -25,4 +25,4 @@ public function testEmpty()
2525
$this->expectException('\Exception');
2626
$this->render([], [], []);
2727
}
28-
}
28+
}

zmsapi/tests/Zmsapi/TicketprinterTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public function testRendering()
1111
$response = $this->render([], [
1212
'__body' => '{
1313
"enabled": true,
14-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
15-
"id": 1,
14+
"hash": "71abcdefghijklmnopqrstuvwxyz",
15+
"id": 8,
1616
"lastUpdate": 1447925326000,
1717
"name": "Eingangsbereich links",
1818
"buttons": [
@@ -56,8 +56,8 @@ public function testFromButtonList()
5656
'__body' => '{
5757
"buttonlist": "s141,l[http://www.berlin.de/|Portal+Berlin.de]",
5858
"enabled": true,
59-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
60-
"id": 1,
59+
"hash": "71abcdefghijklmnopqrstuvwxyz",
60+
"id": 8,
6161
"lastUpdate": 1447925326000,
6262
"name": "Eingangsbereich links"
6363
}'
@@ -74,7 +74,7 @@ public function testFromButtonListScopeFailed()
7474
'__body' => '{
7575
"buttonlist": "s139",
7676
"enabled": true,
77-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
77+
"hash": "71abcdefghijklmnopqrstuvwxyz",
7878
"id": 1,
7979
"lastUpdate": 1447925326000,
8080
"name": "Eingangsbereich links"
@@ -90,8 +90,8 @@ public function testMatchingFailed()
9090
'__body' => '{
9191
"buttonlist": "s106",
9292
"enabled": true,
93-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
94-
"id": 1,
93+
"hash": "71abcdefghijklmnopqrstuvwxyz",
94+
"id": 8,
9595
"lastUpdate": 1447925326000,
9696
"name": "Eingangsbereich links"
9797
}'
@@ -104,8 +104,8 @@ public function testEnableTicketprinter()
104104
'__body' => '{
105105
"buttonlist": "s141",
106106
"enabled": true,
107-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f3",
108-
"id": 2,
107+
"hash": "71abcdefghijklmnopqrstuvwxyz",
108+
"id": 8,
109109
"lastUpdate": 1447925326000,
110110
"name": "Eingangsbereich links"
111111
}'
@@ -131,7 +131,7 @@ public function testUnvalidHash()
131131
$this->render([], [
132132
'__body' => '{
133133
"buttonlist": "s141,l[http://www.berlin.de/|Portal+Berlin.de]",
134-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
134+
"hash": "71abcdefghijklmnopqrstuvwxyz",
135135
"id": 1234
136136
}'
137137
], []);
@@ -154,4 +154,4 @@ public function testNotFound()
154154
}'
155155
], []);
156156
}
157-
}
157+
}

zmsapi/tests/Zmsapi/TicketprinterWaitingnumberByClusterTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TicketprinterWaitingnumberByClusterTest extends Base
99
public function testRendering()
1010
{
1111
//Schöneberg with test scope ghostWorkstationCount of 3
12-
$response = $this->render(['id' => 4, 'hash' => 'ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2'], [], []);
12+
$response = $this->render(['id' => 4, 'hash' => '1abcdefghijklmnopqrstuvwxyz'], [], []);
1313
$this->assertStringContainsString('process.json', (string)$response->getBody());
1414
$this->assertStringContainsString('"id":"146"', (string)$response->getBody());
1515
$this->assertTrue(200 == $response->getStatusCode());
@@ -19,13 +19,13 @@ public function testClusterFailed()
1919
{
2020
$this->expectException('BO\Zmsapi\Exception\Cluster\ClusterNotFound');
2121
$this->expectExceptionCode(404);
22-
$this->render(['id' => 999, 'hash' => 'ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2'], [], []);
22+
$this->render(['id' => 999, 'hash' => '1abcdefghijklmnopqrstuvwxyz'], [], []);
2323
}
2424

2525
public function testProcessReserveFailed()
2626
{
2727
$this->expectException('BO\Zmsdb\Exception\Cluster\ScopesWithoutWorkstationCount');
2828
$this->expectExceptionCode(404);
29-
$this->render(['id' => 76, 'hash' => 'ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2'], [], []);
29+
$this->render(['id' => 76, 'hash' => '1abcdefghijklmnopqrstuvwxyz'], [], []);
3030
}
3131
}

zmsapi/tests/Zmsapi/TicketprinterWaitingnumberByScopeTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TicketprinterWaitingnumberByScopeTest extends Base
99
public function testRendering()
1010
{
1111
//Schöneberg with test scope ghostWorkstationCount of 3
12-
$response = $this->render(['id' => 146, 'hash' => 'ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2'], [], []);
12+
$response = $this->render(['id' => 146, 'hash' => '1abcdefghijklmnopqrstuvwxyz'], [], []);
1313
$this->assertStringContainsString('process.json', (string)$response->getBody());
1414
$this->assertStringContainsString('"id":"146"', (string)$response->getBody());
1515
$this->assertTrue(200 == $response->getStatusCode());
@@ -19,6 +19,6 @@ public function testScopeFailed()
1919
{
2020
$this->expectException('BO\Zmsapi\Exception\Scope\ScopeNotFound');
2121
$this->expectExceptionCode(404);
22-
$this->render(['id' => 999, 'hash' => 'ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2'], [], []);
22+
$this->render(['id' => 999, 'hash' => '1abcdefghijklmnopqrstuvwxyz'], [], []);
2323
}
2424
}

zmsapi/tests/Zmsapi/fixtures/GetOrganisation.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
"ticketprinters": [
2828
{
2929
"enabled": "1",
30-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
30+
"hash": "54abcdefghijklmnopqrstuvwxyz",
3131
"id": "1",
3232
"lastUpdate": "1477661416",
3333
"name": "Test Ticketprinter"
3434
}
3535
]
36-
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Start a transaction
2+
START TRANSACTION;
3+
4+
-- Drop all existing ticket printers in the `kiosk` table
5+
DELETE FROM `kiosk`;
6+
7+
-- Insert a new ticket printer for each organization
8+
INSERT INTO `kiosk` (`kundenid`, `organisationsid`, `timestamp`, `cookiecode`, `name`, `zugelassen`)
9+
SELECT
10+
`KundenID`,
11+
`OrganisationsID`,
12+
UNIX_TIMESTAMP() AS `timestamp`,
13+
CONCAT(`OrganisationsID`, 'abcdefghijklmnopqrstuvwxyz') AS `cookiecode`,
14+
CONCAT('Ticket Printer for ', `Organisationsname`) AS `name`,
15+
1 AS `zugelassen`
16+
FROM
17+
`organisation`;
18+
19+
-- Reset the AUTO_INCREMENT value if necessary
20+
ALTER TABLE `kiosk` AUTO_INCREMENT = 1;
21+
22+
-- Commit the transaction
23+
COMMIT;

zmsdb/src/Zmsdb/Ticketprinter.php

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ protected function readExceptions(Entity $ticketprinter)
122122
throw new Exception\Scope\GivenNumberCountExceeded();
123123
}
124124
if ($scope && $scope->getStatus('ticketprinter', 'deactivated')) {
125+
error_log(json_encode($ticketprinter));
125126
throw new Exception\Ticketprinter\DisabledByScope(
126127
$scope->getPreference('ticketprinter', 'deactivatedText')
127128
);

zmsdb/tests/Zmsdb/OrganisationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testReadByClusterId()
5353
public function testReadByTicketprinterHash()
5454
{
5555
$query = new Query();
56-
$entity = $query->readByHash('ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2'); //Test Ticketprinter
56+
$entity = $query->readByHash('71abcdefghijklmnopqrstuvwxyz'); //Test Ticketprinter
5757
$this->assertEntity("\\BO\\Zmsentities\\Organisation", $entity);
5858
$this->assertEquals('Charlottenburg-Wilmersdorf', $entity->name);
5959
}

zmsdb/tests/Zmsdb/TicketprinterTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,13 @@ public function testReadExpiredTicketprinterList()
159159
$time = new \DateTimeImmutable("2016-11-27 14:31");
160160
$time = $time->setTimestamp($time->getTimestamp() - $duration);
161161
$ticketprinterList = $query->readExpiredTicketprinterList($time);
162-
$this->assertEquals(3, $ticketprinterList->count());
163-
162+
$this->assertEquals(0, $ticketprinterList->count());
163+
//sessions no longer used so 0
164164
$time = new \DateTimeImmutable("2016-11-27 14:30");
165165
$time = $time->setTimestamp($time->getTimestamp() - $duration);
166166
$ticketprinterList = $query->readExpiredTicketprinterList($time);
167-
$this->assertEquals(2, $ticketprinterList->count());
167+
$this->assertEquals(0, $ticketprinterList->count());
168+
//sessions no longer used so 0
168169
}
169170

170171
protected function getTestEntity()

zmsentities/src/Zmsentities/Ticketprinter.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public function getDefaults()
2828

2929
public function getHashWith($organisiationId)
3030
{
31-
$this->hash = $organisiationId . bin2hex(openssl_random_pseudo_bytes(16));
31+
$this->hash = $organisiationId . "abcdefghijklmnopqrstuvwxyz";
32+
//$this->hash = $organisiationId . bin2hex(openssl_random_pseudo_bytes(16));
3233
return $this;
3334
}
3435

zmsentities/tests/Zmsentities/TicketprinterTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function testBasic()
1010
{
1111
$entity = (new $this->entityclass())->getExample();
1212
$this->assertStringContainsString('54', $entity->getHashWith(54), 'Hash not contains organisationId 54');
13-
$this->assertTrue(34 == strlen($entity->getHashWith(54)->hash), 'Hash length does not match');
13+
$this->assertTrue(28 == strlen($entity->getHashWith(54)->hash), 'Hash length does not match');
1414
$this->assertTrue($entity->isEnabled(), 'Ticketprinter should be enabled');
1515
}
1616

zmsstatistic/tests/Zmsstatistic/fixtures/GET_organisation_71_resolved3.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@
646646
{
647647
"enabled": "1",
648648
"reload": 30,
649-
"hash": "ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2",
649+
"hash": "71abcdefghijklmnopqrstuvwxyz",
650650
"id": "1",
651651
"lastUpdate": "1477661416",
652652
"name": "Test Ticketprinter"

zmsticketprinter/phpunit.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
convertNoticesToExceptions="true"
1111
convertWarningsToExceptions="true"
1212
forceCoversAnnotation="false"
13-
stopOnFailure="true"
13+
stopOnFailure="false"
1414
verbose="true"
1515
processIsolation="false"
1616
>

zmsticketprinter/src/Zmsticketprinter/Helper/Ticketprinter.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ public function __construct($args, RequestInterface $request)
3030
$this->organisation = $this->readOrganisation();
3131
$entity = $this->getAssembledEntity();
3232

33-
$hash = static::getHashFromRequest($request);
34-
if ('' === $hash) {
35-
$entity = $this->writeNewWithHash($request, $entity);
36-
} else {
33+
//$hash = static::getHashFromRequest($request);
34+
$hash = $this->organisation->id . 'abcdefghijklmnopqrstuvwxyz';
35+
36+
try {
3737
$entity = $this->getByHash($hash, $entity);
38+
} catch (\Exception $e) {
39+
error_log('Error in getByHash creating new organisation hash: ' . $e->getMessage());
40+
$entity = $this->writeNewWithHash($request, $entity);
3841
}
3942

4043
$this->entity = \App::$http->readPostResult('/ticketprinter/', $entity)->getEntity();

zmsticketprinter/tests/Zmsticketprinter/CustomizedTemplateTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected function getApiCalls()
2121
],
2222
[
2323
'function' => 'readGetResult',
24-
'url' => '/ticketprinter/710caa9f2e7547a52106d6b00868c5cf3a/',
24+
'url' => '/ticketprinter/71abcdefghijklmnopqrstuvwxyz/',
2525
'response' => $this->readFixture("GET_ticketprinter.json"),
2626
],
2727
[
@@ -55,7 +55,7 @@ public function testRendering()
5555
'scopeId' => 615
5656
], [
5757
'__cookie' => [
58-
'Ticketprinter' => '710caa9f2e7547a52106d6b00868c5cf3a',
58+
'Ticketprinter' => '71abcdefghijklmnopqrstuvwxyz',
5959
]
6060
], [ ]);
6161
$this->assertEquals('200', $response->getStatusCode());
@@ -71,7 +71,7 @@ public function testTemplateNotFound()
7171
'scopeId' => 615
7272
], [
7373
'__cookie' => [
74-
'Ticketprinter' => '710caa9f2e7547a52106d6b00868c5cf3a',
74+
'Ticketprinter' => '71abcdefghijklmnopqrstuvwxyz',
7575
],
7676
'template' => 'notfound'
7777
], [ ]);

zmsticketprinter/tests/Zmsticketprinter/HomeUrlTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testRendering()
2222
],
2323
[
2424
'function' => 'readGetResult',
25-
'url' => '/ticketprinter/71ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2/',
25+
'url' => '/ticketprinter/71abcdefghijklmnopqrstuvwxyz/',
2626
'response' => $this->readFixture("GET_ticketprinter.json"),
2727
],
2828
[
@@ -48,7 +48,7 @@ public function testRendering()
4848
\BO\Zmsclient\Ticketprinter::setHomeUrl("", $request);
4949
$this->render([ ], [
5050
'__cookie' => [
51-
'Ticketprinter' => '71ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2',
51+
'Ticketprinter' => '71abcdefghijklmnopqrstuvwxyz',
5252
],
5353
'ticketprinter' => [
5454
'buttonlist' => 's141,l[http://www.berlin.de/|Portal berlin.de]',
@@ -72,7 +72,7 @@ public function testRedirectToSingleScopePage()
7272
],
7373
[
7474
'function' => 'readGetResult',
75-
'url' => '/ticketprinter/71ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2/',
75+
'url' => '/ticketprinter/71abcdefghijklmnopqrstuvwxyz/',
7676
'response' => $this->readFixture("GET_ticketprinter.json"),
7777
],
7878
[
@@ -98,7 +98,7 @@ public function testRedirectToSingleScopePage()
9898
\BO\Zmsclient\Ticketprinter::setHomeUrl("", $request);
9999
$response = $this->render([ ], [
100100
'__cookie' => [
101-
'Ticketprinter' => '71ac9df1f2983c3f94aebc1a9bd121bfecf5b374f2',
101+
'Ticketprinter' => '71abcdefghijklmnopqrstuvwxyz',
102102
],
103103
'ticketprinter' => [
104104
'buttonlist' => 's141',

0 commit comments

Comments
 (0)