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
|
|
|
) { |
24
|
2 |
|
} |
25
|
|
|
|
26
|
1 |
|
#[Override] |
27
|
|
|
public function createDatabaseEntryForUser(UserInterface $user, int $databaseEntryId): ?DatabaseEntryInterface |
28
|
|
|
{ |
29
|
1 |
|
if ($databaseEntryId === 0) { |
30
|
|
|
return null; |
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
if (!$user->hasColony()) { |
34
|
1 |
|
return null; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$databaseEntry = $this->databaseEntryRepository->find($databaseEntryId); |
38
|
|
|
|
39
|
|
|
if ($databaseEntry === null) { |
40
|
|
|
return null; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
//create new user entry |
44
|
|
|
$userEntry = $this->databaseUserRepository->prototype() |
45
|
|
|
->setUser($user) |
46
|
|
|
->setDatabaseEntry($databaseEntry) |
47
|
|
|
->setDate(time()); |
48
|
|
|
|
49
|
|
|
$this->databaseUserRepository->save($userEntry); |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
if (!$user->isNpc()) { |
53
|
|
|
//create prestige log |
54
|
|
|
$this->createPrestigeLog->createLogForDatabaseEntry($databaseEntry, $user, $userEntry->getDate()); |
55
|
|
|
|
56
|
|
|
$this->checkForCompletion($user, $databaseEntry->getCategory(), $databaseEntryId); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $databaseEntry; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function checkForCompletion(UserInterface $user, DatabaseCategoryInterface $category, int $databaseEntryId): void |
63
|
|
|
{ |
64
|
|
|
//check if an award is configured for this category |
65
|
|
|
if ($category->getAward() === null) { |
66
|
|
|
return; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$award = $category->getAward(); |
70
|
|
|
|
71
|
|
|
if ($this->databaseUserRepository->hasUserCompletedCategory($user->getId(), $category->getId(), $databaseEntryId)) { |
72
|
|
|
$this->createUserAward->createAwardForUser($user, $award); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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