From: eileen Date: Thu, 31 Oct 2019 02:55:44 +0000 (+1300) Subject: dev/core#1355 Add contention handling for dedupe jobs X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c9f05fb31c229c1ea180a70abaec9adc1c88ebc0;p=civicrm-core.git dev/core#1355 Add contention handling for dedupe jobs https://lab.civicrm.org/dev/core/issues/1355 --- diff --git a/CRM/Core/Exception/ResourceConflictException.php b/CRM/Core/Exception/ResourceConflictException.php new file mode 100644 index 0000000000..c722320295 --- /dev/null +++ b/CRM/Core/Exception/ResourceConflictException.php @@ -0,0 +1,42 @@ +acquire("data.core.contact.{$contactID}"); + if ($lock->isAcquired()) { + $locks[] = $lock; + } + else { + self::releaseLocks($locks); + throw new CRM_Core_Exception_ResourceConflictException(ts('Contact is in Use'), 'contact_lock'); + } + } + return $locks; + } + + /** + * Release contact locks so another process can alter them if it wants. + * + * @param array $locks + */ + protected static function releaseLocks(array $locks) { + foreach ($locks as $lock) { + /* @var Civi\Core\Lock\LockInterface $lock */ + $lock->release(); + } + } + }