Skip to content

Commit

Permalink
v2.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
kjmartens committed Feb 26, 2019
1 parent d9f2177 commit b7a0e77
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 29 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Solspace Calendar Changelog

## 2.0.16 - 2019-02-26
### Changed
- Improved Calendar for better compatibility with other third party plugins such as Smart Maps.

### Fixed
- Fixed a bug where 'today' would highlight the wrong date in some edge cases in CP Month/Week/Day views.
- Fixed a bug where events were not able to be restored (from soft delete) in Craft 3.1+.
- Fixed a bug where upgrading from Craft 2 to Craft 3 version of Calendar could possibly trigger an error in the `AddIcsTimezoneToCalendar` migration.
- Fixed a bug where dragging and dropping events in CP Month/Week/Day views skipping a month in some edge cases in Craft 3.1+.
- Fixed a bug where saving recurring events with multiple sites enabled could cause an issue if the event is far enough in the future.

## 2.0.15 - 2019-02-06
### Fixed
- Fixed a bug where dragging and dropping events in CP Month/Week/Day views weren't working correctly (would shuffle by several days) in Craft 3.1+.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "solspace/craft3-calendar",
"description": "The most powerful event management plugin for Craft.",
"version": "2.0.15",
"version": "2.0.16",
"type": "craft-plugin",
"authors": [
{
Expand All @@ -16,7 +16,7 @@
"symfony/property-access": "^2.8|^3.0|^4.0",
"symfony/finder": "^2.8|^3.0|^4.0",
"symfony/filesystem": "^2.8|^3.0|^4.0",
"solspace/craft3-commons": "^1.0.16",
"solspace/craft3-commons": "^1.0.17",
"nesbot/carbon": "^1.22.1"
},
"autoload": {
Expand Down
20 changes: 9 additions & 11 deletions src/Controllers/EventsApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Solspace\Calendar\Calendar;
use Solspace\Calendar\Elements\Event;
use Solspace\Calendar\Library\CalendarPermissionHelper;
use Solspace\Calendar\Library\DatabaseHelper;
use Solspace\Calendar\Library\DateHelper;
use Solspace\Calendar\Records\SelectDateRecord;
use yii\web\HttpException;
Expand All @@ -33,18 +32,18 @@ public function actionModifyDate(): Response
$this->requirePostRequest();

/**
* @var Event $event
* @var \DateInterval $interval
* @var bool $isAllDay
* @var Event $event
* @var int $deltaSeconds
* @var bool $isAllDay
*/
list($event, $interval, $isAllDay) = $this->validateAndReturnModificationData();
list($event, $deltaSeconds, $isAllDay) = $this->validateAndReturnModificationData();

$eventsService = $this->getEventsService();

$wasAllDay = $event->allDay;
$oldStartDate = $event->getStartDate()->copy();
$startDate = $event->getStartDate();
$startDate->add($interval);
$startDate->addSeconds($deltaSeconds);

$endDateDiff = $oldStartDate->diff($event->getEndDate());

Expand All @@ -53,7 +52,7 @@ public function actionModifyDate(): Response

$postedStartDateString = \Craft::$app->request->post('startDate');
$postedStartDate = new Carbon($postedStartDateString, DateHelper::UTC);
$originalOccurrenceDate = $postedStartDate->sub($interval);
$originalOccurrenceDate = $postedStartDate->subSeconds($deltaSeconds);

$isOriginalEvent = $originalOccurrenceDate->format('Y-m-d') === $event->getStartDate()->toDateString();

Expand Down Expand Up @@ -149,9 +148,9 @@ public function actionModifyDuration(): Response
* @var Event $event
* @var \DateInterval $interval
*/
list($event, $interval) = $this->validateAndReturnModificationData();
list($event, $deltaSeconds) = $this->validateAndReturnModificationData();

$event->getEndDate()->add($interval);
$event->getEndDate()->addSeconds($deltaSeconds);

$this->getEventsService()->saveEvent($event);

Expand Down Expand Up @@ -303,9 +302,8 @@ private function validateAndReturnModificationData(): array

if ($event) {
CalendarPermissionHelper::requireCalendarEditPermissions($event->getCalendar());
$interval = DateHelper::getDateIntervalFromSeconds($deltaSeconds);

return [$event, $interval, $isAllDay];
return [$event, $deltaSeconds, $isAllDay];
}

throw new HttpException(sprintf('No event with ID [%d] found', $eventId));
Expand Down
36 changes: 28 additions & 8 deletions src/Elements/Db/EventQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,20 @@ private function cacheRecurringEvents(array $foundIds)
continue;
}

$paddedRangeStart = $this->getPaddedRangeStart($rruleObject->isInfinite() ? $startDate : null);
$paddedRangeEnd = $this->getPaddedRangeEnd($rruleObject->isInfinite() ? $freq : null);
$isInfinite = $rruleObject->isInfinite();
$paddedRangeStart = $this->getPaddedRangeStart($isInfinite ? $startDate : null);
$paddedRangeEnd = $this->getPaddedRangeEnd(
$isInfinite ? $startDate : null,
$isInfinite ? $freq : null
);

if ($paddedRangeStart) {
$paddedRangeStart->setTime(0, 0, 0);
}

if ($paddedRangeEnd) {
$paddedRangeEnd->setTime(23, 59, 59);
}

$occurrences = $rruleObject->getOccurrencesBetween($paddedRangeStart, $paddedRangeEnd);
$exceptions = $this->getExceptionService()->getExceptionDatesForEventId($eventId);
Expand Down Expand Up @@ -1017,17 +1029,20 @@ private function getPaddedRangeStart($relativeDate = null)
}

