From 9c6943d4f88732d646f0ea5097dbecc012bfdff1 Mon Sep 17 00:00:00 2001 From: anonymoususer72041 <247563575+anonymoususer72041@users.noreply.github.com> Date: Mon, 4 May 2026 12:33:28 +0200 Subject: [PATCH 1/2] Allow nullable calendar event job orders --- db/cats_schema.sql | 2 +- modules/install/Schema.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/db/cats_schema.sql b/db/cats_schema.sql index 5807a8888..eecda94ed 100755 --- a/db/cats_schema.sql +++ b/db/cats_schema.sql @@ -123,7 +123,7 @@ CREATE TABLE `calendar_event` ( `date_created` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', `date_modified` datetime NOT NULL DEFAULT '1000-01-01 00:00:00', `site_id` int(11) NOT NULL DEFAULT '0', - `joborder_id` int(11) NOT NULL DEFAULT '-1', + `joborder_id` int(11) DEFAULT NULL, `description` text COLLATE utf8_unicode_ci, `duration` int(11) NOT NULL DEFAULT '60', `reminder_enabled` int(1) NOT NULL DEFAULT '0', diff --git a/modules/install/Schema.php b/modules/install/Schema.php index 5562d4ccf..6c5457035 100755 --- a/modules/install/Schema.php +++ b/modules/install/Schema.php @@ -1447,6 +1447,25 @@ public static function get() SET short_description = \'Not reached\' WHERE activity_type_id = 100; ', + '377' => ' + ALTER TABLE `calendar_event` MODIFY `joborder_id` int(11) NULL DEFAULT NULL; + + UPDATE `calendar_event` + SET `joborder_id` = NULL + WHERE `joborder_id` = -1; + + UPDATE + `calendar_event` AS `ce` + LEFT JOIN + `joborder` AS `jo` ON + `ce`.`joborder_id` = `jo`.`joborder_id` AND + `ce`.`site_id` = `jo`.`site_id` + SET + `ce`.`joborder_id` = NULL + WHERE + `ce`.`joborder_id` IS NOT NULL AND + `jo`.`joborder_id` IS NULL; + ', ); } From 7f204c527aacec9723239474521d17b078e3cc0f Mon Sep 17 00:00:00 2001 From: anonymoususer72041 <247563575+anonymoususer72041@users.noreply.github.com> Date: Mon, 4 May 2026 12:56:15 +0200 Subject: [PATCH 2/2] Use nullable calendar event job order references --- lib/Calendar.php | 30 +++++++++++++++++++++++------ lib/JobOrders.php | 15 +++++++++++++++ modules/calendar/CalendarUI.php | 6 +++--- modules/candidates/CandidatesUI.php | 2 +- modules/contacts/ContactsUI.php | 2 +- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/lib/Calendar.php b/lib/Calendar.php index c8c0e202c..37ee6039b 100755 --- a/lib/Calendar.php +++ b/lib/Calendar.php @@ -282,8 +282,8 @@ public function getAllEventTypes() * if none. * @param flag Data Item type flag corresponding with $dataItemID, or -1 * if none. - * @param integer Job Order ID with which to associate this event, or -1 - * if none. + * @param integer|null Job Order ID with which to associate this event, or + * NULL if none. * @param string Short event title. * @param integer Event duration in minutes. * @param boolean Enable reminders? @@ -299,6 +299,15 @@ public function addEvent($type, $date, $description, $allDay, $enteredBy, $reminderEnabled, $reminderEmail, $reminderTime, $isPublic, $timeZoneOffset) { + if ($jobOrderID === null) + { + $jobOrderIDSQL = 'NULL'; + } + else + { + $jobOrderIDSQL = $this->_db->makeQueryInteger($jobOrderID); + } + $sql = sprintf( "INSERT INTO calendar_event ( type, @@ -346,7 +355,7 @@ public function addEvent($type, $date, $description, $allDay, $enteredBy, $this->_db->makeQueryInteger($enteredBy), $this->_db->makeQueryInteger($dataItemID), $this->_db->makeQueryInteger($dataItemType), - $this->_db->makeQueryInteger($jobOrderID), + $jobOrderIDSQL, $this->_siteID, $this->_db->makeQueryString($title), $this->_db->makeQueryInteger($duration), @@ -377,8 +386,8 @@ public function addEvent($type, $date, $description, $allDay, $enteredBy, * if none. * @param flag Data Item type flag corresponding with $dataItemID, or -1 * if none. - * @param integer Job Order ID with which to associate this event, or -1 - * if none. + * @param integer|null Job Order ID with which to associate this event, or + * NULL if none. * @param string Short event title. * @param integer Event duration in minutes. * @param boolean Enable reminders? @@ -394,6 +403,15 @@ public function updateEvent($eventID, $type, $date, $description, $allDay, $reminderEnabled, $reminderEmail, $reminderTime, $isPublic, $timeZoneOffset) { + if ($jobOrderID === null) + { + $jobOrderIDSQL = 'NULL'; + } + else + { + $jobOrderIDSQL = $this->_db->makeQueryInteger($jobOrderID); + } + $sql = sprintf( "UPDATE calendar_event @@ -423,7 +441,7 @@ public function updateEvent($eventID, $type, $date, $description, $allDay, ($allDay ? '1' : '0'), $this->_db->makeQueryInteger($dataItemID), $this->_db->makeQueryInteger($dataItemType), - $this->_db->makeQueryInteger($jobOrderID), + $jobOrderIDSQL, $this->_db->makeQueryString($title), $this->_db->makeQueryInteger($duration), ($reminderEnabled ? '1' : '0'), diff --git a/lib/JobOrders.php b/lib/JobOrders.php index 43f7b69e3..b07cc5f7d 100755 --- a/lib/JobOrders.php +++ b/lib/JobOrders.php @@ -288,6 +288,21 @@ public function delete($jobOrderID) $history = new History($this->_siteID); $history->storeHistoryDeleted(DATA_ITEM_JOBORDER, $jobOrderID); + /* Clear calendar event associations for this job order. */ + $sql = sprintf( + "UPDATE + calendar_event + SET + joborder_id = NULL + WHERE + joborder_id = %s + AND + site_id = %s", + $this->_db->makeQueryInteger($jobOrderID), + $this->_siteID + ); + $this->_db->query($sql); + /* Delete pipeline entries from candidate_joborder. */ $sql = sprintf( "DELETE FROM diff --git a/modules/calendar/CalendarUI.php b/modules/calendar/CalendarUI.php index a9cf1d6e4..8b7ec5eff 100755 --- a/modules/calendar/CalendarUI.php +++ b/modules/calendar/CalendarUI.php @@ -472,7 +472,7 @@ private function onAddEvent() $calendar = new Calendar($this->_siteID); $eventID = $calendar->addEvent( - $type, $date, $description, $allDay, $this->_userID, -1, -1, -1, + $type, $date, $description, $allDay, $this->_userID, -1, -1, null, $title, $duration, $reminderEnabled, $reminderEmail, $reminderTime, $publicEntry, $timeZoneOffset ); @@ -559,7 +559,7 @@ private function onEditEvent() } else { - $jobOrderID = 'NULL'; + $jobOrderID = null; } /* Bail out if we received an invalid date. */ @@ -664,7 +664,7 @@ private function onEditEvent() /* Update the event. */ $calendar = new Calendar($this->_siteID); if (!$calendar->updateEvent($eventID, $type, $date, $description, - $allDay, $dataItemID, $dataItemType, 'NULL', $title, $duration, + $allDay, $dataItemID, $dataItemType, $jobOrderID, $title, $duration, $reminderEnabled, $reminderEmail, $reminderTime, $publicEntry, $_SESSION['CATS']->getTimeZoneOffset())) { diff --git a/modules/candidates/CandidatesUI.php b/modules/candidates/CandidatesUI.php index 06efdaa13..ebb85e239 100755 --- a/modules/candidates/CandidatesUI.php +++ b/modules/candidates/CandidatesUI.php @@ -3289,7 +3289,7 @@ private function _addActivity($isJobOrdersMode, $regardingID, } else { - $eventJobOrderID = -1; + $eventJobOrderID = null; } $calendar = new Calendar($this->_siteID); diff --git a/modules/contacts/ContactsUI.php b/modules/contacts/ContactsUI.php index 9196c473c..b9632e1fd 100755 --- a/modules/contacts/ContactsUI.php +++ b/modules/contacts/ContactsUI.php @@ -1499,7 +1499,7 @@ private function _addActivityScheduleEvent($regardingID, $directoryOverride = '' } else { - $eventJobOrderID = -1; + $eventJobOrderID = null; } $calendar = new Calendar($this->_siteID);