PartitionController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Table;
  4. use PhpMyAdmin\Html\Generator;
  5. use PhpMyAdmin\Response;
  6. use PhpMyAdmin\Table\Partition;
  7. use PhpMyAdmin\Template;
  8. use function strlen;
  9. final class PartitionController extends AbstractController
  10. {
  11. /** @var Partition */
  12. private $model;
  13. /**
  14. * @param Response $response
  15. * @param string $db
  16. * @param string $table
  17. * @param Partition $partition
  18. */
  19. public function __construct($response, Template $template, $db, $table, $partition)
  20. {
  21. parent::__construct($response, $template, $db, $table);
  22. $this->model = $partition;
  23. }
  24. public function analyze(): void
  25. {
  26. $partitionName = $_POST['partition_name'] ?? '';
  27. if (strlen($partitionName) === 0) {
  28. return;
  29. }
  30. [$rows, $query] = $this->model->analyze($this->db, $this->table, $partitionName);
  31. $message = Generator::getMessage(
  32. __('Your SQL query has been executed successfully.'),
  33. $query,
  34. 'success'
  35. );
  36. $this->render('table/partition/analyze', [
  37. 'partition_name' => $partitionName,
  38. 'message' => $message,
  39. 'rows' => $rows,
  40. ]);
  41. }
  42. public function check(): void
  43. {
  44. $partitionName = $_POST['partition_name'] ?? '';
  45. if (strlen($partitionName) === 0) {
  46. return;
  47. }
  48. [$rows, $query] = $this->model->check($this->db, $this->table, $partitionName);
  49. $message = Generator::getMessage(
  50. __('Your SQL query has been executed successfully.'),
  51. $query,
  52. 'success'
  53. );
  54. $this->render('table/partition/check', [
  55. 'partition_name' => $partitionName,
  56. 'message' => $message,
  57. 'rows' => $rows,
  58. ]);
  59. }
  60. public function drop(): void
  61. {
  62. $partitionName = $_POST['partition_name'] ?? '';
  63. if (strlen($partitionName) === 0) {
  64. return;
  65. }
  66. [$result, $query] = $this->model->drop($this->db, $this->table, $partitionName);
  67. if ($result) {
  68. $message = Generator::getMessage(
  69. __('Your SQL query has been executed successfully.'),
  70. $query,
  71. 'success'
  72. );
  73. } else {
  74. $message = Generator::getMessage(
  75. __('Error'),
  76. $query,
  77. 'error'
  78. );
  79. }
  80. $this->render('table/partition/drop', [
  81. 'partition_name' => $partitionName,
  82. 'message' => $message,
  83. ]);
  84. }
  85. public function optimize(): void
  86. {
  87. $partitionName = $_POST['partition_name'] ?? '';
  88. if (strlen($partitionName) === 0) {
  89. return;
  90. }
  91. [$rows, $query] = $this->model->optimize($this->db, $this->table, $partitionName);
  92. $message = Generator::getMessage(
  93. __('Your SQL query has been executed successfully.'),
  94. $query,
  95. 'success'
  96. );
  97. $this->render('table/partition/optimize', [
  98. 'partition_name' => $partitionName,
  99. 'message' => $message,
  100. 'rows' => $rows,
  101. ]);
  102. }
  103. public function rebuild(): void
  104. {
  105. $partitionName = $_POST['partition_name'] ?? '';
  106. if (strlen($partitionName) === 0) {
  107. return;
  108. }
  109. [$result, $query] = $this->model->rebuild($this->db, $this->table, $partitionName);
  110. if ($result) {
  111. $message = Generator::getMessage(
  112. __('Your SQL query has been executed successfully.'),
  113. $query,
  114. 'success'
  115. );
  116. } else {
  117. $message = Generator::getMessage(
  118. __('Error'),
  119. $query,
  120. 'error'
  121. );
  122. }
  123. $this->render('table/partition/rebuild', [
  124. 'partition_name' => $partitionName,
  125. 'message' => $message,
  126. ]);
  127. }
  128. public function repair(): void
  129. {
  130. $partitionName = $_POST['partition_name'] ?? '';
  131. if (strlen($partitionName) === 0) {
  132. return;
  133. }
  134. [$rows, $query] = $this->model->repair($this->db, $this->table, $partitionName);
  135. $message = Generator::getMessage(
  136. __('Your SQL query has been executed successfully.'),
  137. $query,
  138. 'success'
  139. );
  140. $this->render('table/partition/repair', [
  141. 'partition_name' => $partitionName,
  142. 'message' => $message,
  143. 'rows' => $rows,
  144. ]);
  145. }
  146. public function truncate(): void
  147. {
  148. $partitionName = $_POST['partition_name'] ?? '';
  149. if (strlen($partitionName) === 0) {
  150. return;
  151. }
  152. [$result, $query] = $this->model->truncate($this->db, $this->table, $partitionName);
  153. if ($result) {
  154. $message = Generator::getMessage(
  155. __('Your SQL query has been executed successfully.'),
  156. $query,
  157. 'success'
  158. );
  159. } else {
  160. $message = Generator::getMessage(
  161. __('Error'),
  162. $query,
  163. 'error'
  164. );
  165. }
  166. $this->render('table/partition/truncate', [
  167. 'partition_name' => $partitionName,
  168. 'message' => $message,
  169. ]);
  170. }
  171. }