Skip to content

Commit

Permalink
Fix is_read value in Admin notes (#43096)
Browse files Browse the repository at this point in the history
* Add is_read property to note data

* Add changefile(s) from automation for the following project(s): woocommerce

* Remove unnecessary type casting

* Fix boolean typecasting in DataStore and Note classes

* Restoring the original `isset( $note_row->is_read )` condition. I believe it's there for notes without this property.

* WC_Admin_Tests_Notes_Data_Store::test_read to account for return type of `get_is_snoozable`.

---------

Co-authored-by: Simran <simran.kaur@automattic.com>
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: And Finally <andfinally@users.noreply.github.com>
  • Loading branch information
4 people committed Mar 20, 2024
1 parent 1adeaf2 commit 28f79b4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Fix `is_read` value in Admin notes.
9 changes: 5 additions & 4 deletions plugins/woocommerce/src/Admin/Notes/DataStore.php
Expand Up @@ -37,6 +37,7 @@ public function create( &$note ) {
'layout' => $note->get_layout(),
'image' => $note->get_image(),
'is_deleted' => (int) $note->get_is_deleted(),
'is_read' => (int) $note->get_is_read(),
);

$note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data() );
Expand Down Expand Up @@ -109,7 +110,7 @@ public function read( &$note ) {
$note->set_source( $note_row->source );
$note->set_date_created( $note_row->date_created );
$note->set_date_reminder( $note_row->date_reminder );
$note->set_is_snoozable( $note_row->is_snoozable );
$note->set_is_snoozable( (bool) $note_row->is_snoozable );
$note->set_is_deleted( (bool) $note_row->is_deleted );
isset( $note_row->is_read ) && $note->set_is_read( (bool) $note_row->is_read );
$note->set_layout( $note_row->layout );
Expand Down Expand Up @@ -162,11 +163,11 @@ public function update( &$note ) {
'source' => $note->get_source(),
'date_created' => $date_created_to_db,
'date_reminder' => $date_reminder_to_db,
'is_snoozable' => $note->get_is_snoozable(),
'is_snoozable' => (int) $note->get_is_snoozable(),
'layout' => $note->get_layout(),
'image' => $note->get_image(),
'is_deleted' => $note->get_is_deleted(),
'is_read' => $note->get_is_read(),
'is_deleted' => (int) $note->get_is_deleted(),
'is_read' => (int) $note->get_is_read(),
),
array( 'note_id' => $note->get_id() )
);
Expand Down
4 changes: 2 additions & 2 deletions plugins/woocommerce/src/Admin/Notes/Note.php
Expand Up @@ -339,7 +339,7 @@ public function get_image( $context = 'view' ) {
* Get deleted status.
*
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
* @return array
* @return bool
*/
public function get_is_deleted( $context = 'view' ) {
return $this->get_prop( 'is_deleted', $context );
Expand All @@ -349,7 +349,7 @@ public function get_is_deleted( $context = 'view' ) {
* Get is_read status.
*
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
* @return array
* @return bool
*/
public function get_is_read( $context = 'view' ) {
return $this->get_prop( 'is_read', $context );
Expand Down
Expand Up @@ -45,7 +45,7 @@ public function test_read() {
$this->assertEquals( $note->get_type(), $read_note->get_type() );
$this->assertEquals( $note->get_name(), $read_note->get_name() );
$this->assertEquals( $note->get_source(), $read_note->get_source() );
$this->assertEquals( $note->get_is_snoozable(), '0' !== $read_note->get_is_snoozable() );
$this->assertEquals( $note->get_is_snoozable(), false !== $read_note->get_is_snoozable() );
$this->assertEquals( $note->get_layout(), $read_note->get_layout() );
$this->assertEquals( $note->get_image(), $read_note->get_image() );
$this->assertEquals( $note->get_actions(), $read_note->get_actions() );
Expand Down

0 comments on commit 28f79b4

Please sign in to comment.