We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53477
    • 9 Posts
    When open /manager/?a=system/logs in mgr.

    I see 4 сolumn:
    Event, User, Action, Object

    How to add a user to the field in the user field in parentheses of the contents of the field from the user's profile "Full name".

    I want it to look something like this:
    23-05-2017, 10:52 am user001(Ryzhikov Petr Petrovich) login web
    but not
    23-05-2017, 10:52 am user001 login web

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      I don't think this is possible without hacking the MODX core. All that's stored in the DB table is the user's ID, and the function that saves the log item would crash if you sent it something else. The DB file is an integer field, so it wouldn't hold a string.

      If you could find the code that *displays* the Manage Action log, you could modify it to get the user profile from the ID and display what you want about the user.

      You'd have to make your change again every time you upgraded MODX.

      I looked for that code, but couldn't find it.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 53477
        • 9 Posts
        Quote from: BobRay at May 23, 2017, 11:14 PM
        I don't think this is possible without hacking the MODX core. All that's stored in the DB table is the user's ID, and the function that saves the log item would crash if you sent it something else. The DB file is an integer field, so it wouldn't hold a string.

        If you could find the code that *displays* the Manage Action log, you could modify it to get the user profile from the ID and display what you want about the user.

        You'd have to make your change again every time you upgraded MODX.

        I looked for that code, but couldn't find it.

        File is there core/model/modx/processors/system/log/getlist.class.php

        But i dont known how modify it sad
        • discuss.answer
          • 3749
          • 24,544 Posts
          It was a little tricky to work out. I assumed the grid would use the 'user' field, for the "User" column, but it used the 'username' field, so you can modify that in the prepareLog() method:

              public function prepareLog(modManagerLog $log) {
                  $logArray = $log->toArray();
                  if (!empty($logArray['classKey']) && !empty($logArray['item']) && $logArray['item'] !== 'unknown') {
                      $logArray['name'] = $logArray['classKey'] . ' (' . $logArray['item'] . ')';
                      /** @var xPDOObject $obj */
                      $obj = $this->modx->getObject($logArray['classKey'], $logArray['item']);
                      if ($obj && ($obj->get($obj->getPK()) == $logArray['item'])) {
                          $nameField = $this->getNameField($logArray['classKey']);
                          $k = $obj->getField($nameField, true);
                          if (!empty($k)) {
                              $pk = $obj->get('id');
                              $logArray['name'] = $obj->get($nameField).(!empty($pk) ? ' ('.$pk.')' : '');
                          }
                      }
                  } else {
                      $logArray['name'] = $log->get('item');
                  }
                  $logArray['occurred'] = date($this->getProperty('dateFormat'), strtotime($logArray['occurred']));
          
          /* Add this *******************************  */    
                  $userId = $this->modx->getOption('user', $logArray, '', true);
                  if (!empty($userId)) {
                      $profile = $this->modx->getObject('modUserProfile', array('internalKey' => $userId));
                      if ($profile) {
                          $logArray['username'] = $logArray['username'] . ' (' . $profile->get('fullname') . ')';
                      }
                  }
          /* *******************************  */    
                  return $logArray;
              }
          

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 53477
            • 9 Posts
            Quote from: BobRay at May 24, 2017, 06:26 PM
            It was a little tricky to work out. I assumed the grid would use the 'user' field, for the "User" column, but it used the 'username' field, so you can modify that in the prepareLog() method:

                public function prepareLog(modManagerLog $log) {
                    $logArray = $log->toArray();
                    if (!empty($logArray['classKey']) && !empty($logArray['item']) && $logArray['item'] !== 'unknown') {
                        $logArray['name'] = $logArray['classKey'] . ' (' . $logArray['item'] . ')';
                        /** @var xPDOObject $obj */
                        $obj = $this->modx->getObject($logArray['classKey'], $logArray['item']);
                        if ($obj && ($obj->get($obj->getPK()) == $logArray['item'])) {
                            $nameField = $this->getNameField($logArray['classKey']);
                            $k = $obj->getField($nameField, true);
                            if (!empty($k)) {
                                $pk = $obj->get('id');
                                $logArray['name'] = $obj->get($nameField).(!empty($pk) ? ' ('.$pk.')' : '');
                            }
                        }
                    } else {
                        $logArray['name'] = $log->get('item');
                    }
                    $logArray['occurred'] = date($this->getProperty('dateFormat'), strtotime($logArray['occurred']));
            
            /* Add this *******************************  */    
                    $userId = $this->modx->getOption('user', $logArray, '', true);
                    if (!empty($userId)) {
                        $profile = $this->modx->getObject('modUserProfile', array('internalKey' => $userId));
                        if ($profile) {
                            $logArray['username'] = $logArray['username'] . ' (' . $profile->get('fullname') . ')';
                        }
                    }
            /* *******************************  */    
                    return $logArray;
                }
            


            Thank you very much! You are a magician!
              • 3749
              • 24,544 Posts
              Glad I could help. smiley

              PS: If I were a magician, it wouldn't have taken me two hours to figure out. wink
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting