class-delete.php
6 months ago
class-export.php
1 week ago
class-global-replace.php
6 months ago
class-modify.php
6 months ago
class-nothing.php
6 months ago
class-run.php
1 week ago
class-delete.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex\Action\Type; |
| 4 | |
| 5 | use SearchRegex\Action\Action; |
| 6 | use SearchRegex\Source; |
| 7 | use SearchRegex\Plugin; |
| 8 | |
| 9 | /** |
| 10 | * Action to delete rows |
| 11 | */ |
| 12 | class Delete extends Action { |
| 13 | /** |
| 14 | * Track how many rows have been deleted |
| 15 | */ |
| 16 | private int $deleted = 0; |
| 17 | |
| 18 | /** |
| 19 | * @return array<string, mixed> |
| 20 | */ |
| 21 | public function to_json() { |
| 22 | return [ |
| 23 | 'action' => 'delete', |
| 24 | ]; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @param int $row_id |
| 29 | * @param array<string, mixed> $row |
| 30 | * @param Source\Source $source |
| 31 | * @param array<\SearchRegex\Search\Column> $columns |
| 32 | * @return array<\SearchRegex\Search\Column> |
| 33 | */ |
| 34 | public function perform( $row_id, array $row, Source\Source $source, array $columns ) { |
| 35 | if ( $this->should_save() ) { |
| 36 | $this->deleted++; |
| 37 | |
| 38 | $this->log_action( 'Delete: ' . $source->get_table_name() . ' row ' . (string) $row_id ); |
| 39 | |
| 40 | if ( Plugin\Settings::init()->can_save() ) { |
| 41 | $source->delete_row( $row_id ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | return $columns; |
| 46 | } |
| 47 | } |
| 48 |