| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * Factory application class. |
| 18 | 18 | * |
| 19 | - * @since 1.5 | |
| 19 | + * @since 1.15 (J) - 1.5 (WP) | |
| 20 | 20 | */ |
| 21 | 21 | final class VBOFactory |
| 22 | 22 | { |
| 23 | 23 | /** |
| @@ -55,8 +55,15 @@ | ||
| 55 | 55 | */ |
| 56 | 56 | private static $crontabSimulator; |
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | + * Task Manager instance. | |
| 60 | + * | |
| 61 | + * @var VBOTaskManager | |
| 62 | + */ | |
| 63 | + private static $taskManager; | |
| 64 | + | |
| 65 | + /** | |
| 59 | 66 | * Class constructor. |
| 60 | 67 | * @private This object cannot be instantiated. |
| 61 | 68 | */ |
| 62 | 69 | private function __construct() |
| @@ -121,9 +128,9 @@ | ||
| 121 | 128 | * Returns the current cron factory. |
| 122 | 129 | * |
| 123 | 130 | * @return VBOCronFactory |
| 124 | 131 | * |
| 125 | - * @since 1.5.10 | |
| 132 | + * @since 1.15.10 (J) - 1.5.10 (WP) | |
| 126 | 133 | */ |
| 127 | 134 | public static function getCronFactory() |
| 128 | 135 | { |
| 129 | 136 | // check if cron factory class is already instantiated |
| @@ -144,9 +151,9 @@ | ||
| 144 | 151 | * @param VBOCronFactory $factory The cron jobs factory. |
| 145 | 152 | * |
| 146 | 153 | * @return void |
| 147 | 154 | * |
| 148 | - * @since 1.5.10 | |
| 155 | + * @since 1.15.10 (J) - 1.5.10 (WP) | |
| 149 | 156 | */ |
| 150 | 157 | VBOFactory::getPlatform()->getDispatcher()->trigger('onCreateCronJobsFactoryVikBooking', [static::$cronFactory]); |
| 151 | 158 | } |
| 152 | 159 | |
| @@ -153,13 +160,13 @@ | ||
| 153 | 160 | return static::$cronFactory; |
| 154 | 161 | } |
| 155 | 162 | |
| 156 | 163 | /** |
| 157 | - * Returns the current cron notification center instance. | |
| 164 | + * Returns the current notification center instance. | |
| 158 | 165 | * |
| 159 | 166 | * @return VBONotificationCenter |
| 160 | 167 | * |
| 161 | - * @since 1.6.8 | |
| 168 | + * @since 1.16.8 (J) - 1.6.8 (WP) | |
| 162 | 169 | */ |
| 163 | 170 | public static function getNotificationCenter() |
| 164 | 171 | { |
| 165 | 172 | // check if the notification center class is already instantiated |
| @@ -176,9 +183,9 @@ | ||
| 176 | 183 | * Returns the current crontab simulator. |
| 177 | 184 | * |
| 178 | 185 | * @return VBOCrontabSimulator |
| 179 | 186 | * |
| 180 | - * @since 1.7 | |
| 187 | + * @since 1.17 (J) - 1.7 (WP) | |
| 181 | 188 | */ |
| 182 | 189 | public static function getCrontabSimulator() |
| 183 | 190 | { |
| 184 | 191 | // check if cron factory class is already instantiated |
| @@ -205,10 +212,32 @@ | ||
| 205 | 212 | * Run performances cleaner. |
| 206 | 213 | * Should run every week. |
| 207 | 214 | */ |
| 208 | 215 | static::$crontabSimulator->schedule(new VBOCrontabRunnerAware('performance_cleaner', 60 * 60 * 24 * 7, function(VBOCrontabLogger $logger) { |
| 216 | + // performance cleaning check | |
| 209 | 217 | VBOPerformanceCleaner::runCheck(); |
| 218 | + // clean up expired passcodes from smart locks | |
| 219 | + VBOFactory::getDoorAccessControl()->cleanExpiredPasscodes(); | |
| 210 | 220 | })); |
| 221 | + | |
| 222 | + /** | |
| 223 | + * Run the door-access-control framework. | |
| 224 | + * Should run every hour. | |
| 225 | + */ | |
| 226 | + static::$crontabSimulator->schedule(new VBOCrontabRunnerAware('door_access_control', 60 * 60, function(VBOCrontabLogger $logger) { | |
| 227 | + // watch if any booking is approaching the check-in date | |
| 228 | + VBOFactory::getDoorAccessControl()->handleUpcomingArrivals(); | |
| 229 | + // watch if passcodes get used for the first time | |
| 230 | + VBOFactory::getDoorAccessControl()->watchFirstAccess(); | |
| 231 | + })); | |
| 232 | + | |
| 233 | + /** | |
| 234 | + * Run database optimization. | |
| 235 | + * Should run every hour. | |
| 236 | + */ | |
| 237 | + static::$crontabSimulator->schedule(new VBOCrontabRunnerAware('db_optimization', 60 * 60, function(VBOCrontabLogger $logger) { | |
| 238 | + VBOPerformanceCleaner::optimizeDatabase(); | |
| 239 | + })); | |
| 211 | 240 | } |
| 212 | 241 | |
| 213 | 242 | if (class_exists('VCMCrontabProvider')) { |
| 214 | 243 | // in case VikChannelManager is installed, schedule the native background tasks |
| @@ -229,9 +258,9 @@ | ||
| 229 | 258 | * @param VBOCrontabSimulator $crontab The crontab simulator instance. |
| 230 | 259 | * |
| 231 | 260 | * @return void |
| 232 | 261 | * |
| 233 | - * @since 1.7 | |
| 262 | + * @since 1.17 (J) - 1.7 (WP) | |
| 234 | 263 | */ |
| 235 | 264 | VBOFactory::getPlatform()->getDispatcher()->trigger('onSetupCrontabSimulator', [static::$crontabSimulator]); |
| 236 | 265 | |
| 237 | 266 | // do not run in case we are doing an AJAX request |
| @@ -240,6 +269,76 @@ | ||
| 240 | 269 | } |
| 241 | 270 | } |
| 242 | 271 | |
| 243 | 272 | return static::$crontabSimulator; |
| 273 | + } | |
| 274 | + | |
| 275 | + /** | |
| 276 | + * Returns the current task manager instance. | |
| 277 | + * | |
| 278 | + * @return VBOTaskManager | |
| 279 | + * | |
| 280 | + * @since 1.18.0 (J) - 1.8.0 (WP) | |
| 281 | + */ | |
| 282 | + public static function getTaskManager() | |
| 283 | + { | |
| 284 | + // check if the object is already instantiated | |
| 285 | + if (is_null(static::$taskManager)) | |
| 286 | + { | |
| 287 | + // create object instance | |
| 288 | + static::$taskManager = new VBOTaskManager; | |
| 289 | + } | |
| 290 | + | |
| 291 | + return static::$taskManager; | |
| 292 | + } | |
| 293 | + | |
| 294 | + /** | |
| 295 | + * Returns a new chat mediator instance. | |
| 296 | + * | |
| 297 | + * @return VBOChatMediator | |
| 298 | + * | |
| 299 | + * @since 1.18 (J) - 1.8 (WP) | |
| 300 | + */ | |
| 301 | + public static function getChatMediator() | |
| 302 | + { | |
| 303 | + return new VBOChatMediator(new VBOChatStorageDatabase); | |
| 304 | + } | |
| 305 | + | |
| 306 | + /** | |
| 307 | + * Returns a new help wizard instance. | |
| 308 | + * | |
| 309 | + * @return VBOHelpWizard | |
| 310 | + * | |
| 311 | + * @since 1.18.2 (J) - 1.8.2 (WP) | |
| 312 | + */ | |
| 313 | + public static function getHelpWizard() | |
| 314 | + { | |
| 315 | + $helpWizard = new VBOHelpWizard([ | |
| 316 | + 'delay' => 0, | |
| 317 | + ]); | |
| 318 | + | |
| 319 | + // get VikBooking configuration status | |
| 320 | + $metrics = VikBookingHelper::getFirstSetupMetrics(); | |
| 321 | + | |
| 322 | + // do not spam the user with wizard hints until the first configuration is complete | |
| 323 | + if (empty($metrics['totprices']) || empty($metrics['totrooms']) || empty($metrics['totdailyfares'])) { | |
| 324 | + return $helpWizard; | |
| 325 | + } | |
| 326 | + | |
| 327 | + // attach the folder where the instructions should be stored | |
| 328 | + $helpWizard->addIncludePath(VBO_ADMIN_PATH . '/helpers/src/help/wizard/drivers/'); | |
| 329 | + | |
| 330 | + return $helpWizard; | |
| 331 | + } | |
| 332 | + | |
| 333 | + /** | |
| 334 | + * Returns the Door Access Control instance. | |
| 335 | + * | |
| 336 | + * @return VBODooraccessFactory | |
| 337 | + * | |
| 338 | + * @since 1.18.4 (J) - 1.8.4 (WP) | |
| 339 | + */ | |
| 340 | + public static function getDoorAccessControl() | |
| 341 | + { | |
| 342 | + return VBODooraccessFactory::getInstance(); | |
| 244 | 343 | } |
| 245 | 344 | } |