Skip to content

Commit

Permalink
Merge pull request #15223 from seamuslee001/when_package_upgrade
Browse files Browse the repository at this point in the history
Upgrade When package to the lastest version
  • Loading branch information
mattwire authored Oct 13, 2019
2 parents 3ca1720 + 30aa3e5 commit d5ef1ed
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 17 deletions.
44 changes: 33 additions & 11 deletions CRM/Core/BAO/RecurringEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @copyright CiviCRM LLC (c) 2004-2019
*/

require_once 'packages/When/When.php';
use When\When;

/**
* Class CRM_Core_BAO_RecurringEntity.
Expand Down Expand Up @@ -240,7 +240,7 @@ public function generate() {
*/
public function generateRecursion() {
// return if already generated
if (is_a($this->recursion, 'When')) {
if (is_a($this->recursion, 'When\When')) {
return $this->recursion;
}

Expand Down Expand Up @@ -334,7 +334,7 @@ public function generateRecursiveDates() {
$this->generateRecursion();

$recursionDates = [];
if (is_a($this->recursion, 'When')) {
if (is_a($this->recursion, 'When\When')) {
$initialCount = CRM_Utils_Array::value('start_action_offset', $this->schedule);

$exRangeStart = $exRangeEnd = NULL;
Expand All @@ -343,8 +343,12 @@ public function generateRecursiveDates() {
$exRangeEnd = $this->excludeDateRangeColumns[1];
}

if (CRM_Core_Config::singleton()->userFramework == 'UnitTests') {
$this->recursion->RFC5545_COMPLIANT = When::IGNORE;
}
$count = 1;
while ($result = $this->recursion->next()) {
$result = $this->recursion_start_date;
while ($result = $this->getNextOccurrence($result)) {
$skip = FALSE;
if ($result == $this->recursion_start_date) {
// skip the recursion-start-date from the list we going to generate
Expand Down Expand Up @@ -1004,14 +1008,14 @@ public function getRecursionFromSchedule($scheduleReminderDetails = []) {
}
$start = new DateTime($currDate);
$this->recursion_start_date = $start;
if ($scheduleReminderDetails['repetition_frequency_unit']) {
$repetition_frequency_unit = $scheduleReminderDetails['repetition_frequency_unit'];
if ($repetition_frequency_unit == "day") {
$repetition_frequency_unit = "dai";
}
$repetition_frequency_unit = $repetition_frequency_unit . 'ly';
$r->recur($start, $repetition_frequency_unit);
$repetition_frequency_unit = $scheduleReminderDetails['repetition_frequency_unit'];
if ($repetition_frequency_unit == "day") {
$repetition_frequency_unit = "dai";
}
$repetition_frequency_unit = $repetition_frequency_unit . 'ly';
$r->startDate($start)
->exclusions([$start])
->freq($repetition_frequency_unit);

if ($scheduleReminderDetails['repetition_frequency_interval']) {
$r->interval($scheduleReminderDetails['repetition_frequency_interval']);
Expand Down Expand Up @@ -1258,4 +1262,22 @@ public static function updateModeAndPriceSet($entityId, $entityTable, $mode, $li
return $finalResult;
}

/**
* Get next occurrence for the given date
*
* @param \DateTime $occurDate
* @param bool $strictly_after
*
* @return bool
*/
private function getNextOccurrence($occurDate, $strictly_after = TRUE) {
try {
return $this->recursion->getNextOccurrence($occurDate, $strictly_after);
}
catch (Exception $exception) {
CRM_Core_Session::setStatus(ts($exception->getMessage()));
}
return FALSE;
}

}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"pear/log": "1.13.1",
"katzien/php-mime-type": "2.1.0",
"civicrm/composer-downloads-plugin": "^2.0",
"league/csv": "^9.2"
"league/csv": "^9.2",
"tplaner/when": "dev-master#c1ec099f421bff354cc5c929f83b94031423fc80"
},
"require-dev": {
"cache/integration-tests": "dev-master"
Expand Down
50 changes: 49 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Core/BAO/RecurringEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public function testActivityGeneration() {
$this->assertEquals(5, count($generatedEntities['civicrm_activity']), "Cehck if number of iterations are 5");
$expectedDates = [
'20141025103000',
'20141227103000',
'20150328103000',
'20150627103000',
'20150926103000',
'20150124103000',
'20150425103000',
'20150725103000',
'20151024103000',
];
foreach ($generatedEntities['civicrm_activity'] as $entityID) {
$this->assertDBNotNull('CRM_Activity_DAO_Activity', $entityID, 'id',
Expand Down

0 comments on commit d5ef1ed

Please sign in to comment.