Skip to content

Commit f7f1e81

Browse files
committed
Eliminate repeated update of Drupal users
1 parent 75f28a5 commit f7f1e81

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/Job/DeveloperSync.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function execute(): bool {
147147
$last_modified_delta = $developer->getLastModifiedAt()->getTimestamp() - $user->getChangedTime();
148148
// Update Drupal user because the Apigee Edge developer is the most
149149
// recent.
150-
if ($last_modified_delta >= 0) {
150+
if ($last_modified_delta > 0) {
151151
$update_user_job = new UserUpdate($user->getEmail());
152152
$update_user_job->setTag($this->getTag());
153153
$this->scheduleJob($update_user_job);

src/Job/UserCreateUpdate.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ protected function executeRequest() {
7575
// the same developer in apigee_edge_user_presave() while creating
7676
// Drupal user based on a developer should be avoided.
7777
_apigee_edge_set_sync_in_progress(TRUE);
78+
79+
// Synchronize user's last modified timestamp with developer's timestamp
80+
// to maintain data consistency and prevent infinite sync loops where
81+
// outdated timestamps cause repeated scheduling of sync operations.
82+
// @see \Drupal\apigee_edge\Job\DeveloperSync::execute()
83+
$result->getUser()->setChangedTime($developer->getLastModifiedAt()->getTimestamp());
7884
$result->getUser()->save();
7985
}
8086
}
@@ -121,9 +127,6 @@ protected function beforeUserSave(DeveloperToUserConversionResult $result) : voi
121127
throw $problem;
122128
}
123129
}
124-
// It's necessary because changed time is automatically updated on the
125-
// UI only.
126-
$result->getUser()->setChangedTime(\Drupal::time()->getCurrentTime());
127130
}
128131

129132
/**

src/UserDeveloperConverter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ public function convertDeveloper(DeveloperInterface $developer) : DeveloperToUse
182182
$user = $user_storage->create([
183183
'pass' => \Drupal::service('password_generator')->generate(),
184184
]);
185+
// Set user creation date to match the original developer's creation
186+
// timestamp to maintain chronological consistency between related
187+
// entities and prevent confusion when comparing created vs modified dates
188+
// in the user interface.
189+
$user->set('created', $developer->getCreatedAt()->getTimestamp());
185190
// Suppress invalid email validation errors.
186191
DeveloperEmailUniqueValidator::whitelist($developer->id());
187192
}

0 commit comments

Comments
 (0)