-
Notifications
You must be signed in to change notification settings - Fork 108
feat: trash (soft delete) #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: core-beta
Are you sure you want to change the base?
Changes from 7 commits
67d6d1f
a61cdb8
2477a42
cbf1d8f
1ddd6fc
1020778
afd294e
fe2577d
156d62b
ea55759
93e66de
cef726a
53ac5ee
a104e07
28a1778
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,12 +50,25 @@ class Snippet extends Data_Item { | |
| */ | ||
| public const DEFAULT_DATE = '0000-00-00 00:00:00'; | ||
|
|
||
| /** | ||
| * Raw active value from database before processing. | ||
| * | ||
| * @var mixed | ||
| */ | ||
| private $raw_active_value; | ||
|
|
||
| /** | ||
| * Constructor function. | ||
| * | ||
| * @param array<string, mixed>|object $initial_data Initial snippet data. | ||
| */ | ||
| public function __construct( $initial_data = null ) { | ||
| if ( is_array( $initial_data ) && isset( $initial_data['active'] ) ) { | ||
| $this->raw_active_value = $initial_data['active']; | ||
| } elseif ( is_object( $initial_data ) && isset( $initial_data->active ) ) { | ||
| $this->raw_active_value = $initial_data->active; | ||
| } | ||
|
|
||
| $default_values = array( | ||
| 'id' => 0, | ||
| 'name' => '', | ||
|
|
@@ -101,6 +114,15 @@ public function is_condition(): bool { | |
| return 'condition' === $this->scope; | ||
| } | ||
|
|
||
| /** | ||
| * Determine if the snippet is trashed (soft deleted). | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function is_trashed(): bool { | ||
| return '-1' === (string) $this->raw_active_value || -1 === (int) $this->raw_active_value; | ||
imantsk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
louiswol94 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Prepare a value before it is stored. | ||
| * | ||
|
|
@@ -120,7 +142,7 @@ protected function prepare_field( $value, string $field ) { | |
| return code_snippets_build_tags_array( $value ); | ||
|
|
||
| case 'active': | ||
| return ( is_bool( $value ) ? $value : (bool) $value ) && ! $this->is_condition(); | ||
| return ( is_bool( $value ) ? $value : (bool) $value ) && ! $this->is_condition() && (int) $value != -1; | ||
code-snippets-bot marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth changing the type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sheabunge Can we maybe do this in another PR. It started looking like a big scary change 🫣 |
||
|
|
||
| default: | ||
| return $value; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.