/
Usage of Web Request & Session in CLI [5.3.0-B1]
Usage of Web Request & Session in CLI [5.3.0-B1]
There is no such concept as "Web Request" and "Session" or even "User is Logged In" concepts when In-Portal is executed from CLI (command-line). Yet the corresponding access methods for objects representing these concepts (GetVar, SetVar, RecallVar, StoreVar) still work and are used in In-Portal.
Solution
I propose, that we:
- sub-class the kApplication class and use that sub-class instead of kApplication class from CLI
- find usages of above mentioned methods, that at least make some sense in CLI
- extract those particular usages into methods on kApplication class
- change extracted methods in the CLI kApplication class version to return sane values
Concept | In Web Request | In CLI |
---|---|---|
logged-in user id | $this->Application->RecallVar('user_id') |
|
is ajax request | $this->Application->GetVar('ajax') == 'yes' |
|
current language id | $this->Application->GetVar('m_lang') |
|
current theme id | $this->Application->GetVar('m_theme') |
|
automatic object loading by ID in url | code inside "kDBEventHandler::StoreSelectedIDs" method |
|
getting current site domain field | $this->Application->siteDomainField('FieldName') |
|
current session id | $this->Application->GetSID() |
|
main popup window identifier | $this->Application->GetTopmostWid() |
|
popup window identifier | $this->Application->GetVar('m_wid') |
|
is current user logged-in | $this->Application->LoggedIn() |
|
website visitor IP address | $this->Application->getClientIP() |
|
attempt to read/write web request data |
|
|
attempt to read/write web request data | other methods |
|
attempt to read/write session data |
|
|
attempt to read/write session data | other methods |
|
Even though most of methods mentioned makes no sense in CLI they still return value that makes sense to avoid changing every call site.
Things, that usually are done from CLI
- sending e-mail
- can be several e-mails at once
- each e-mail on different language
- phrases used inside e-mail
- building a link
- to homepage
- to other page
- with use_section="1" attribute
- with mod-rewrite globally enabled
- with mod-rewrite globally disabled
- link to a category item
- printing a grid
- with help of PrintList/PrintList2 tags
- usage of InitList tag
- loading an item
- from database by given id