/**
* @param string $recurrenceFrequency
* @param Carbon|string|null $relativeDate
* @param string $recurrenceFrequency
*
* @return Carbon|null
*/
private function getPaddedRangeEnd($recurrenceFrequency = null)
private function getPaddedRangeEnd($relativeDate = null, $recurrenceFrequency = null)
{
$paddedRangeEnd = null;
if ($this->rangeEnd) {
$paddedRangeEnd = $this->rangeEnd->copy()->addWeek();
} else if ($recurrenceFrequency) {
$paddedRangeEnd = new Carbon(DateHelper::UTC);
return $this->rangeEnd->copy()->addWeek();
}

$paddedRangeEnd = null;
if ($recurrenceFrequency) {
$paddedRangeEnd = $this->parseCarbon($relativeDate) ?? new Carbon(DateHelper::UTC);

switch ($recurrenceFrequency) {
case RecurrenceHelper::DAILY:
Expand Down Expand Up @@ -1192,6 +1207,11 @@ private function orderEvents(array &$events)
$orderBy = 'startDate';
}

$firstEvent = reset($events);
if (!$firstEvent || !isset($firstEvent->{$orderBy})) {
return;
}

usort(
$events,
function (Event $eventA, Event $eventB) use ($modifier, $orderBy) {
Expand Down
14 changes: 13 additions & 1 deletion src/Elements/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use craft\base\Element;
use craft\elements\actions\Restore;
use craft\elements\db\ElementQueryInterface;
use craft\elements\User;
use craft\helpers\UrlHelper;
Expand Down Expand Up @@ -318,7 +319,7 @@ protected static function defineDefaultTableAttributes(string $source): array
*/
protected static function defineActions(string $source = null): array
{
return [
$actions = [
\Craft::$app->elements->createAction(
[
'type' => DeleteEventAction::class,
Expand All @@ -327,6 +328,17 @@ protected static function defineActions(string $source = null): array
]
),
];

if (version_compare(\Craft::$app->getVersion(), '3.1', '>=')) {
$actions[] = \Craft::$app->elements->createAction([
'type' => Restore::class,
'successMessage' => \Craft::t('app', 'Events restored.'),
'partialSuccessMessage' => \Craft::t('app', 'Some events restored.'),
'failMessage' => \Craft::t('app', 'Events not restored.'),
]);
}

return $actions;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/js/src/calendar.js

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

2 changes: 1 addition & 1 deletion src/Resources/js/src/widget/month.js

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

15 changes: 10 additions & 5 deletions src/migrations/m180921_124711_AddIcsTimezoneToCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ class m180921_124711_AddIcsTimezoneToCalendar extends Migration
*/
public function safeUp()
{
$this->addColumn(
'{{%calendar_calendars}}',
'icsTimezone',
$this->string(200)->null()
);
$table = $this->getDb()->getTableSchema('{{%calendar_calendars}}');
if (!$table->getColumn('icsTimezone')) {
$this->addColumn(
'{{%calendar_calendars}}',
'icsTimezone',
$this->string(200)->null()
);
}

return true;
}

/**
Expand Down

0 comments on commit b7a0e77

Please sign in to comment.