Skip to content

Commit

Permalink
Merge pull request #29 from joomdonation/export_logs_improvement
Browse files Browse the repository at this point in the history
Improve export logs + purge
thanks @joomdonation
  • Loading branch information
alikon authored May 11, 2018
2 parents f663a82 + 26a06e8 commit 98cb5cf
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 15 deletions.
54 changes: 40 additions & 14 deletions administrator/components/com_userlogs/controllers/userlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
*/
class UserlogsControllerUserlogs extends JControllerAdmin
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
*
* @since __DEPLOY_VERSION__
*/
public function __construct(array $config = array())
{
parent::__construct($config);

$this->registerTask('exportSelectedLogs', 'exportLogs');
}

/**
* Method to get a model object, loading it if required.
*
Expand Down Expand Up @@ -50,11 +64,22 @@ public function exportLogs()
// Check for request forgeries.
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));

// Get selected logs
$pks = ArrayHelper::toInteger($this->input->post->get('cid', array(), 'array'));

// Get the logs data
$data = $this->getModel('userlogs')->getLogsData();
$data = $this->getModel('userlogs')->getLogsData($pks);

// Export data to CSV file
UserlogsHelper::dataToCsv($data);
if (count($data))
{
// Export data to CSV file
UserlogsHelper::dataToCsv($data);
}
else
{
$this->setMessage(JText::_('COM_USERLOGS_NO_LOGS_TO_EXPORT'));
$this->setRedirect(JRoute::_('index.php?option=com_userlogs&view=userlogs'));
}
}

/**
Expand All @@ -77,24 +102,25 @@ public function delete()
}

/**
* Method to export selected logs
* Clean out the logs
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function exportSelectedLogs()
public function purge()
{
// Check for request forgeries.
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));

// Get selected logs
$pks = ArrayHelper::toInteger($this->input->post->get('cid', array(), 'array'));
$model = $this->getModel();

// Get the logs data
$data = $this->getModel('userlogs')->getLogsData($pks);
if ($model->purge())
{
$message = JText::_('COM_USERLOGS_PURGE_SUCCESS');
}
else
{
$message = JText::_('COM_REDIRECT_PURGE_FAIL');
}

// Export data to CSV file
UserlogsHelper::dataToCsv($data);
$this->setRedirect(JRoute::_('index.php?option=com_userlogs&view=userlogs'), $message);
}
}
21 changes: 21 additions & 0 deletions administrator/components/com_userlogs/models/userlogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,25 @@ public function delete(&$pks)
return false;
}
}

/**
* Removes all of logs from the table.
*
* @return boolean result of operation
*
* @since __DEPLOY_VERSION__
*/
public function purge()
{
try
{
$this->getDbo()->truncateTable('#__user_logs');

return true;
}
catch (Exception $e)
{
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ protected function addToolbar()
if (JFactory::getUser()->authorise('core.delete', 'com_userlogs'))
{
JToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'userlogs.delete');
$bar = JToolbar::getInstance('toolbar');
$bar->appendButton('Confirm', 'COM_USERLOGS_PURGE_CONFIRM', 'delete', 'COM_USERLOGS_TOOLBAR_PURGE', 'userlogs.purge', false);
}

if (JFactory::getUser()->authorise('core.admin', 'com_userlogs') || JFactory::getUser()->authorise('core.options', 'com_userlogs'))
Expand Down
7 changes: 6 additions & 1 deletion administrator/language/en-GB/en-GB.com_userlogs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ COM_USERLOGS_MESSAGE_ASC="Message ascending"
COM_USERLOGS_MESSAGE_DESC="Message descending"
COM_USERLOGS_N_ITEMS_DELETED="%s logs deleted."
COM_USERLOGS_N_ITEMS_DELETED_1="%s log deleted."
COM_USERLOGS_NO_LOGS_TO_EXPORT="There are no User Action logs to export."
COM_USERLOGS_NO_ITEM_SELECTED="Please first make a selection from the list."
COM_USERLOGS_OPTION_FILTER_DATE="- Select Date -"
COM_USERLOGS_OPTION_RANGE_NEVER="Never"
Expand All @@ -33,9 +34,13 @@ COM_USERLOGS_OPTION_RANGE_PAST_WEEK="In the last week"
COM_USERLOGS_OPTION_RANGE_PAST_YEAR="In the last year"
COM_USERLOGS_OPTION_RANGE_POST_YEAR="More than a year ago"
COM_USERLOGS_OPTION_RANGE_TODAY="Today"
COM_USERLOGS_PURGE_CONFIRM="Are you sure want to delete all User Action logs?"
COM_USERLOGS_PURGE_FAIL="Failed to delete all User Action logs."
COM_USERLOGS_PURGE_SUCCESS="All User Action logs have been deleted."
COM_USERLOGS_TOOLBAR_PURGE="Purge"
COM_USERLOGS_SELECT_EXTENSION="- Select Extension -"
COM_USERLOGS_SELECT_USER="- Select User -"
COM_USERLOGS_NAME="Name"
COM_USERLOGS_NAME_ASC="Name ascending"
COM_USERLOGS_NAME_DESC="Name descending"
COM_USERLOGS_XML_DESCRIPTION = "The component that views the log of the actions of different users."
COM_USERLOGS_XML_DESCRIPTION = "The component that views the log of the actions of different users."

0 comments on commit 98cb5cf

Please sign in to comment.