J3.x: Καταγραφή Ενεργειών Χρήστη
From Joomla! Documentation
Πως να χρησιμοποιήσετε το νέο σύστημα Καταγραφής Ενεργειών Χρήστη
Από την έκδοση Joomla 3.9, ενσωματώθηκε το σύστημα καταγραφής ενεργειών στο core.
This system is the finalization of the "Recording Action Logs" project from GSoC 2016. This system provides an infrastructure to create an audit log of activity performed on a website and can be fine tuned to the site admin's preferences. Extensions are able to hook into this system to add custom messages or have the system process standard CRUD actions.
Σε αυτόν τον οδηγό, θα βρείτε όλες τις πληροφορίες για το πως θα στήσετε αυτό το νέο σύστημα.
Σημείωση: Μόνο οι Διαχειριστές έχουν πρόσβαση στο Σύστημα Καταγραφής ενεργειών.
Εφαρμογή
Αρχείο Καταγραφής Ενεργειών Χρήστη
Πλοηγηθείτε στο Χρήστες → Αρχείο καταγραφής ενεργειών χρήστη για να δείτε το αρχείο καταγραφής ενεργειών χρήστη.
File:Joomla-39-action-logs-dashboard-el.png
From this screen a Super User has a global overview of all activities performed on a site by users and has the ability to review, export, delete and purge entries.
Για να μάθετε περισσότερα, παρακαλούμε διαβάστε:
Πρόσθετο
Σύστημα - Αρχείο καταγραφής ενεργειών χρήστη
Εάν ενεργοποιηθεί, επιτρέπει τον ορισμό των ημερών που θα διατηρούνται τα αρχεία καταγραφής πριν διαγραφούν.
Αρχείο Καταγραφής
Εάν ενεργοποιηθεί, καταγράφει τις ενέργειες των χρηστών στις επεκτάσεις του πυρήνα του Joomla, ώστε να μπορούν να ελεγχθούν αν χρειαστεί.
Προστασία δεδομένων - Αρχείο Καταγραφής Ενεργειών
Εάν ενεργοποιηθεί, δίνει την δυνατότητα εξαγωγής δεδομένων καταγραφής ενεργειών μετά από αίτημα ενός χρήστη.
Ένθεμα
Action Logs - Latest Module
This admin module shows on the control panel a list of the latest actions performed on a site.
File:Joomla-39-action-logs-latest-module-el.png
Note: The module is not displayed by default on sites upgrading to Joomla 3.9. In order to display it on your control panel, navigate to Extensions → Manage → Manage → Enable the System - User Actions Log plugin and then go to Extensions → Modules → Administrator → New → Action Logs-Latest
Διαβάστε επίσης: Latest Actions Admin Module.
Πώς να συνδέσετε μια επέκταση στο σύστημα
Εάν πιστεύετε ότι χρειάζονται αλλαγές ή βελτιώσεις σε αυτόν τον τομέα, μην διστάσετε να προσθέσετε ή να επεξεργαστείτε πληροφορίες.
Component Installation Script
Προσθέστε την επέκταση στον πίνακα (#__action_logs_extensions) έτσι ώστε να εμφανιστεί στις ρυθμίσεις της Καταγραφής Ενεργειών Χρήστη
$extension = 'com_mycomponent';
$db = \Joomla\CMS\Factory::getDbo();
$db->setQuery(' INSERT into #__action_logs_extensions (extension) VALUES ('.$db->Quote($extension).') ' );
try {
// If it fails, it will throw a RuntimeException
$result = $db->execute();
} catch (RuntimeException $e) {
\Joomla\CMS\Factory::getApplication()->enqueueMessage($e->getMessage());
return false;
}
Προσθέστε την επέκταση στον πίνακα (#__action_log_config) έτσι ώστε να συλλέγονται οι πληροφορίες των ενεργειών.
$logConf = new stdClass();
$logConf->id = 0;
$logConf->type_title = 'transaction';
$logConf->type_alias = $extension;
$logConf->id_holder = 'id';
$logConf->title_holder = 'trans_desc';
$logConf->table_name = '#__mycomponent_transaction';
$logConf->text_prefix = 'COM_MYCOMPONENT_TRANSACTION';
try {
// If it fails, it will throw a RuntimeException
// Insert the object into the table.
$result = Factory::getDbo()->insertObject('#__action_log_config', $logConf);
} catch (RuntimeException $e) {
\Joomla\CMS\Factory::getApplication()->enqueueMessage($e->getMessage());
return false;
}
Φυσικά, θα ήταν καλό να κάνετε έναν έλεγχο, ώστε να σιγουρευτείτε ότι οι εγγραφές δεν υπάρχουν ήδη.
Βοηθός Εφαρμογής
In this example, the component helper is used to perform the storing of actions.
/**
* Record transaction details in log record
* @param object $user Saves getting the current user again.
* @param int $tran_id The transaction id just created or updated
* @param int $id Passed id reference from the form to identify if new record
* @return boolean True
*/
public static function recordActionLog($user = null, $tran_id = 0, $id = 0)
{
// get the component details such as the id
$extension = MycomponentHelper::getExtensionDetails('com_mycomponent');
// get the transaction details for use in the log for easy reference
$tran = MycomponentHelper::getTransaction($tran_id);
$con_type = "transaction";
if ($id === 0) { $type = 'New '; } else { $type = 'Update '; }
$message = array();
$message['action'] = $con_type;
$message['type'] = $type . $tran->tran_type . ' - '.$tran->tran_desc . ' $' . $tran->tran_amount;
$message['id'] = $tran->id;
$message['title'] = $extension->name;
$message['extension_name'] = $extension->name;
$message['itemlink'] = "index.php?option=com_mycomponent&task=transaction.edit&id=".$tran->id;
$message['userid'] = $user->id;
$message['username'] = $user->username;
$message['accountlink'] = "index.php?option=com_users&task=user.edit&id=".$user->id;
$messages = array($message);
$messageLanguageKey = Text::_('COM_MYCOMPONENT_TRANSACTION_LINK');
$context = $extension->name.'.'.$con_type;
$fmodel = MycomponentHelper::getForeignModel('Actionlog', 'ActionlogsModel');
$fmodel->addLog($messages, $messageLanguageKey, $context, $user->id);
return true;
}
/**
* Get the Model from another component for use
* @param string $name The model name. Optional. Default to my own for safety.
* @param string $prefix The class prefix. Optional
* @param array $config Configuration array for model. Optional
* @return object The model
*/
public function getForeignModel($name = 'Transaction', $prefix = 'MycomponentModel', $config = array('ignore_request' => true))
{
\Joomla\CMS\MVC\Model\ItemModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_actionlogs/models', 'ActionlogsModelActionlog');
$fmodel = \Joomla\CMS\MVC\Model\ItemModel::getInstance($name, $prefix, $config);
return $fmodel;
}
Front End Transaction Form
Now that the foundations are set, we just need to trigger the process. We're capturing information about a transaction that is created or update and we have a model called transactionform.php. It is in the Save method that we want to capture a log.
// So the code above this point checks and does what it should do and then after the successful save of the record, we check for the parameter setting to see if logging is required, we pass key elements to recordActionLog.
$table = $this->getTable();
if ($table->save($data) === true) {
/* ---------------------------------------------------------------- */
// trigger transaction log if required
$act_log = $params->get('act_log', 0);
if ($act_log && $table->id) {
// gather information and log in a new action log record
MycomponentHelper::recordActionLog($user, $table->id, $data['id']);
}
/* ---------------------------------------------------------------- */
return $table->id;
} else {
return false;
}
Αρχείο Γλώσσας
Finally, to help with the Action Log Listing in the admin side of Joomla, we want to set some key elements of data to be displayed in the language file en-GB.com_mycomponent.ini.
COM_MYCOMPONENT_TRANSACTION_LINK="User <a href='{accountlink}'>{username}</a> created a transaction ( <a href='{itemlink}'>{type}</a> )"
Ελπίζουμε να βοηθήσαμε.