function setDefaultValues() { // do a cleanup here (ticket #1616) CRM_Donrec_Logic_Snapshot::cleanup(); $uid = CRM_Donrec_Logic_Settings::getLoggedInContactID(); $remaining_snapshots = CRM_Donrec_Logic_Snapshot::getUserSnapshots($uid); if (!empty($remaining_snapshots)) { $remaining_snapshot = array_pop($remaining_snapshots); $this->getElement('rsid')->setValue($remaining_snapshot); $this->assign('statistic', CRM_Donrec_Logic_Snapshot::getStatistic($remaining_snapshot)); $this->assign('remaining_snapshot', TRUE); } }
function setDefaultValues() { // do a cleanup here (ticket #1616) CRM_Donrec_Logic_Snapshot::cleanup(); $contactId = empty($_REQUEST['cid']) ? NULL : $_REQUEST['cid']; $this->getElement('cid')->setValue($contactId); $this->assign('cid', $contactId); $uid = CRM_Donrec_Logic_Settings::getLoggedInContactID(); //TODO: what if we have more than 1 remaining snapshot (what should not happen at all)? $remaining_snapshots = CRM_Donrec_Logic_Snapshot::getUserSnapshots($uid); if (!empty($remaining_snapshots)) { $remaining_snapshot = array_pop($remaining_snapshots); $this->getElement('rsid')->setValue($remaining_snapshot); $this->assign('statistic', CRM_Donrec_Logic_Snapshot::getStatistic($remaining_snapshot)); $this->assign('remaining_snapshot', TRUE); } }
/** * * * @author niko bochan */ public function testSnapshotMaintenanceMixed() { // prerequisites $contributions_f = $this->generateContributions(5); $this->assertEquals(5, count($contributions_f)); $contributions_e = $this->generateContributions(5); $this->assertEquals(5, count($contributions_e)); // generate a new snapshot (not expired) $result = CRM_Donrec_Logic_Snapshot::create($contributions_f, 1); $snapshot_fresh = $result['snapshot']; $this->assertNotNull($snapshot_fresh, "CRM_Donrec_Logic_Snapshot::create() returned NULL"); $this->assertDBQuery(5, "SELECT count(*) FROM `donrec_snapshot`"); // generate an expired snapshot $result = CRM_Donrec_Logic_Snapshot::create($contributions_e, 2, -20); $snapshot_expired = $result['snapshot']; $this->assertNotNull($snapshot_expired, "CRM_Donrec_Logic_Snapshot::create() returned NULL"); $this->assertDBQuery(10, "SELECT count(*) FROM `donrec_snapshot`"); // call maintenance method CRM_Donrec_Logic_Snapshot::cleanup(); //result: the expired one should be gone. the fresh snapshot should still be there. $this->assertDBQuery(5, "SELECT count(*) FROM `donrec_snapshot` WHERE `created_by` = 1"); $this->assertDBQuery(0, "SELECT count(*) FROM `donrec_snapshot` WHERE `created_by` = 2"); $this->assertDBQuery(5, "SELECT count(*) FROM `donrec_snapshot`"); }