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

CRM-20588, Add Pre and Post hook for Batch #10364

Merged
merged 3 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions CRM/Batch/BAO/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,24 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
* Create a new batch.
*
* @param array $params
* @param array $ids
* Associated array of ids.
* @param string $context
* String.
*
* @return object
* $batch batch object
*/
public static function create(&$params, $ids = NULL, $context = NULL) {
if (empty($params['id'])) {
public static function create(&$params) {
$op = 'edit';
$batchId = CRM_Utils_Array::value('id', $params);
if (!$batchId) {
$op = 'create';
$params['name'] = CRM_Utils_String::titleToVar($params['title']);
}

CRM_Utils_Hook::pre($op, 'Batch', $batchId, $params);
$batch = new CRM_Batch_DAO_Batch();
$batch->copyValues($params);
if ($context == 'financialBatch' && !empty($ids['batchID'])) {
$batch->id = $ids['batchID'];
}
$batch->save();

CRM_Utils_Hook::post($op, 'Batch', $batch->id, $batch);

return $batch;
}

Expand Down Expand Up @@ -170,9 +168,11 @@ public static function removeBatchEntity($params) {
*/
public static function deleteBatch($batchId) {
// delete entry from batch table
CRM_Utils_Hook::pre('delete', 'Batch', $batchId, CRM_Core_DAO::$_nullArray);
$batch = new CRM_Batch_DAO_Batch();
$batch->id = $batchId;
$batch->delete();
CRM_Utils_Hook::post('delete', 'Batch', $batch->id, $batch);
return TRUE;
}

Expand Down
5 changes: 2 additions & 3 deletions CRM/Financial/Form/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ public function postProcess() {
$batchParams['modified_id'] = $session->get('userID');
$batchParams['status_id'] = $this->_exportStatusId;

$ids = array();
foreach ($batchIds as $batchId) {
$batchParams['id'] = $ids['batchID'] = $batchId;
$batchParams['id'] = $batchId;
// Update totals
$batchParams = array_merge($batchParams, $totals[$batchId]);
CRM_Batch_BAO_Batch::create($batchParams, $ids, 'financialBatch');
CRM_Batch_BAO_Batch::create($batchParams);
}

CRM_Batch_BAO_Batch::exportFinancialBatch($batchIds, $this->_exportFormat);
Expand Down
4 changes: 1 addition & 3 deletions CRM/Financial/Form/FinancialBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ public static function formRule($values, $files, $self) {
*/
public function postProcess() {
$session = CRM_Core_Session::singleton();
$ids = array();
$params = $this->exportValues();
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id');
if ($this->_id) {
$ids['batchID'] = $this->_id;
$params['id'] = $this->_id;
}

Expand Down Expand Up @@ -228,7 +226,7 @@ public function postProcess() {
$activityTypeName = 'Edit Batch';
}

$batch = CRM_Batch_BAO_Batch::create($params, $ids, 'financialBatch');
$batch = CRM_Batch_BAO_Batch::create($params);

$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');

Expand Down
11 changes: 1 addition & 10 deletions CRM/Financial/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public static function assignRemove() {
if ($recordClass[0] == 'CRM' && count($recordClass) >= 3) {
foreach ($records as $recordID) {
$params = array();
$ids = NULL;
switch ($op) {
case 'assign':
case 'remove':
Expand All @@ -207,14 +206,12 @@ public static function assignRemove() {
$params = $totals[$recordID];
case 'reopen':
$status = $op == 'close' ? 'Closed' : 'Reopened';
$ids['batchID'] = $recordID;
$batchStatus = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'status_id', array('labelColumn' => 'name'));
$params['status_id'] = CRM_Utils_Array::key($status, $batchStatus);
$session = CRM_Core_Session::singleton();
$params['modified_date'] = date('YmdHis');
$params['modified_id'] = $session->get('userID');
$params['id'] = $recordID;
$context = "financialBatch";
break;

case 'export':
Expand All @@ -223,17 +220,11 @@ public static function assignRemove() {

case 'delete':
$params = $recordID;
$context = "financialBatch";
break;
}

if (method_exists($recordBAO, $methods[$op]) & !empty($params)) {
if (isset($context)) {
$updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params, $ids, $context));
}
else {
$updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params, $ids));
}
$updated = call_user_func_array(array($recordBAO, $methods[$op]), array(&$params));
if ($updated) {
$redirectStatus = $updated->status_id;
if ($batchStatus[$updated->status_id] == "Reopened") {
Expand Down