Skip to content

Commit

Permalink
[K6.3] Refactor log clean view into modal making log controller / mod…
Browse files Browse the repository at this point in the history
…el / vi… (Kunena#9637)

* Refactor log clean view into modal making log controller / model / view obsolete

* Refactor log clean view into modal making log controller / model / view obsolete
  • Loading branch information
Ruud68 authored Feb 29, 2024
1 parent b6628c4 commit cd95def
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 876 deletions.
116 changes: 0 additions & 116 deletions src/admin/src/Controller/LogController.php

This file was deleted.

60 changes: 40 additions & 20 deletions src/admin/src/Controller/LogsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

\defined('_JEXEC') or die();


use Exception;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Factory;
Expand Down Expand Up @@ -52,30 +53,49 @@ public function __construct($config = [])
}

/**
* Redirect user to the right layout in order to define some settings
* Clean
*
* @return void
* @return bool
*
* @since Kunena 5.0
* @since Kunena 6.3.0-BETA3
* @throws \Exception
*/
public function cleanEntries(): void
public function clean()
{
$this->setRedirect(Route::_("index.php?option=com_kunena&view=log&layout=clean", false));
}
if (!Session::checkToken()) {
$this->app->enqueueMessage(Text::_('COM_KUNENA_ERROR_TOKEN'), 'error');
$this->setRedirect(KunenaRoute::_($this->baseurl, false));

/**
* Method to just redirect to main manager in case of use of cancel button
*
* @param null $key key
* @param null $urlVar url var
*
* @return void
*
* @throws Exception
* @since Kunena 5.0
*/
public function cancel($key = null, $urlVar = null)
{
$this->app->redirect(KunenaRoute::_($this->baseurl, false));
return false;
}

$days = $this->input->getInt('clean_days', 0);
$timestamp = new Date('now -' . $days . ' days');

$db = Factory::getContainer()->get('DatabaseDriver');
$query = $db->getQuery(true)
->delete('#__kunena_logs')
->where('time < ' . $timestamp->toUnix());

$db->setQuery($query);

try {
$db->execute();
} catch (Exception $e) {
$this->app->enqueueMessage($e->getMessage(), 'error');
$this->setRedirect(KunenaRoute::_($this->baseurl, false));

return false;
}

$numRows = $db->getAffectedRows();

if ($numRows > 0) {
$this->app->enqueueMessage(Text::sprintf('COM_KUNENA_LOG_ENTRIES_DELETED', $numRows), 'success');
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
} else {
$this->app->enqueueMessage(Text::_('COM_KUNENA_LOG_ENTRIES_DELETED_NOTHING_TO_DELETE'), 'notice');
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
}
}
}
Loading

0 comments on commit cd95def

Please sign in to comment.