Skip to content
Snippets Groups Projects

Resolve #3508432 "Sortable undo by date"

Merged aaron.ferris requested to merge issue/scanner-3508432:3508432-sortable-undo-by-date into 2.0.x
@@ -8,6 +8,7 @@ use Drupal\Core\Link;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Controller for Search and Replace module.
@@ -17,7 +18,7 @@ class ScannerController extends ControllerBase {
/**
* Class constructor.
*/
public function __construct(protected DateFormatter $dateFormatter, protected Connection $database) {
public function __construct(protected DateFormatter $dateFormatter, protected Connection $database, protected RequestStack $requestStack) {
}
/**
@@ -29,6 +30,7 @@ class ScannerController extends ControllerBase {
// Load the service required to construct this class.
$container->get('date.formatter'),
$container->get('database'),
$container->get('request_stack')
);
}
@@ -39,26 +41,30 @@ class ScannerController extends ControllerBase {
* A render array (table).
*/
public function undoListing(): array {
$query = $this->database->query('SELECT * from {scanner} WHERE undone = 0');
$sort_order = $this->requestStack->getCurrentRequest()->query->get('sort', 'asc');
$query = $this->database->query("SELECT * from {scanner} WHERE undone = 0 ORDER BY time $sort_order");
$results = $query->fetchAll();
$header = [
$this->t('Date'),
[
'data' => $this->t('Date'),
'sortable' => TRUE,
'field' => 'date',
],
$this->t('Searched'),
$this->t('Replaced'),
$this->t('Count'),
$this->t('Operation'),
];
$rows = [];
// Build the rows of the table.
foreach ($results as $result) {
$undo_link = Link::fromTextAndUrl($this->t('Undo'), Url::fromUri("internal:/admin/content/scanner/undo/$result->undo_id/confirm"))->toString();
$rows[] = [
$this->dateFormatter->format($result->time),
$result->searched,
$result->replaced,
$result->count,
$undo_link,
$rows[$result->time] = [
'date' => $this->dateFormatter->format($result->time),
'searched' => $result->searched,
'replaced' => $result->replaced,
'count' => $result->count,
'undo_link' => $undo_link,
];
}
Loading