| @@ -33,8 +33,17 @@ | ||
| 33 | 33 | * @throws \InvalidArgumentException If day exists and $allowExisting is false |
| 34 | 34 | */ |
| 35 | 35 | public function getOrCreateDay(int $tripId, int $dayNumber, ?string $dayTitle = null, ?string $dayDescription = null, bool $allowExisting = true): int |
| 36 | 36 | { |
| 37 | + // The method body uses $wpdb and $tableDays directly for the day | |
| 38 | + // update/insert below. The cached-query closures declare their own copies, | |
| 39 | + // but the body never did — so $wpdb was null ("Call to a member function | |
| 40 | + // update() on null") and $tableDays was empty ("Incorrect table name '')". | |
| 41 | + // This broke saving an activity onto an existing, titled day and silently | |
| 42 | + // mis-created new days. Declare both here. | |
| 43 | + global $wpdb; | |
| 44 | + $tableDays = TripItineraryDaysTable::getTableName(); | |
| 45 | + | |
| 37 | 46 | // Use QueryCache for caching day existence checks |
| 38 | 47 | $cacheKey = Cache::KEY_DAY_EXISTS . "_{$tripId}_day_{$dayNumber}"; |
| 39 | 48 | |
| 40 | 49 | $existingDay = $this->cacheQueryResult($cacheKey, function() use ($tripId, $dayNumber) { |