1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
declare(strict_types=1); |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
8
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\TrackEDefault; |
10
|
|
|
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
11
|
|
|
use DateTime; |
12
|
|
|
use DateTimeZone; |
13
|
|
|
use Doctrine\DBAL\Schema\Schema; |
14
|
|
|
use Exception; |
15
|
|
|
|
16
|
|
|
class Version20250927180003 extends AbstractMigrationChamilo |
17
|
|
|
{ |
18
|
|
|
public function getDescription(): string |
19
|
|
|
{ |
20
|
|
|
return 'Save c_item_property.lastedit_user_id as track_e_default for portfolio items and comments'; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @throws Exception |
25
|
|
|
*/ |
26
|
|
|
public function up(Schema $schema): void |
27
|
|
|
{ |
28
|
|
|
$itemsRows = $this->connection |
29
|
|
|
->executeQuery( |
30
|
|
|
"SELECT * FROM c_item_property |
31
|
|
|
WHERE tool IN ('portfolio', 'portfolio_comment') |
32
|
|
|
AND (to_user_id IS NULL OR to_user_id = 0) |
33
|
|
|
AND lastedit_type IN ('PortfolioUpdated', 'PortfolioCommentUpdated')" |
34
|
|
|
) |
35
|
|
|
->fetchAllAssociative(); |
36
|
|
|
|
37
|
|
|
foreach ($itemsRows as $itemRow) { |
38
|
|
|
$lastUserId = $itemRow['lastedit_user_id']; |
39
|
|
|
$courseId = $itemRow['c_id'] ?: null; |
40
|
|
|
$sessionId = $itemRow['session_id'] ?: null; |
41
|
|
|
$date = $itemRow['lastedit_date'] ?: $itemRow['insert_date']; |
42
|
|
|
|
43
|
|
|
$eventType = match ($itemRow['lastedit_type']) { |
44
|
|
|
'PortfolioCommentUpdated' => 'portfolio_comment_updated', |
45
|
|
|
'PortfolioUpdated' => 'portfolio_updated', |
46
|
|
|
default => null, |
47
|
|
|
}; |
48
|
|
|
|
49
|
|
|
$valueType = match ($itemRow['lastedit_type']) { |
50
|
|
|
'PortfolioCommentUpdated' => 'portfolio_comment_id', |
51
|
|
|
'PortfolioUpdated' => 'portfolio_id', |
52
|
|
|
default => null, |
53
|
|
|
}; |
54
|
|
|
|
55
|
|
|
if (!$eventType || !$valueType) { |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$trackEvent = new TrackEDefault(); |
60
|
|
|
$trackEvent |
61
|
|
|
->setDefaultUserId($lastUserId) |
62
|
|
|
->setCId($courseId) |
63
|
|
|
->setSessionId($sessionId) |
64
|
|
|
->setDefaultDate(new DateTime($date, new DateTimeZone('UTC'))) |
65
|
|
|
->setDefaultEventType($eventType) |
66
|
|
|
->setDefaultValueType($valueType) |
67
|
|
|
->setDefaultValue((string) $itemRow['ref']) |
68
|
|
|
; |
69
|
|
|
|
70
|
|
|
$this->entityManager->persist($trackEvent); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$this->entityManager->flush(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.