|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Database\Lib; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use Stu\Module\Award\Lib\CreateUserAwardInterface; |
|
9
|
|
|
use Stu\Module\Prestige\Lib\CreatePrestigeLogInterface; |
|
10
|
|
|
use Stu\Orm\Entity\DatabaseCategoryInterface; |
|
11
|
|
|
use Stu\Orm\Entity\DatabaseEntryInterface; |
|
12
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
13
|
|
|
use Stu\Orm\Repository\DatabaseEntryRepositoryInterface; |
|
14
|
|
|
use Stu\Orm\Repository\DatabaseUserRepositoryInterface; |
|
15
|
|
|
|
|
16
|
|
|
final class CreateDatabaseEntry implements CreateDatabaseEntryInterface |
|
17
|
|
|
{ |
|
18
|
2 |
|
public function __construct( |
|
19
|
|
|
private DatabaseEntryRepositoryInterface $databaseEntryRepository, |
|
20
|
|
|
private DatabaseUserRepositoryInterface $databaseUserRepository, |
|
21
|
|
|
private CreatePrestigeLogInterface $createPrestigeLog, |
|
22
|
|
|
private CreateUserAwardInterface $createUserAward |
|
23
|
2 |
|
) {} |
|
24
|
|
|
|
|
25
|
1 |
|
#[Override] |
|
26
|
|
|
public function createDatabaseEntryForUser(UserInterface $user, int $databaseEntryId): ?DatabaseEntryInterface |
|
27
|
|
|
{ |
|
28
|
1 |
|
if ($databaseEntryId === 0) { |
|
29
|
|
|
return null; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
if (!$user->hasColony()) { |
|
33
|
1 |
|
return null; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$databaseEntry = $this->databaseEntryRepository->find($databaseEntryId); |
|
37
|
|
|
|
|
38
|
|
|
if ($databaseEntry === null) { |
|
39
|
|
|
return null; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
//create new user entry |
|
43
|
|
|
$userEntry = $this->databaseUserRepository->prototype() |
|
44
|
|
|
->setUser($user) |
|
45
|
|
|
->setDatabaseEntry($databaseEntry) |
|
46
|
|
|
->setDate(time()); |
|
47
|
|
|
|
|
48
|
|
|
$this->databaseUserRepository->save($userEntry); |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
if (!$user->isNpc()) { |
|
52
|
|
|
//create prestige log |
|
53
|
|
|
$this->createPrestigeLog->createLogForDatabaseEntry($databaseEntry, $user, $userEntry->getDate()); |
|
54
|
|
|
|
|
55
|
|
|
$this->checkForCategoryCompletion($user, $databaseEntry->getCategory(), $databaseEntryId); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $databaseEntry; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function checkForCategoryCompletion( |
|
62
|
|
|
UserInterface $user, |
|
63
|
|
|
DatabaseCategoryInterface $category, |
|
64
|
|
|
?int $ignoredDatabaseEntryId = null |
|
65
|
|
|
): void { |
|
66
|
|
|
//check if an award is configured for this category |
|
67
|
|
|
if ($category->getAward() === null) { |
|
68
|
|
|
return; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$award = $category->getAward(); |
|
72
|
|
|
|
|
73
|
|
|
if ($this->databaseUserRepository->hasUserCompletedCategory($user->getId(), $category->getId(), $ignoredDatabaseEntryId)) { |
|
74
|
|
|
$this->createUserAward->createAwardForUser($user, $award); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths