PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
← All changes | admin/controllers/bookings.php +67 -64 1.8.7 → 1.8.16 View file →
@@ -1202,9 +1202,9 @@
1202 1202 try {
1203 1203 // let the room re-assignment operations start
1204 1204 $moveset = VBOBookingRelocator::getInstance($options)
1205 1205 ->findRelocation();
1206 - } catch (Exception $e) {
1206 + } catch (Throwable $e) {
1207 1207 // propagate the error
1208 1208 VBOHttpDocument::getInstance($app)->close($e->getCode(), $e->getMessage());
1209 1209 }
1210 1210
@@ -1231,8 +1231,9 @@
1231 1231 *
1232 1232 * @return void
1233 1233 *
1234 1234 * @since 1.18.7 (J) - 1.8.7 (WP)
1235 + * @since 1.18.11 (J) - 1.8.11 (WP) operation is performed through a VBOBookingRelocator object.
1235 1236 */
1236 1237 public function apply_room_assignment()
1237 1238 {
1238 1239 $app = JFactory::getApplication();
@@ -1249,14 +1250,11 @@
1249 1250 if (!$moveset) {
1250 1251 VBOHttpDocument::getInstance($app)->close(400, 'Missing reassignment moveset.');
1251 1252 }
1252 1253
1253 - // room details empty container
1254 - $roomDetails = [];
1254 + // identify booking ID
1255 + $bookingId = null;
1255 1256
1256 - // confirm the integrity of the operations to execute
1257 - $confirmedOperations = [];
1258 -
1259 1257 // scan operation steps
1260 1258 $operationSteps = explode('-', $moveset);
1261 1259 foreach ($operationSteps as $operationStep) {
1262 1260 // obtain move details
@@ -1264,76 +1262,81 @@
1264 1262 if (count($moveData) < 4) {
1265 1263 VBOHttpDocument::getInstance($app)->close(400, 'Invalid moveset operation.');
1266 1264 }
1267 1265
1268 - // fetch requested room record
1269 - $dbo->setQuery(
1270 - $dbo->getQuery(true)
1271 - ->select('*')
1272 - ->from($dbo->qn('#__vikbooking_ordersrooms'))
1273 - ->where($dbo->qn('id') . ' = ' . (int) ($moveData[1] ?? 0))
1274 - ->where($dbo->qn('idorder') . ' = ' . (int) ($moveData[0] ?? 0))
1275 - );
1276 - $roomRecord = $dbo->loadAssoc();
1266 + // keep setting booking ID until last moveset operation
1267 + $bookingId = (int) ($moveData[0] ?? 0);
1268 + }
1277 1269
1278 - if (!$roomRecord) {
1279 - VBOHttpDocument::getInstance($app)->close(404, 'Could not find moveset operation.');
1280 - }
1270 + if (!$bookingId) {
1271 + VBOHttpDocument::getInstance($app)->close(400, 'No valid moveset operations.');
1272 + }
1281 1273
1282 - // confirm operation
1283 - $confirmedOperations[] = $moveData;
1274 + try {
1275 + // access booking relocator object
1276 + $relocator = VBOBookingRelocator::getInstance([
1277 + 'id' => $bookingId,
1278 + ]);
1284 1279
1285 - if (!$roomDetails) {
1286 - // load the first and only room details
1287 - $roomDetails = VikBooking::getRoomInfo((int) $roomRecord['idroom'], ['id', 'name'], true);
1288 - }
1280 + // execute given relocation moveset
1281 + $relocator->execMovesetSignature($moveset, $undo);
1282 + } catch (Exception $e) {
1283 + // raise error
1284 + VBOHttpDocument::getInstance($app)->close($e->getCode(), $e->getMessage());
1289 1285 }
1290 1286
1291 - if (!$confirmedOperations) {
1292 - VBOHttpDocument::getInstance($app)->close(400, 'No valid moveset operations.');
1287 + // process completed
1288 + VBOHttpDocument::getInstance($app)->json([
1289 + 'success' => true,
1290 + ]);
1291 + }
1292 +
1293 + /**
1294 + * Regular task to create passcodes for a booking that should have had them.
1295 + *
1296 + * @since 1.18.16 (J) - 1.8.16 (WP)
1297 + */
1298 + public function generatePasscodes()
1299 + {
1300 + $app = JFactory::getApplication();
1301 +
1302 + $bookingId = $app->input->getUInt('bid', 0);
1303 +
1304 + if (!$bookingId) {
1305 + $app->enqueueMessage('Missing booking ID.', 'error');
1306 + $app->redirect('index.php?option=com_vikbooking');
1307 + $app->close();
1293 1308 }
1294 1309
1295 - // get current CMS user and name
1296 - $user = JFactory::getUser();
1297 - $userName = $user->name;
1310 + if (!JSession::checkToken() && !JSession::checkToken('get')) {
1311 + $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
1312 + $app->redirect('index.php?option=com_vikbooking&task=editorder&cid[]=' . $bookingId);
1313 + $app->close();
1314 + }
1298 1315
1299 - // determine action name
1300 - $actionName = $undo ? JText::translate('VBO_UNDO_CHANGES') : JText::translate('VBO_RESOLVE_ROOM_ASSIGNMENT');
1316 + try {
1317 + // access booking registry
1318 + $registry = VBOBookingRegistry::getInstance(['id' => $bookingId]);
1319 + } catch (Exception $e) {
1320 + $app->enqueueMessage($e->getMessage(), 'error');
1321 + $app->redirect('index.php?option=com_vikbooking');
1322 + $app->close();
1323 + }
1301 1324
1302 - // apply all moves
1303 - foreach ($confirmedOperations as $moveData) {
1304 - // determine the room index to apply
1305 - $prev_room_index = $undo ? (int) ($moveData[3] ?? 0) : (int) ($moveData[2] ?? 0);
1306 - $new_room_index = $undo ? (int) ($moveData[2] ?? 0) : (int) ($moveData[3] ?? 0);
1307 - // update current room record
1308 - $dbo->setQuery(
1309 - $dbo->getQuery(true)
1310 - ->update($dbo->qn('#__vikbooking_ordersrooms'))
1311 - ->set($dbo->qn('roomindex') . ' = ' . ($new_room_index ?: 'NULL'))
1312 - ->where($dbo->qn('id') . ' = ' . (int) ($moveData[1] ?? 0))
1313 - ->where($dbo->qn('idorder') . ' = ' . (int) ($moveData[0] ?? 0))
1314 - );
1315 - $dbo->execute();
1325 + // do not check the history to see if previous passcode generation events occurred
1326 + // always simulate the creation of this booking
1327 + $generated = VBOFactory::getDoorAccessControl()->processBookingConfirmation($registry->getData(), $registry->getRooms());
1316 1328
1317 - // Booking History
1318 - VikBooking::getBookingHistoryInstance((int) ($moveData[0] ?? 0))
1319 - ->setExtraData([
1320 - 'action' => 'resolve_room_assignment',
1321 - 'type' => $undo ? 'undo' : 'apply',
1322 - ])
1323 - ->store(
1324 - 'MB',
1325 - sprintf(
1326 - '(%s) %s: %s',
1327 - (string) $userName,
1328 - $actionName,
1329 - JText::sprintf('VBOROOMSUBUNITCHANGEFT', $roomDetails['name'], $prev_room_index, $new_room_index)
1330 - )
1331 - );
1329 + if ($registry->hasPreCheckedIn()) {
1330 + // simulate the pre-check-in completion of the booking
1331 + $generatedTwo = VBOFactory::getDoorAccessControl()->processPrecheckinCompleted($registry->getData(), $registry->getRooms());
1332 1332 }
1333 1333
1334 - // process completed
1335 - VBOHttpDocument::getInstance($app)->json([
1336 - 'success' => true,
1337 - ]);
1334 + // evaluate result
1335 + $generated = $generated || $generatedTwo;
1336 +
1337 + // complete with a successful message
1338 + $app->enqueueMessage(JText::translate('VBO_W_DOORACCESSCONTROL_TITLE'), ($generated ? 'success' : 'warning'));
1339 + $app->redirect('index.php?option=com_vikbooking&task=editorder&cid[]=' . $bookingId);
1340 + $app->close();
1338 1341 }
1339 1342 }