implement TwingleProject cloning
This commit is contained in:
parent
247874f380
commit
9df3ff4153
2 changed files with 45 additions and 4 deletions
|
@ -107,7 +107,20 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate values between CiviCRM Campaigns and Twingle format
|
* ## Clone this TwingleProject
|
||||||
|
*
|
||||||
|
* This method removes the id and the identifier from this instance and in
|
||||||
|
* the next step it pushes the clone as a new project with the same values to
|
||||||
|
* Twingle.
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function clone() {
|
||||||
|
unset($this->values['id']);
|
||||||
|
unset($this->values['identifier']);
|
||||||
|
$this->create(); // this will also trigger the postSave hook
|
||||||
|
}
|
||||||
|
|
||||||
*
|
*
|
||||||
* @param array $values
|
* @param array $values
|
||||||
* array of which values shall be translated
|
* array of which values shall be translated
|
||||||
|
|
|
@ -55,12 +55,40 @@ function twinglecampaign_civicrm_postSave_civicrm_campaign($dao) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This callback function synchronizes a recently updated TwingleProject campaign
|
* This callback function synchronizes a recently updated TwingleProject
|
||||||
|
* campaign
|
||||||
|
*
|
||||||
* @param $campaign_id
|
* @param $campaign_id
|
||||||
* @throws \CiviCRM_API3_Exception
|
*
|
||||||
*/
|
*/
|
||||||
function twinglecampaign_postSave_callback($campaign_id) {
|
function twinglecampaign_postSave_callback($campaign_id) {
|
||||||
civicrm_api3('TwingleProject', 'sync', ['id' => $campaign_id]);
|
if ($_POST['action'] == 'clone') {
|
||||||
|
unset($_POST['action']);
|
||||||
|
$result = civicrm_api3('TwingleProject', 'getsingle',
|
||||||
|
['id' => $campaign_id]
|
||||||
|
)['values'][$campaign_id];
|
||||||
|
$project = new CRM_TwingleCampaign_BAO_TwingleProject($result);
|
||||||
|
try {
|
||||||
|
$project->clone();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Civi::log()->error(
|
||||||
|
E::LONG_NAME .
|
||||||
|
" could not clone TwingleProject campaign: " .
|
||||||
|
$e->getMessage()
|
||||||
|
);
|
||||||
|
CRM_Utils_System::setUFMessage('TwingleProject could not get cloned.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
civicrm_api3('TwingleProject', 'sync', ['id' => $campaign_id]);
|
||||||
|
CRM_Utils_System::setUFMessage('TwingleProject was cloned.');
|
||||||
|
} catch (CiviCRM_API3_Exception $e) {
|
||||||
|
Civi::log()->error(
|
||||||
|
'twinglecampaign_postSave_callback ' . $e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue