Ignore:
Timestamp:
Mar 6, 2023, 1:48:45 AM (22 months ago)
Author:
chronos
Message:
  • Fixed: Class types casting for better type checking.
  • Fixed: XML direct export.
  • Modified: User class instance moved from Core class to ModuleUser class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Log/Log.php

    r891 r893  
    3333  function WriteLog($Text, $Type)
    3434  {
    35     if (isset($this->System->User) and !is_null($this->System->User->Id))
    36       $UserId = $this->System->User->Id;
     35    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
     36    if (isset($User) and !is_null($User->Id))
     37      $UserId = $User->Id;
    3738      else $UserId = 'NULL';
    3839    $Query = 'INSERT INTO `Log` ( `User` , `Type` , `Text` , `Date` , `IP`, `URL` ) '.
     
    4041      GetRemoteAddress().'", "'.GetRequestURI().'")';
    4142    $this->System->Database->query($Query);
     43  }
     44
     45  static function Cast(Module $Module): ModuleLog
     46  {
     47    if ($Module instanceof ModuleLog)
     48    {
     49      return $Module;
     50    }
     51    throw new Exception('Expected '.ModuleLog::GetClassName().' type but got '.gettype($Module));
    4252  }
    4353}
     
    91101      (
    92102        'Title' => $LogType['Name'].' ('.$Line['UserName'].', '.$Line['IP'].')',
    93         'Link' => 'https://'.$this->System->Config['Web']['Host'].$this->System->Link('/log/'),
     103        'Link' => 'https://'.Core::Cast($this->System)->Config['Web']['Host'].$this->System->Link('/log/'),
    94104        'Description' => $LogType['Name'].': '.$Line['Text'].' ('.$Line['UserName'].
    95105          ', '.$Line['IP'].', '.HumanDate($Line['Date']).')',
     
    100110    $Output .= GenerateRSS(array
    101111    (
    102       'Title' => $this->System->Config['Web']['Title'].' - '.T('Logs'),
    103       'Link' => 'https://'.$this->System->Config['Web']['Host'].$this->System->Link('/'),
    104       'Description' => $this->System->Config['Web']['Description'],
    105       'WebmasterEmail' => $this->System->Config['Web']['AdminEmail'],
     112      'Title' => Core::Cast($this->System)->Config['Web']['Title'].' - '.T('Logs'),
     113      'Link' => 'https://'.Core::Cast($this->System)->Config['Web']['Host'].$this->System->Link('/'),
     114      'Description' => Core::Cast($this->System)->Config['Web']['Description'],
     115      'WebmasterEmail' => Core::Cast($this->System)->Config['Web']['AdminEmail'],
    106116      'Items' => $Items,
    107117    ));
     
    121131  function ShowList()
    122132  {
     133    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
    123134    $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    124135
     
    141152
    142153    // Show category filter
    143     if ($this->System->User->Licence(LICENCE_MODERATOR))
     154    if ($User->Licence(LICENCE_MODERATOR))
    144155    {
    145156      $Output = '<strong>'.T('Filter').':</strong>';
     
    203214    $Output .= '</table>'.
    204215      $PageList['Output'];
    205       if ($this->System->User->Licence(LICENCE_ADMIN))
     216      if ($User->Licence(LICENCE_ADMIN))
    206217      {
    207218        $Output .= '<div>'.T('Remove').': <a href="'.$this->System->Link('/log/?a=delerrlog&amp;type='.LOG_TYPE_ERROR).'">'.T('Error logs').'</a> '.
     
    215226  function DeleteErrorLog()
    216227  {
    217     if ($this->System->User->Licence(LICENCE_ADMIN) and
     228    $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
     229    if ($User->Licence(LICENCE_ADMIN) and
    218230    (($_GET['type'] == LOG_TYPE_ERROR) or ($_GET['type'] == LOG_TYPE_PAGE_NOT_FOUND)))
    219231    {
Note: See TracChangeset for help on using the changeset viewer.