| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 | 
							- <?php
 
- declare(strict_types=1);
 
- namespace PhpMyAdmin\Server\Status;
 
- use PhpMyAdmin\DatabaseInterface;
 
- use PhpMyAdmin\Html\Generator;
 
- use PhpMyAdmin\Util;
 
- use function __;
 
- use function array_keys;
 
- use function count;
 
- use function mb_strtolower;
 
- use function strlen;
 
- use function ucfirst;
 
- final class Processes
 
- {
 
-     /** @var DatabaseInterface */
 
-     private $dbi;
 
-     public function __construct(DatabaseInterface $dbi)
 
-     {
 
-         $this->dbi = $dbi;
 
-     }
 
-     /**
 
-      * @param array $params Request parameters
 
-      *
 
-      * @return array<string, array|string|bool>
 
-      */
 
-     public function getList(array $params): array
 
-     {
 
-         $urlParams = [];
 
-         $showFullSql = ! empty($params['full']);
 
-         if ($showFullSql) {
 
-             $urlParams['full'] = '';
 
-         } else {
 
-             $urlParams['full'] = 1;
 
-         }
 
-         $sqlQuery = $showFullSql
 
-             ? 'SHOW FULL PROCESSLIST'
 
-             : 'SHOW PROCESSLIST';
 
-         if (
 
-             (! empty($params['order_by_field'])
 
-                 && ! empty($params['sort_order']))
 
-             || ! empty($params['showExecuting'])
 
-         ) {
 
-             $urlParams['order_by_field'] = $params['order_by_field'];
 
-             $urlParams['sort_order'] = $params['sort_order'];
 
-             $urlParams['showExecuting'] = $params['showExecuting'];
 
-             $sqlQuery = 'SELECT * FROM `INFORMATION_SCHEMA`.`PROCESSLIST` ';
 
-         }
 
-         if (! empty($params['showExecuting'])) {
 
-             $sqlQuery .= ' WHERE state != "" ';
 
-         }
 
-         if (! empty($params['order_by_field']) && ! empty($params['sort_order'])) {
 
-             $sqlQuery .= ' ORDER BY '
 
-                 . Util::backquote($params['order_by_field'])
 
-                 . ' ' . $params['sort_order'];
 
-         }
 
-         $result = $this->dbi->query($sqlQuery);
 
-         $rows = [];
 
-         while ($process = $result->fetchAssoc()) {
 
-             // Array keys need to modify due to the way it has used
 
-             // to display column values
 
-             foreach (array_keys($process) as $key) {
 
-                 $newKey = ucfirst(mb_strtolower($key));
 
-                 if ($newKey === $key) {
 
-                     continue;
 
-                 }
 
-                 $process[$newKey] = $process[$key];
 
-                 unset($process[$key]);
 
-             }
 
-             $rows[] = [
 
-                 'id' => $process['Id'],
 
-                 'user' => $process['User'],
 
-                 'host' => $process['Host'],
 
-                 'db' => ! isset($process['Db']) || strlen($process['Db']) === 0 ? '' : $process['Db'],
 
-                 'command' => $process['Command'],
 
-                 'time' => $process['Time'],
 
-                 'state' => ! empty($process['State']) ? $process['State'] : '---',
 
-                 'progress' => ! empty($process['Progress']) ? $process['Progress'] : '---',
 
-                 'info' => ! empty($process['Info']) ? Generator::formatSql($process['Info'], ! $showFullSql) : '---',
 
-             ];
 
-         }
 
-         return [
 
-             'columns' => $this->getSortableColumnsForProcessList($showFullSql, $params),
 
-             'rows' => $rows,
 
-             'refresh_params' => $urlParams,
 
-             'is_mariadb' => $this->dbi->isMariaDB(),
 
-         ];
 
-     }
 
-     private function getSortableColumnsForProcessList(bool $showFullSql, array $params): array
 
-     {
 
-         // This array contains display name and real column name of each
 
-         // sortable column in the table
 
-         $sortableColumns = [
 
-             [
 
-                 'column_name' => __('ID'),
 
-                 'order_by_field' => 'Id',
 
-             ],
 
-             [
 
-                 'column_name' => __('User'),
 
-                 'order_by_field' => 'User',
 
-             ],
 
-             [
 
-                 'column_name' => __('Host'),
 
-                 'order_by_field' => 'Host',
 
-             ],
 
-             [
 
-                 'column_name' => __('Database'),
 
-                 'order_by_field' => 'Db',
 
-             ],
 
-             [
 
-                 'column_name' => __('Command'),
 
-                 'order_by_field' => 'Command',
 
-             ],
 
-             [
 
-                 'column_name' => __('Time'),
 
-                 'order_by_field' => 'Time',
 
-             ],
 
-             [
 
-                 'column_name' => __('Status'),
 
-                 'order_by_field' => 'State',
 
-             ],
 
-         ];
 
-         if ($this->dbi->isMariaDB()) {
 
-             $sortableColumns[] = [
 
-                 'column_name' => __('Progress'),
 
-                 'order_by_field' => 'Progress',
 
-             ];
 
-         }
 
-         $sortableColumns[] = [
 
-             'column_name' => __('SQL query'),
 
-             'order_by_field' => 'Info',
 
-         ];
 
-         $sortableColCount = count($sortableColumns);
 
-         $columns = [];
 
-         foreach ($sortableColumns as $columnKey => $column) {
 
-             $is_sorted = ! empty($params['order_by_field'])
 
-                 && ! empty($params['sort_order'])
 
-                 && ($params['order_by_field'] == $column['order_by_field']);
 
-             $column['sort_order'] = 'ASC';
 
-             if ($is_sorted && $params['sort_order'] === 'ASC') {
 
-                 $column['sort_order'] = 'DESC';
 
-             }
 
-             if (isset($params['showExecuting'])) {
 
-                 $column['showExecuting'] = 'on';
 
-             }
 
-             $columns[$columnKey] = [
 
-                 'name' => $column['column_name'],
 
-                 'params' => $column,
 
-                 'is_sorted' => $is_sorted,
 
-                 'sort_order' => $column['sort_order'],
 
-                 'has_full_query' => false,
 
-                 'is_full' => false,
 
-             ];
 
-             if (0 !== --$sortableColCount) {
 
-                 continue;
 
-             }
 
-             $columns[$columnKey]['has_full_query'] = true;
 
-             if (! $showFullSql) {
 
-                 continue;
 
-             }
 
-             $columns[$columnKey]['is_full'] = true;
 
-         }
 
-         return $columns;
 
-     }
 
- }
 
 
  |