19 declare(strict_types=1);
32 return 'ilUpdateNewAccountMailTemplatesForMustache';
37 return self::NUMBER_OF_STEPS;
43 new \ilDatabaseUpdatedObjective()
49 $this->db = $environment->
getResource(Environment::RESOURCE_DATABASE);
59 $this->
replace(
$lang,
'/\[IF_PASSWORD\]/',
'{{#IF_PASSWORD}}');
60 $this->
replace(
$lang,
'/\[IF_NO_PASSWORD\]/',
'{{#IF_NO_PASSWORD}}');
61 $this->
replace(
$lang,
'/\[IF_TARGET\]/',
'{{#IF_TARGET}}');
62 $this->
replace(
$lang,
'/\[IF_TIMELIMIT\]/',
'{{#IF_TIMELIMIT}}');
68 $q =
'SELECT COUNT(*) AS open FROM mail_template ' . PHP_EOL . $this->
getWhere();
69 $res = $this->db->query(
$q);
70 $row = $this->db->fetchAssoc(
$res);
72 return (
int) $row[
'open'];
77 $this->db->setLimit(1);
78 $q =
'SELECT lang FROM mail_template ' . PHP_EOL . $this->
getWhere();
79 $res = $this->db->query(
$q);
81 if ($this->db->numRows(
$res) === 0) {
85 $row = $this->db->fetchAssoc(
$res);
92 return ' WHERE (' . PHP_EOL
100 protected function replace(
string $lang,
string $regex_search,
string $replacement): void
102 $res = $this->db->queryF(
103 'SELECT subject, body FROM mail_template WHERE lang = %s AND type = %s',
107 if ($this->db->numRows(
$res) === 1) {
108 $row = $this->db->fetchAssoc(
$res);
121 $this->db->manipulateF(
122 'UPDATE mail_template SET subject = %s, body = %s WHERE lang = %s AND type = %s',
124 [$subject, $body, $lang,
'nacc']
131 $res = $this->db->queryF(
132 'SELECT subject, body FROM mail_template WHERE lang = %s AND type = %s',
136 if ($this->db->numRows(
$res) === 1) {
137 $row = $this->db->fetchAssoc(
$res);
141 '/\[([A-Z_\/]+?)\]/',
146 '/\[([A-Z_\/]+?)\]/',
150 $this->db->manipulateF(
151 'UPDATE mail_template SET subject = %s, body = %s WHERE lang = %s AND type = %s',
153 [$subject, $body, $lang,
'nacc']
160 string $regex_search,
163 if ($text === null) {
A migration is a potentially long lasting operation that can be broken into discrete steps...
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An environment holds resources to be used in the setup process.