ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective Class Reference
+ Inheritance diagram for ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective:
+ Collaboration diagram for ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective:

Public Member Functions

 __construct ()
 
 getHash ()
 Get a hash for this objective.The hash of two objectives must be the same, if they are the same objective, with the same config on the same environment, i.e. if the one is achieved the other is achieved as well because they are the same. More...
 
 getLabel ()
 Get a label that describes this objective. More...
 
 isNotable ()
 Get to know if this is an interesting objective for a human. More...
 
 getPreconditions (Environment $environment)
 Objectives might depend on other objectives. More...
 
 isApplicable (Environment $environment)
 Get to know whether the objective is applicable. More...
 
 achieve (Environment $environment)
 Objectives can be achieved. More...
 
- Public Member Functions inherited from ILIAS\Setup\Objective\AdminConfirmedObjective
 __construct (string $message)
 
 getHash ()
 Get a hash for this objective.The hash of two objectives must be the same, if they are the same objective, with the same config on the same environment, i.e. if the one is achieved the other is achieved as well because they are the same. More...
 
 getLabel ()
 Get a label that describes this objective. More...
 
 isNotable ()
 Get to know if this is an interesting objective for a human. More...
 
 getPreconditions (Setup\Environment $environment)
 
 achieve (Setup\Environment $environment)
 
 isApplicable (Setup\Environment $environment)
 @inheritDoc More...
 
 getHash ()
 Get a hash for this objective. More...
 
 getLabel ()
 Get a label that describes this objective. More...
 
 isNotable ()
 Get to know if this is an interesting objective for a human. More...
 
 getPreconditions (Environment $environment)
 Objectives might depend on other objectives. More...
 
 achieve (Environment $environment)
 Objectives can be achieved. More...
 
 isApplicable (Environment $environment)
 Get to know whether the objective is applicable. More...
 

Private Member Functions

 inform (string $text, bool $force=false)
 
 error (string $text)
 
 getCurlConnection (ilSetting $settings, string $url)
 

Private Attributes

IOWrapper $io = null
 
Container $old_DIC = null
 
ilSetting $old_settings = null
 

Additional Inherited Members

- Protected Attributes inherited from ILIAS\Setup\Objective\AdminConfirmedObjective
string $message
 

Detailed Description

Definition at line 39 of file BackgoundWorkerObjective.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::__construct ( )

Definition at line 45 of file BackgoundWorkerObjective.php.

46 {
48 "This will start a Background-Worker\n" .
49 'Continue?'
50 );
51 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ achieve()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::achieve ( Environment  $environment)

Objectives can be achieved.

They might add resources to the environment when they have been achieved.

This method needs to be idempotent for a given environment. That means: if this is executed a second time, nothing new should happen. Or the other way round: if the environment already looks like desired, the objective should not take any further actions when this is called.

Exceptions

LogicException if there are unfullfilled preconditions.

Exceptions

RuntimeException if there are missing resources.

Implements ILIAS\Setup\Objective.

Definition at line 89 of file BackgoundWorkerObjective.php.

89 : Environment
90 {
91 $environment = parent::achieve($environment);
92 $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
93 $settings_factory = $environment->getResource(Environment::RESOURCE_SETTINGS_FACTORY);
94 $ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
95
96 if ($io instanceof IOWrapper) {
97 $this->io = $io;
98 }
99
100 $settings = $settings_factory->settingsFor('common');
101
102 try {
103 $internal_path = $settings->get('soap_internal_wsdl_path');
104 if ($internal_path) {
105 $uri = (new \ILIAS\Data\URI($internal_path));
106 parse_str($uri->getQuery() ?? '', $query);
107 $uri = (string) (isset($query['wsdl']) ?
108 $uri :
109 $uri->withQuery(http_build_query(array_merge($query, ['wsdl' => '']))));
110 } elseif (trim($settings->get('soap_wsdl_path', '')) !== '') {
111 $uri = $settings->get('soap_wsdl_path', '');
112 } else {
113 $uri = ilUtil::_getHttpPath() . '/public/soap/server.php?wsdl';
114 }
115 $this->inform('Trying to call webserver by using WSDL: ' . $uri);
116 $soap_client = new SoapClient($uri, ['exceptions' => true, 'trace' => true, 'connection_timeout' => 10]);
117 $this->inform('SOAP client initialized');
118
119 $client_id = defined('CLIENT_ID') ? CLIENT_ID : $environment->getResource(Environment::RESOURCE_CLIENT_ID);
120 if ($client_id === null) {
121 throw new RuntimeException('CLIENT_ID is not defined.');
122 }
123
124 $url = $ini->readVariable('server', 'http_path');
125 $session_url = rtrim($url, '/') . '/goto.php';
126 $curl = $this->getCurlConnection($settings, $session_url);
127 $result = $curl->exec();
128 $header_array = $curl->getResponseHeaderArray();
129 $session_id = null;
130 if (isset($header_array['set-cookie'])) {
131 $set_cookie = $header_array['set-cookie'];
132 $cookies = is_array($set_cookie) ? $set_cookie : [$set_cookie];
133 foreach ($cookies as $cookie) {
134 if (preg_match('/PHPSESSID=([^;]+)/i', $cookie, $matches)) {
135 $session_id = $matches[1];
136 break;
137 }
138 }
139 }
140
141 if ($session_id === null) {
142 throw new RuntimeException('Could not extract session ID from server response.');
143 }
144
145 if (!$result) {
146 throw new RuntimeException('Could not retrieve session ID from server.');
147 }
148
149 $this->inform('Obtained session ID: ' . substr($session_id, 0, 40));
150 $session_string = $session_id ? ($session_id . '::' . $client_id) : ('::' . $client_id);
151 $this->inform('Calling startBackgroundTaskWorker with session: ' . ($session_id ? substr($session_id, 0, 40) : 'empty') . ', client: ' . $client_id);
152
153 $result = $soap_client->__call('startBackgroundTaskWorker', [
154 $session_string,
155 ]);
156 if ($result) {
157 $this->inform('Calling webserver successful.');
158 } else {
159 throw new RuntimeException('Calling webserver failed.');
160 }
161 } catch (Throwable $t) {
162 $this->error($t->getMessage());
163 $this->error('Calling webserver failed');
164 $this->error('Stack trace: ' . $t->getTraceAsString());
165 }
166
167 return $environment;
168 }
$settings
Definition: index.php:44
string $client_id
Definition: class.ilias.php:36
static _getHttpPath()
const CLIENT_ID
Definition: constants.php:41

