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
Fix is_read value in Admin notes #43096
Conversation
Test Results SummaryCommit SHA: a63502f
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
Hi @Dan-Q, @andfinally, @raicem, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
Hi @andfinally, @raicem, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
1 similar comment
Hi @andfinally, @raicem, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this simpler approach: it's more minimal than earlier versions of this PR. And it fixes the WCCOM issue 16504-gh-Automattic/woocommerce.com. It would be helpful to have a more detailed explanation of why we need to do this, though. In particular, what goes wrong when we cast is_deleted
or is_read
as Boolean in DataStore::read
?
I tried this test from woocommerce/woocommerce-admin#6322, and it created Notes with is_deleted
and is_read
set to 1
in the DB table as expected.
add_action( 'plugins_loaded', function () {
$note = new Automattic\WooCommerce\Admin\Notes\Note();
$note->set_name( 'wc-undismissable-note' );
$note->set_title( 'Undismissable note' );
$note->set_content( 'I don\'t wanna dismiss a thing' );
$note->set_content_data( (object) array() );
$note->set_type( 'info' );
$note->set_source( 'woocommerce-admin' );
$note->add_action( 'learn-more', __( 'Learn more', 'woocommerce' ), 'https://woocommerce.com/', 'actioned', true );
$note->set_is_deleted( true );
$note->set_is_read( 1 );
$note->save();
$note = new Automattic\WooCommerce\Admin\Notes\Note( $note->get_id() );
var_dump( $note->get_is_deleted() ); // Should return `true`.
exit;
} );
BTW, I noticed that the return types defined for Note::get_is_read
and Note::get_is_deleted
are incorrect – they should be boolean
instead of array
, same as Note::get_is_snoozable
.
@andfinally, I have noted your suggestion related to fixing the return type of Since we're having the discussion in the PR: https://github.com/Automattic/woocommerce.com/pull/19118, I'll commit the suggestion after our discussion. |
@andfinally, I have moved the typecasting to the update function and fixed the return type of get_is_read and get_is_deleted in phpdoc. I'd appreciate it if you could review the PR again. |
@andfinally Hey, would you like me to review this? I noticed it's been sitting here for a while. |
That would be great, thanks @raicem! I'm reviewing again myself right now, but would love to have another pair of eyes to have some assurance we won't break Notes. --- EDIT --- I've figured out how to test the basic core Activity Notes functionality – added to the test steps. |
e4ef6b1
to
cc01dc7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Simran! Changes look logical, fix the original problem in WCCOM, and as far as I can tell, don't break Activity Notes. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and works as described, thanks @simranvijwani and @andfinally!
78b4a72
to
687c68d
Compare
687c68d
to
8557af9
Compare
I'm struggling to get the automated test builds to run on this one. Rebasing didn't help, unfortunately. |
@andfinally I see tests fail because of a particular failure at woocommerce/tests/legacy/unit-tests/woocommerce-admin/notes/class-wc-tests-notes-data-store.php:48. $this->assertEquals( $note->get_is_snoozable(), '0' !== $read_note->get_is_snoozable() ); I read we converted $this->assertEquals( $note->get_is_snoozable(), false === $read_note->get_is_snoozable() ); |
…ieve it's there for notes without this property.
8557af9
to
9ff5e14
Compare
… of `get_is_snoozable`.
Thanks Cem, excellent point! This got the build working again. |
Submission Review Guidelines:
Changes proposed in this Pull Request:
Closes 16504-gh-Automattic/woocommerce.com.
We were getting the below error in logs while deleting any vendor note:
This was happening because
is_read
value was not set with correct datatype increate
andread
function in core: https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Admin/Notes/DataStore.php#L66The datatype for the is_read is tinyint(1).
How to test the changes in this Pull Request:
Test for local Woo.com environments
This test is intended for the Marketplace Engineering teams. If you're doing testing for the WooCommerce release, it's fine to disregard this section.
We want to create a Vendor Note on our local WCCOM.
plugins/woocommerce/bin/build-zip.sh
. It is unnecessary for this test, and demands massive amounts of RAM which your local environment probably doesn't have.cd plugins/woocommerce
andpnpm run build:zip
.plugins/woocommerce
folder of your WooCommerce project.Fatal error: Uncaught Exception: The authoritative table for orders storage can't be changed while there are orders out of sync
error after activating the plugin, runwp wc cot sync
in CLI to sync your existing orders.wp_wc_admin_notes
table of your WCCOM database?1
foris_deleted
?0
foris_deleted
?Test for WooCommerce: activity panel notes
This tests that we haven't broken Activity Panel Notes, which also use this class.
wp-content/plugins
folder and paste in this content. This is taken from the example in the WooCommerce repo, with some added namespacing. (I've corrected the trunk version of the Markdown file in this PR.)/wp-admin/plugins.php
. Activate the plugin "WooCommerce Activity Panel Inbox Example Plugin One".wp_wc_admin_notes
table in your local DB, and notice that the plugin has added a new record.wp-admin/admin.php?page=wc-settings&tab=general
. Click on the "Activity" button in the top right of your screen and notice this note that the plugin has created.is_read
.Changelog entry
Significance
Type
Message
Fix
is_read
value in Admin notes.Comment