ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MigrateNewAccountAttachments.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\User\Setup;
20
24
26{
28 private int $root_user_id;
29
30 public function getLabel(): string
31 {
32 return 'Migrate New Account Mail Attachments to IRSS';
33 }
34
36 {
37 return 15;
38 }
39
40 public function getPreconditions(Environment $environment): array
41 {
42 return \ilResourceStorageMigrationHelper::getPreconditions();
43 }
44
45 public function prepare(Environment $environment): void
46 {
47 $this->helper = new \ilResourceStorageMigrationHelper(
48 new Stakeholder(),
49 $environment
50 );
51 $this->root_user_id = $this->helper->getDatabase()->fetchObject(
52 $this->helper->getDatabase()->query(
53 'SELECT usr_id FROM usr_data WHERE login="root"'
54 )
55 )?->usr_id ?? 6;
56 }
57
58 public function step(Environment $environment): void
59 {
60 $db = $this->helper->getDatabase();
61 $res = $db->fetchObject(
62 $db->query(
63 'SELECT
64 att_file, lang
65 FROM mail_template
66 WHERE att_file IS NOT NULL AND type = "nacc" LIMIT 1;'
67 )
68 );
69
70 $path = '/' . implode(
71 '/',
72 array_map(
73 static fn(string $path_part): string => trim($path_part, '/'),
74 [
75 $this->helper->getClientDataDir() . '/ilReg/reg_7',
76 $res->lang,
77 ]
78 )
79 );
80
81 $rid = null;
82
83 if (file_exists($path)) {
84 $rid = $this->helper->movePathToStorage(
85 $path,
86 $this->root_user_id,
87 static fn() => $res->att_file,
88 static fn() => $res->att_file
89 );
90 }
91 if ($rid !== null) {
92 $rid = $rid->serialize();
93 }
94
95 $db->update(
96 'mail_template',
97 [
98 'att_file' => [\ilDBConstants::T_TEXT, null],
99 'att_rid' => [\ilDBConstants::T_TEXT, $rid]
100 ],
101 [
102 'lang' => [\ilDBConstants::T_TEXT, $res->lang],
103 'type' => [\ilDBConstants::T_TEXT, 'nacc'],
104 ]
105 );
106 }
107
109 {
110 return $this->helper->getDatabase()->fetchObject(
111 $this->helper->getDatabase()->query(
112 'SELECT COUNT(*) cnt FROM mail_template WHERE att_file IS NOT NULL AND type = "nacc"'
113 )
114 )->cnt;
115 }
116}
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
prepare(Environment $environment)
Prepare the migration by means of some environment.
step(Environment $environment)
Run one step of the migration.
getPreconditions(Environment $environment)
Objectives the migration depend on.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:29
$path
Definition: ltiservices.php:30
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Agent.php:21