19declare(strict_types=1);
32class MailOutboxMigration
implements Migration
34 public const int NUMBER_OF_STEPS = 10;
35 public const int NUMBER_OF_PATHS_PER_STEP = 10;
45 return (
new ReflectionClass($this))->getShortName();
48 public function getDefaultAmountOfStepsPerRun():
int
50 return self::NUMBER_OF_STEPS;
53 public function getPreconditions(
Environment $environment): array
60 public function prepare(
Environment $environment): void
63 $this->ps_in_fold_entry = $this->db->prepareManip(
64 'INSERT INTO mail_obj_data (obj_id, user_id, title, m_type) VALUES(?, ?, ?, ?)',
68 $this->ps_in_tree_entry = $this->db->prepareManip(
69 'INSERT INTO mail_tree (tree, child, parent, lft, rgt, depth) VALUES(?, ?, ?, ?, ?, ?)',
80 $this->ps_up_tree_entry = $this->db->prepareManip(
83 SET lft = CASE WHEN lft > ? THEN lft + 2 ELSE lft END,
84 rgt = CASE WHEN rgt > ? THEN rgt + 2 ELSE rgt END
91 public function step(Environment $environment): void
93 $this->db->setLimit(self::NUMBER_OF_PATHS_PER_STEP);
95 SELECT mail_obj_data.*, mail_tree.*
97 INNER JOIN mail_obj_data ON mail_obj_data.user_id = ud.usr_id AND mail_obj_data.title = %s AND mail_obj_data.m_type = %s
98 INNER JOIN mail_tree ON mail_tree.child = mail_obj_data.obj_id AND mail_tree.tree = ud.usr_id
99 LEFT JOIN mail_obj_data AS outbox ON outbox.user_id = ud.usr_id AND outbox.title = %s
100 WHERE outbox.obj_id IS
NULL
103 $res = $this->db->queryF(
106 [
'd_drafts',
'drafts',
'e_outbox']
108 while ($draft_folder_row = $this->db->fetchAssoc(
$res)) {
109 $outbox_folder_id = $this->db->nextId(
'mail_obj_data');
111 $this->ps_in_fold_entry,
112 [$outbox_folder_id, (
int) $draft_folder_row[
'user_id'],
'e_outbox',
'outbox']
115 "Created outbox folder (obj_id: $outbox_folder_id) for user_id: " . $draft_folder_row[
'user_id']
118 $right = $draft_folder_row[
'rgt'];
122 $this->db->execute($this->ps_up_tree_entry, [$right, $right, $draft_folder_row[
'user_id']]);
124 $this->ps_in_tree_entry,
126 $draft_folder_row[
'user_id'],
128 $draft_folder_row[
'parent'],
135 "Inserted outbox folder (obj_id: $outbox_folder_id) into tree for user_id: " . $draft_folder_row[
'user_id']
140 public function getRemainingAmountOfSteps():
int
143 SELECT COUNT(*) AS paths
145 INNER JOIN mail_obj_data ON mail_obj_data.user_id = ud.usr_id AND mail_obj_data.title = %s AND mail_obj_data.m_type = %s
146 INNER JOIN mail_tree ON mail_tree.child = mail_obj_data.obj_id AND mail_tree.tree = ud.usr_id
147 LEFT JOIN mail_obj_data AS outbox ON outbox.user_id = ud.usr_id AND outbox.title = %s
148 WHERE outbox.obj_id IS
NULL
151 $res = $this->db->queryF(
154 ['d_drafts', 'drafts', 'e_outbox']
156 $row = $this->db->fetchAssoc(
$res);
157 $paths = (
int) ($row['paths'] ?? 0);
158 $num_steps = (
int) ceil($paths / self::NUMBER_OF_PATHS_PER_STEP);
161 "Remaining outbox folders
to create: $paths / Estimated steps remaining: $num_steps",
168 private function inform(
string $text,
bool $force = false):
void
170 if ($this->io ===
null || (!$force && !$this->io->isVerbose())) {
174 $this->io->inform(
$text);
179 if ($this->io ===
null) {
183 $this->io->error(
$text);
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
A migration is a potentially long lasting operation that can be broken into discrete steps.
to(\GdImage $image, ?int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.