Skip to content
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

Add change processing #9

Merged
merged 6 commits into from
Dec 10, 2024
Merged

Add change processing #9

merged 6 commits into from
Dec 10, 2024

Conversation

bjendres
Copy link
Member

@bjendres bjendres commented Dec 2, 2024

adds a symfony-driven system for change processing

@bjendres bjendres requested a review from jensschuppe December 2, 2024 21:17
@bjendres bjendres changed the title Adde change processing Add change processing Dec 3, 2024
@jensschuppe jensschuppe added this to the POC milestone Dec 6, 2024
@jensschuppe jensschuppe added the enhancement New feature or request label Dec 6, 2024
Copy link
Contributor

@jensschuppe jensschuppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's take the chance for reformatting the affected files according to CiviCRM code style, see #10 for introducing code quality tools.

@@ -21,7 +23,8 @@
*
* @package Civi\Api4
*/
class Message {
class Message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest naming it ChangeMessage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, moved this to #11

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disagree, but let's discuss

foreach ($changes as $change) {
$this->applyChange($change);
$change_processor = new \Civi\Share\ChangeProcessingEvent($change['id'], $local_node_id, $change);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name the variable $changeProcessingEvent or just $event.

$this->applyChange($change);
$change_processor = new \Civi\Share\ChangeProcessingEvent($change['id'], $local_node_id, $change);
try {
\Civi::dispatcher()->dispatch('de.systopia.change.process', $change_processor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's define the event name in a constant on the event class and rename it to match the CiviCRM event naming schema, e. g. civi.share.change.process.

Comment on lines +222 to +228
$changes = civicrm_api4('ShareChange', 'get', [
'where' => [
['id', 'IN', $this->change_ids],
['status', 'IN', ShareChange::ACTIVE_STATUS],
],
'checkPermissions' => TRUE,
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use OOP style for executing API4 actions.

Comment on lines +71 to +73
->addValue('status', \Civi\Api4\ShareChange::STATUS_PENDING)
->addValue('change_type', 'civishare.change.test')
->addValue('status', 'PENDING')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status is set twice, I suppose the second one is superfluous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is

@@ -135,27 +138,96 @@ public function send($local_node_id = null)
*
* @return void
*/
public function processOnNode($local_node_id)
public function processChanges($local_node_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is $local_node_id supposed to be the source node? Is this the internal or external ID of the node?

@@ -103,11 +106,11 @@ public function send($local_node_id = null)
foreach ($peerings as $peered_node) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename $peered_node to $peering, as it is not holding the node itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you, we could do that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually suggest splitting this class into one for messages to be sent and one for received messages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disagree, but let's discuss

@@ -135,27 +138,96 @@ public function send($local_node_id = null)
*
* @return void
*/
public function processOnNode($local_node_id)
public function processChanges($local_node_id)
{
$lock = \Civi::lockManager()->acquire('data.civishare.changes'); // is 'data' the right type?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should be a TODO on a separate line above.

Comment on lines +34 to +35
/** @var array change data */
protected ?array $change_data = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a separate class Change (or maybe two for changes to be sent and received changes) with defined properties and methods for things currently done by the Message class, e.g. markAllChanges(), processChanges(), setChangeStatus(), etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disagree, but let's discuss

@bjendres bjendres mentioned this pull request Dec 6, 2024
@bjendres bjendres merged commit af9c47f into master Dec 10, 2024
@jensschuppe jensschuppe deleted the add-change-processing branch December 16, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants