add handleDuplicates() function to deactivate duplicates
This commit is contained in:
parent
fc515de26d
commit
ef2cb029f6
1 changed files with 26 additions and 0 deletions
|
@ -164,6 +164,32 @@ class TwingleProject {
|
||||||
|
|
||||||
return new TwingleProject($result, TRUE);
|
return new TwingleProject($result, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deactivate all duplicates but the newest one
|
||||||
|
*
|
||||||
|
* @param array $result
|
||||||
|
*
|
||||||
|
* @throws \CiviCRM_API3_Exception
|
||||||
|
*/
|
||||||
|
private function handleDuplicates(array $result) {
|
||||||
|
|
||||||
|
// Sort projects by last_update
|
||||||
|
uasort($result['values'], function ($a, $b) {
|
||||||
|
return $a['last_update'] <=> $b['last_update'];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete newest project from array
|
||||||
|
array_shift($result['values']);
|
||||||
|
|
||||||
|
// Instantiate projects to deactivate them
|
||||||
|
foreach ($result['values'] as $p) {
|
||||||
|
$project = TwingleProject::fetch($p['id']);
|
||||||
|
$project->deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate $value keys to custom field names
|
* Translate $value keys to custom field names
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue