ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilUpdateMailTemplatesForMustache Class Reference
+ Inheritance diagram for ilUpdateMailTemplatesForMustache:
+ Collaboration diagram for ilUpdateMailTemplatesForMustache:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 

Data Fields

const NUMBER_OF_STEPS = 10000
 
- Data Fields inherited from ILIAS\Setup\Migration
const INFINITE = -1
 

Protected Member Functions

 getNextTemplateToBeUpdated ()
 
 getWhere ()
 
 replace (int $tpl_id, string $lang)
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Definition at line 24 of file class.ilUpdateMailTemplatesForMustache.php.

Member Function Documentation

◆ getDefaultAmountOfStepsPerRun()

ilUpdateMailTemplatesForMustache::getDefaultAmountOfStepsPerRun ( )

Tell the default amount of steps to be executed for one run of the migration.

Return Migration::INFINITE if all units should be migrated at once.

Implements ILIAS\Setup\Migration.

Definition at line 35 of file class.ilUpdateMailTemplatesForMustache.php.

35  : int
36  {
37  return self::NUMBER_OF_STEPS;
38  }

◆ getLabel()

ilUpdateMailTemplatesForMustache::getLabel ( )
Returns
string - a meaningful and concise description for your migration.

Implements ILIAS\Setup\Migration.

Definition at line 30 of file class.ilUpdateMailTemplatesForMustache.php.

30  : string
31  {
32  return 'ilUpdateMailTemplatesForMustache';
33  }

◆ getNextTemplateToBeUpdated()

ilUpdateMailTemplatesForMustache::getNextTemplateToBeUpdated ( )
protected
Returns
array{0: int, 1: string}|null

Definition at line 76 of file class.ilUpdateMailTemplatesForMustache.php.

References $q, $res, getWhere(), and ILIAS\Repository\int().

Referenced by step().

76  : ?array
77  {
78  $this->db->setLimit(1);
79  $q = 'SELECT tpl_id, lang FROM mail_man_tpl ' . PHP_EOL . $this->getWhere();
80  $res = $this->db->query($q);
81 
82  if ($this->db->numRows($res) === 0) {
83  return null;
84  }
85 
86  $row = $this->db->fetchAssoc($res);
87 
88  return [
89  (int) $row['tpl_id'],
90  $row['lang']
91  ];
92  }
$res
Definition: ltiservices.php:69
$q
Definition: shib_logout.php:21
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPreconditions()

ilUpdateMailTemplatesForMustache::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 40 of file class.ilUpdateMailTemplatesForMustache.php.

40  : array
41  {
42  return [
43  new \ilDatabaseUpdatedObjective()
44  ];
45  }

◆ getRemainingAmountOfSteps()

ilUpdateMailTemplatesForMustache::getRemainingAmountOfSteps ( )

Count up how many "things" need to be migrated.

This helps the admin to decide how big he can create the steps and also how long a migration takes

Implements ILIAS\Setup\Migration.

Definition at line 64 of file class.ilUpdateMailTemplatesForMustache.php.

References $q, $res, and getWhere().

64  : int
65  {
66  $q = 'SELECT COUNT(tpl_id) AS open FROM mail_man_tpl ' . PHP_EOL . $this->getWhere();
67  $res = $this->db->query($q);
68  $row = $this->db->fetchAssoc($res);
69 
70  return (int) $row['open'];
71  }
$res
Definition: ltiservices.php:69
$q
Definition: shib_logout.php:21
+ Here is the call graph for this function:

◆ getWhere()

ilUpdateMailTemplatesForMustache::getWhere ( )
protected

Definition at line 94 of file class.ilUpdateMailTemplatesForMustache.php.

Referenced by getNextTemplateToBeUpdated(), and getRemainingAmountOfSteps().

94  : string
95  {
96  return " WHERE (m_subject REGEXP '\[[A-Z_]+?\]' OR m_message REGEXP '\[[A-Z_]+?\]')" . PHP_EOL;
97  }
+ Here is the caller graph for this function:

◆ prepare()

ilUpdateMailTemplatesForMustache::prepare ( Environment  $environment)

Prepare the migration by means of some environment.

This is not supposed to modify the environment, but will be run to prime the migration object to run step and getRemainingAmountOfSteps afterwards.

Implements ILIAS\Setup\Migration.

Definition at line 47 of file class.ilUpdateMailTemplatesForMustache.php.

References ILIAS\Setup\Environment\getResource().

47  : void
48  {
49  $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
50  }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
+ Here is the call graph for this function:

◆ replace()

ilUpdateMailTemplatesForMustache::replace ( int  $tpl_id,
string  $lang 
)
protected

Definition at line 99 of file class.ilUpdateMailTemplatesForMustache.php.

References $message, $res, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by step().

99  : void
100  {
101  $res = $this->db->queryF(
102  'SELECT m_subject, m_message FROM mail_man_tpl WHERE tpl_id = %s AND lang = %s',
104  [$tpl_id, $lang]
105  );
106  if ($this->db->numRows($res) === 1) {
107  $row = $this->db->fetchAssoc($res);
108 
109  $subject = isset($row['m_subject']) ? preg_replace(
110  '/\[([A-Z_]+?)\]/',
111  '{{$1}}',
112  $row['m_subject']
113  ) : null;
114  $message = isset($row['m_message']) ? preg_replace(
115  '/\[([A-Z_]+?)\]/',
116  '{{$1}}',
117  $row['m_message']
118  ) : null;
119 
120  $this->db->manipulateF(
121  'UPDATE mail_man_tpl SET m_subject = %s, m_message = %s WHERE tpl_id = %s AND lang = %s',
123  [$subject, $message, $tpl_id, $lang]
124  );
125  }
126  }
$res
Definition: ltiservices.php:69
$lang
Definition: xapiexit.php:26
$message
Definition: xapiexit.php:32
+ Here is the caller graph for this function:

◆ step()

ilUpdateMailTemplatesForMustache::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 52 of file class.ilUpdateMailTemplatesForMustache.php.

References $lang, getNextTemplateToBeUpdated(), and replace().

52  : void
53  {
54  $tpl_values = $this->getNextTemplateToBeUpdated();
55  if ($tpl_values === null) {
56  return;
57  }
58 
59  [$tpl_id, $lang] = $tpl_values;
60 
61  $this->replace($tpl_id, $lang);
62  }
$lang
Definition: xapiexit.php:26
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilUpdateMailTemplatesForMustache::$db
protected

Definition at line 28 of file class.ilUpdateMailTemplatesForMustache.php.

◆ NUMBER_OF_STEPS

const ilUpdateMailTemplatesForMustache::NUMBER_OF_STEPS = 10000

Definition at line 26 of file class.ilUpdateMailTemplatesForMustache.php.


The documentation for this class was generated from the following file: