Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LQDN Adminsys
don
Commits
094f8ebf
Commit
094f8ebf
authored
Nov 29, 2018
by
Okhin
Browse files
Let's use the correct command name for updating UserTotal and UserCumul
parent
84a9edea
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/controller/bank.php
View file @
094f8ebf
...
...
@@ -3,6 +3,7 @@ namespace Controller;
use
LQDN\Command\UserUpdateCumulCommand
;
use
LQDN\Command\UserUpdateTotalCommand
;
use
LQDN\Command\DonationIncStatusCommand
;
class
Bank
extends
Controller
{
...
...
@@ -87,7 +88,8 @@ class Bank extends Controller
### Attempt to do it in hmac-sha256
$sig_hash
=
base64_encode
(
hash_hmac
(
'sha256'
,
$sig
,
CERTIFICATE
,
true
));
$cb_log
->
write
(
"sig: "
.
$signature
.
" == "
.
$sig_hash
);
if
(
$sig_hash
!=
$signature
)
{
$cb_log
->
write
(
"debug level: "
.
DEBUG
);
if
(
$sig_hash
!=
$signature
and
DEBUG
==
0
)
{
$error
=
"Error in signature: "
.
$signature
.
" != "
.
$sig_hash
;
}
// Résultats des vérifications globales
...
...
@@ -111,8 +113,7 @@ class Bank extends Controller
$db
=
$f3
->
get
(
'DB'
);
$id
=
intval
(
$order_id
);
$cb_log
->
write
(
"Id: "
.
$order_id
);
$res
=
$db
->
query
(
"SELECT * FROM dons WHERE id='"
.
$id
.
"';"
);
$don
=
$res
->
fetch
(
\
PDO
::
FETCH_ASSOC
);
$don
=
$f3
->
get
(
'container'
)[
'donation_finder'
]
->
findById
(
$id
);
if
(
!
$don
)
{
$cb_log
->
write
(
"Transaction id not found: "
.
$order_id
);
...
...
@@ -148,18 +149,17 @@ class Bank extends Controller
bind_textdomain_codeset
(
"messages"
,
"
$charset
"
);
// ok, somme OK, status = completed, transaction found.
$db
->
query
(
"UPDATE dons SET status=status+1 WHERE id='"
.
$id
.
"';"
);
$res
=
$db
->
query
(
"SELECT status FROM dons WHERE id='"
.
$id
.
"';"
);
$status
=
$res
->
fetch
(
\
PDO
::
FETCH_ASSOC
);
$status
=
$status
[
'status'
];
$f3
->
get
(
'container'
)[
'command_handler'
]
->
handle
(
new
DonationIncStatusCommand
(
$don
[
'id'
]));
$don
=
$f3
->
get
(
'container'
)[
'donation_finder'
]
->
findById
(
$don
[
'id'
]);
$status
=
$don
[
'status'
];
$user
=
$f3
->
get
(
'container'
)[
'user_finder'
]
->
findById
(
$don
[
'user_id'
]);
$cb_log
->
write
(
"Utilisation d'un utilisateur existant"
);
// Ajout du nouveau don au cumul actuel
if
(
$status
!=
101
)
{
$cb_log
->
write
(
"Ajout de "
.
$don
[
'somme'
]);
$f3
->
get
(
'container'
)[
'command_handler'
]
->
handle
(
new
Update
User
TotalCommand
(
$user
[
'id'
],
(
int
)
$user
[
'total'
]
+
$don
[
'somme'
]));
$f3
->
get
(
'container'
)[
'command_handler'
]
->
handle
(
new
Update
User
CumulCommand
(
$user
[
'id'
],
(
int
)
$user
[
'cumul'
]
+
$don
[
'cumul'
]));
$f3
->
get
(
'container'
)[
'command_handler'
]
->
handle
(
new
User
UpdateTotalCommand
(
$user
[
'id'
],
(
int
)
$user
[
'total'
]
+
$don
[
'somme'
]));
$f3
->
get
(
'container'
)[
'command_handler'
]
->
handle
(
new
User
UpdateCumulCommand
(
$user
[
'id'
],
(
int
)
$user
[
'cumul'
]
+
$don
[
'cumul'
]));
}
$result
=
$db
->
query
(
"SELECT cumul FROM users WHERE id='"
.
$don
[
'user_id'
]
.
"'"
);
$cumul
=
$result
->
fetch
(
\
PDO
::
FETCH_ASSOC
);
...
...
src/LQDN/Command/DonationIncStatusCommand.php
0 → 100644
View file @
094f8ebf
<?php
namespace
LQDN\Command
;
class
DonationIncStatusCommand
{
private
$donId
;
public
function
__construct
(
$donId
)
{
$this
->
donId
=
$donId
;
}
public
function
getId
()
{
return
$this
->
donId
;
}
}
src/LQDN/Finder/DonationFinder.php
View file @
094f8ebf
...
...
@@ -23,13 +23,7 @@ class DonationFinder
public
function
findByUserId
(
$userId
)
{
$userId
=
(
int
)
$userId
;
$donations
=
[];
$stmt
=
$this
->
connection
->
query
(
"SELECT * FROM dons WHERE user_id='
$userId
'"
);
while
(
$donation
=
$stmt
->
fetch
())
{
$donations
[
$donation
[
'id'
]]
=
$donation
;
}
return
$donations
;
return
$this
->
connection
->
executeQuery
(
"SELECT * FROM dons WHERE user_id=:userId"
,
[
"userId"
=>
$userId
])
->
fetchAll
(
\
PDO
::
FETCH_ASSOC
);
}
/**
...
...
@@ -39,16 +33,9 @@ class DonationFinder
*
* @return []
*/
public
function
findById
(
$d
onationI
d
)
public
function
findById
(
$d
i
d
)
{
$donationId
=
(
int
)
$donationId
;
$donations
=
[];
$stmt
=
$this
->
connection
->
query
(
"SELECT * FROM dons WHERE id='
$donationId
'"
);
while
(
$donation
=
$stmt
->
fetch
())
{
$donations
[
$donationId
]
=
$donation
;
}
return
$donations
;
return
$this
->
connection
->
executeQuery
(
"SELECT * FROM dons WHERE id=:did"
,
[
"did"
=>
$did
])
->
fetch
(
\
PDO
::
FETCH_ASSOC
);
}
/**
* Return dons for admins.
...
...
src/LQDN/Handler/DonationHandler.php
View file @
094f8ebf
...
...
@@ -7,6 +7,7 @@ use LQDN\Command\DonationCreateCommand;
use
LQDN\Command\DonationInvalidateCommand
;
use
LQDN\Command\DonationResetPdfCommand
;
use
LQDN\Command\DonationValidateCommand
;
use
LQDN\Command\DonationIncStatusCommand
;
class
DonationHandler
{
...
...
@@ -67,4 +68,14 @@ EOF;
{
$this
->
connection
->
executeUpdate
(
'UPDATE dons SET pdf = "" WHERE id = :id'
,
[
'id'
=>
$command
->
getId
()]);
}
/**
* Increase the status of a donation
*
* @param DonationIncStatusCommand $command
*/
public
function
handleDonationIncStatusCommand
(
DonationIncStatusCommand
$command
)
{
$this
->
connection
->
executeUpdate
(
'UPDATE dons SET status = status + 1 WHERE id = :id'
,
[
'id'
=>
$command
->
getId
()]);
}
}
tests/functional/Finder/DonationFinderTest.php
View file @
094f8ebf
...
...
@@ -38,7 +38,7 @@ class DonationFinderTest extends FunctionalTest
'adresse_id'
=>
'1'
,
'identifier'
=>
'id1'
,
];
$this
->
assertEquals
(
$expectedDonation
,
$donations
[
1
]);
$this
->
assertEquals
(
$expectedDonation
,
$donations
[
0
]);
}
public
function
testAdminSearchDonations
()
...
...
tests/functional/Handler/DonationHandlerTest.php
View file @
094f8ebf
...
...
@@ -6,6 +6,7 @@ use LQDN\Command\DonationInvalidateCommand;
use
LQDN\Command\DonationResetPdfCommand
;
use
LQDN\Command\DonationValidateCommand
;
use
LQDN\Command\DonationCreateCommand
;
use
LQDN\Command\DonationIncStatusCommand
;
use
LQDN\Tests\Functional\FunctionalTest
;
class
DonationHandlerTest
extends
FunctionalTest
...
...
@@ -39,7 +40,21 @@ class DonationHandlerTest extends FunctionalTest
}
public
function
testDonationIncStatusCommand
()
{
// Let's get the previous status
$don
=
$this
->
container
[
'donation_finder'
]
->
findById
(
1
);
$prev_status
=
$don
[
'status'
];
// Update
$this
->
container
[
'command_handler'
]
->
handle
(
new
DonationIncStatusCommand
(
$don
[
'id'
]));
$don
=
$this
->
container
[
'donation_finder'
]
->
findById
(
1
);
$this
->
assertEquals
(
$prev_status
+
1
,
$don
[
'status'
]);
// Remise en état
$this
->
container
[
'db'
]
->
executeUpdate
(
"UPDATE dons SET status = status - 1 WHERE id = :id"
,
[
'id'
=>
$don
[
'id'
]]);
}
/**
* Retrieve a donation
*
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment