silverstripe-event-calendar icon indicating copy to clipboard operation
silverstripe-event-calendar copied to clipboard

Trying a SS4 upgrade of this module. Wondering if you could help with this error?

Open muppsy007 opened this issue 5 years ago • 1 comments

Hi @unclecheese. I'm trying to do an SS4 upgrade of your module, based on this fork. I'm running into an error in one of your module methods that bamboozles me and thought you might have a clue since you wrote the logic.

It's in the method Calendar->getEventList()

public function getEventList($start, $end, $filter = null, $limit = null, $announcement_filter = null) {
		if(Config::inst()->get(Calendar::class, "caching_enabled")) {
			return $this->getCachedEventList($start, $end, $filter, $limit);
		}

		$eventList = new ArrayList();

		foreach($this->getAllCalendars() as $calendar) {
			if($events = $calendar->getStandardEvents($start, $end, $filter)) {
				$eventList->merge($events);
			}

The error occurs at $eventList->merge($events). Seemingly on first pass. Which should be simply adding the results of getStandardEvents() to an empty ArrayList. But this is what I get when that merge is attempted on SS4:

[Emergency] Uncaught SilverStripe\ORM\Connect\DatabaseException: Couldn't run query: SELECT DISTINCT "CalendarDateTime"."ClassName", "CalendarDateTime"."LastEdited", "CalendarDateTime"."Created", "CalendarDateTime"."StartDate", "CalendarDateTime"."StartTime", "CalendarDateTime"."EndDate", "CalendarDateTime"."EndTime", "CalendarDateTime"."AllDay", "CalendarDateTime"."EventID", "CalendarDateTime"."ID", CASE WHEN "CalendarDateTime"."ClassName" IS NOT NULL THEN "CalendarDateTime"."ClassName" ELSE 'Unclecheese\\EventCalendar\\CalendarDateTime' END AS "RecordClassName" FROM "CalendarDateTime" INNER JOIN "CalendarEvent" ON = "CalendarEvent"."ID" WHERE ("" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) AND (Recursion != 1) AND ( (StartDate = '2020-04-05') OR (StartDate BETWEEN '2019-10-05' AND '2020-04-05') OR (EndDate BETWEEN '2019-10-05' AND '2020-04-05') ) ORDER BY "CalendarDateTime"."StartDate" ASC, "CalendarDateTime"."StartTime" ASC You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= "CalendarEvent"."ID" WHERE ("" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ' at line 4

Looks like something is coming back empty in that WHERE ("" IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) clause. But I can for the life of me see where that where clause comes from. I'm assuming it's a result of the merge. I've checked the datatype of getStandardEvents() and it is an DataList, not an ArrayList. I'm not sure if this has something to do with it.

Any hints at all?

muppsy007 avatar Oct 06 '19 19:10 muppsy007

Digging further, it seems that the main culprit is inside getStandardEvents()

protected function getStandardEvents($start, $end, $filter = null) {
		$children = $this->AllChildren();
		$ids = $children->column('ID');
		$datetimeClass = $this->getDateTimeClass();
		$relation = $this->getDateToEventRelation();
		$eventClass = $this->getEventClass();

		$list = DataList::create($datetimeClass)
			->filter(array(
				$relation => $ids
			))
			->innerJoin($eventClass, "$relation = \"{$eventClass}\".\"ID\"")
			->innerJoin("SiteTree", "\"SiteTree\".\"ID\" = \"{$eventClass}\".\"ID\"")
			->where("Recursion != 1");

It has two problems here. getEventClass() returns the namespaced classname, which the code then complains about not being a table. So I just hard code this to "CalendarEvent" to get around it for now.

The issue where the above error comes from however is getDateToEventRelation(). Which returns null. Still digging but any help would be appreciated.

muppsy007 avatar Oct 06 '19 21:10 muppsy007