/** * Execute the next chunk/step of the donation receipt run */ function civicrm_api3_donation_receipt_engine_next($params) { // first, check if the snapshot ID is there if (empty($params['sid'])) { return civicrm_api3_create_error(ts("No 'sid' parameter given.", array('domain' => 'de.systopia.donrec'))); } // Init the engine $sid = (int) $params['sid']; $engine = new CRM_Donrec_Logic_Engine(); $engine_error = $engine->init($sid, $params); if ($engine_error) { return civicrm_api3_create_error($engine_error); } // just run the next step $result = $engine->nextStep(); // and return the result return civicrm_api3_create_success($result); }
function run() { CRM_Utils_System::setTitle(ts('Creating Donation Receipts', array('domain' => 'de.systopia.donrec'))); // extract the parameters $parameters = array(); $parameters['test'] = empty($_REQUEST['final']) ? 1 : 0; $parameters['bulk'] = empty($_REQUEST['bulk']) ? 0 : 1; $parameters['exporters'] = empty($_REQUEST['exporters']) ? array('Dummy') : explode(',', $_REQUEST['exporters']); //get session-vars $session = CRM_Core_Session::singleton(); if ($parameters['test']) { $url_back = $session->get('url_back_test') . '&exporters=' . $_REQUEST['exporters']; } else { $url_back = $session->get('url_back'); } $this->assign('url_back', $url_back); // get the snapshot_id if (empty($_REQUEST['sid'])) { $this->assign('error', ts("No snapshot ID given. Please call this page from a proper selection.", array('domain' => 'de.systopia.donrec'))); } else { // Init the engine $sid = (int) $_REQUEST['sid']; $engine = new CRM_Donrec_Logic_Engine(); $engine_error = $engine->init($sid, $parameters); if ($engine_error) { $this->assign('error', $engine_error); } else { $this->assign('sid', $sid); if ($parameters['test']) { // if this is a test-run: restart $engine->resetTestRun(); } $this->assign('bulk', $parameters['bulk']); $this->assign('test', $parameters['test']); $this->assign('exporters', implode('', $parameters['exporters'])); } } parent::run(); }
public function testEngineMultiExport() { // create a new snapshot $contributions = $this->generateContributions(6); $result = CRM_Donrec_Logic_Snapshot::create($contributions, 1); $snapshot = $result['snapshot']; // engine setup parameters $sid = $snapshot->getId(); $parameters = array(); $parameters['test'] = 1; $parameters['bulk'] = 0; $parameters['exporters'] = 'Dummy,SecondDummy'; // let's try to start it $engine = new CRM_Donrec_Logic_Engine(); $engine_error = $engine->init($sid, $parameters, TRUE); $this->assertEquals(FALSE, $engine_error); $ctr = 0; foreach ($contributions as $id) { $stats = $engine->nextStep(); $ctr++; $this->assertDBQuery('TEST', sprintf("SELECT `status` FROM `donrec_snapshot` WHERE `contribution_id` = %d;", $id)); $this->assertDBQuery('{"Dummy":{"test":"Dummy was here!"},"SecondDummy":{"test":"2nd Dummy was here!"}}', sprintf("SELECT `process_data` FROM `donrec_snapshot` WHERE `contribution_id` = %d;", $id)); $this->assertEquals($stats['count'], 6); $this->assertEquals($stats['completed_test'], $ctr); } }