References ILIAS\$client_id, ILIAS\$ini, ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective\$io, $settings, ilUtil\_getHttpPath(), CLIENT_ID, ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective\error(), ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective\getCurlConnection(), ILIAS\Setup\Environment\getResource(), ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective\inform(), ILIAS\Setup\Environment\RESOURCE_ADMIN_INTERACTION, ILIAS\Setup\Environment\RESOURCE_CLIENT_ID, ILIAS\Setup\Environment\RESOURCE_ILIAS_INI, and ILIAS\Setup\Environment\RESOURCE_SETTINGS_FACTORY.

+ Here is the call graph for this function:

◆ error()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::error ( string  $text)
private

Definition at line 179 of file BackgoundWorkerObjective.php.

179 : void
180 {
181 if ($this->io === null) {
182 return;
183 }
184
185 $this->io->error($text);
186 }
$text
Definition: xapiexit.php:21

References $text.

Referenced by ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective\achieve().

+ Here is the caller graph for this function:

◆ getCurlConnection()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::getCurlConnection ( ilSetting  $settings,
string  $url 
)
private

Definition at line 188 of file BackgoundWorkerObjective.php.

189 {
190 $curl = new ilCurlConnection(
191 $url,
193 );
194 $curl->init();
195 $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
196 $curl->setOpt(CURLOPT_SSL_VERIFYHOST, 0);
197 $curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
198 $curl->setOpt(CURLOPT_FOLLOWLOCATION, 1);
199 $curl->setOpt(CURLOPT_MAXREDIRS, 1);
200
201 return $curl;
202 }
class ilProxySettings

References $settings.

Referenced by ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective\achieve().

+ Here is the caller graph for this function:

◆ getHash()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::getHash ( )

Get a hash for this objective.The hash of two objectives must be the same, if they are the same objective, with the same config on the same environment, i.e. if the one is achieved the other is achieved as well because they are the same.

Reimplemented from ILIAS\Setup\Objective\AdminConfirmedObjective.

Definition at line 53 of file BackgoundWorkerObjective.php.

53 : string
54 {
55 return hash('sha256', self::class);
56 }

◆ getLabel()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::getLabel ( )

Get a label that describes this objective.

Reimplemented from ILIAS\Setup\Objective\AdminConfirmedObjective.

Definition at line 58 of file BackgoundWorkerObjective.php.

58 : string
59 {
60 return 'Start a Background-Worker';
61 }

◆ getPreconditions()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::getPreconditions ( Environment  $environment)

Objectives might depend on other objectives.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Objective.

Definition at line 68 of file BackgoundWorkerObjective.php.

◆ inform()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::inform ( string  $text,
bool  $force = false 
)
private

Definition at line 170 of file BackgoundWorkerObjective.php.

170 : void
171 {
172 if ($this->io === null || (!$force && !$this->io->isVerbose())) {
173 return;
174 }
175
176 $this->io->inform($text);
177 }

References $text.

Referenced by ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective\achieve().

+ Here is the caller graph for this function:

◆ isApplicable()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::isApplicable ( Environment  $environment)

Get to know whether the objective is applicable.

Don't change the environment or cause changes on services in the environment. Just check if this objective needs to be achieved, either currently or at all. In case of doubt whether the objective is applicable or not return true.

Implements ILIAS\Setup\Objective.

Definition at line 78 of file BackgoundWorkerObjective.php.

78 : bool
79 {
80 $ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
81
82 if (!$ini->groupExists('background_tasks')) {
83 return false;
84 }
85
86 return $ini->readVariable('background_tasks', 'concurrency') === SetupConfig::TYPE_ASYNCHRONOUS;
87 }

References ILIAS\$ini, ILIAS\Setup\Environment\getResource(), ILIAS\Setup\Environment\RESOURCE_ILIAS_INI, and ILIAS\BackgroundTasks\Setup\SetupConfig\TYPE_ASYNCHRONOUS.

+ Here is the call graph for this function:

◆ isNotable()

ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::isNotable ( )

Get to know if this is an interesting objective for a human.

Reimplemented from ILIAS\Setup\Objective\AdminConfirmedObjective.

Definition at line 63 of file BackgoundWorkerObjective.php.

63 : bool
64 {
65 return true;
66 }

Field Documentation

◆ $io

IOWrapper ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::$io = null
private

◆ $old_DIC

Container ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::$old_DIC = null
private

Definition at line 42 of file BackgoundWorkerObjective.php.

◆ $old_settings

ilSetting ILIAS\BackgroundTasks\Setup\BackgoundWorkerObjective::$old_settings = null
private

Definition at line 43 of file BackgoundWorkerObjective.php.


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