-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: add hub bookmarks to nodes #56
Merged
chickenn00dle
merged 6 commits into
trunk
from
feat/add-network-sites-dropdown-to-nodes
Feb 22, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ff0e0fb
feat: add hub bookmarks to nodes
chickenn00dle af6a429
feat: store node data as option
chickenn00dle 1c3f3d5
feat: correctly store nodes data as array
chickenn00dle 7d8e3ae
chore: reorganize some code
chickenn00dle 9ac9775
chore: refactor get_bookmarks
chickenn00dle 1e590d1
chore: use network node hooks
chickenn00dle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
includes/hub/stores/event-log-items/class-nodes-synced.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Newspack Nodes Synced Log Item | ||
* | ||
* @package Newspack | ||
*/ | ||
|
||
namespace Newspack_Network\Hub\Stores\Event_Log_Items; | ||
|
||
use Newspack_Network\Hub\Stores\Abstract_Event_Log_Item; | ||
|
||
/** | ||
* Class to handle the Nodes Synced Log Item | ||
*/ | ||
class Nodes_Synced extends Abstract_Event_Log_Item { | ||
|
||
/** | ||
* Gets a summary for this event | ||
* | ||
* @return string | ||
*/ | ||
public function get_summary() { | ||
return __( 'Node data synced', 'newspack-network' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Newspack Nodes Synced Incoming Event class | ||
* | ||
* @package Newspack | ||
*/ | ||
|
||
namespace Newspack_Network\Incoming_Events; | ||
|
||
use Newspack_Network\Debugger; | ||
use Newspack_Network\Hub\Node; | ||
|
||
/** | ||
* Class to handle the Nodes Synced Event | ||
* | ||
* This event is always sent from the Hub and received by Nodes. | ||
*/ | ||
class Nodes_Synced extends Abstract_Incoming_Event { | ||
/** | ||
* Process event in Node | ||
* | ||
* @return void | ||
*/ | ||
public function process_in_node() { | ||
Debugger::log( 'Processing network_nodes_synced event.' ); | ||
// Get data passed for node urls. | ||
$data = $this->get_data(); | ||
|
||
// If the data is empty, return early. | ||
if ( empty( $data ) ) { | ||
Debugger::log( 'No data passed for network_nodes_synced event.' ); | ||
return; | ||
} | ||
|
||
$nodes_data = $data->nodes_data; | ||
|
||
// If the nodes data is empty, return early. | ||
if ( empty( $nodes_data ) ) { | ||
Debugger::log( 'No nodes data passed for network_nodes_synced event.' ); | ||
return; | ||
} | ||
|
||
foreach ( $nodes_data as $key => $node ) { | ||
// We don't need top store data for the current node. | ||
if ( $node['url'] === get_site_url() ) { | ||
unset( $nodes_data[ $key ] ); | ||
} | ||
} | ||
|
||
$updated = update_option( Node::HUB_NODES_SYNCED_OPTION, $nodes_data ); | ||
|
||
if ( $updated ) { | ||
Debugger::log( 'network_nodes_synced event processed. Synced ' . count( $nodes_data ) . ' nodes.' ); | ||
} else { | ||
Debugger::log( 'Error processing network_nodes_synced event.' ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ran into some issues treating
$data
as an array in the incoming events class so had to massage this here to work with the nodes data array.