| @@ -288,8 +288,10 @@ | ||
| 288 | 288 | // upload dir path for the invoices in PDF format |
| 289 | 289 | 'invoices' => VBO_SITE_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'invoices' . DIRECTORY_SEPARATOR . 'generated', |
| 290 | 290 | // upload dir path for the scans of the ID/Documents of the customers |
| 291 | 291 | 'idscans' => VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'idscans', |
| 292 | + // dir path for the PMS reports data | |
| 293 | + 'pmsdata' => VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'pmsdata', | |
| 292 | 294 | // dir path to extend the reports |
| 293 | 295 | 'report' => VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'report', |
| 294 | 296 | // dir path to extend the SMS APIs |
| 295 | 297 | 'smsapi' => VBO_ADMIN_PATH . DIRECTORY_SEPARATOR . 'smsapi', |
| @@ -317,8 +319,10 @@ | ||
| 317 | 319 | // upload dir path for the invoices in PDF format |
| 318 | 320 | 'invoices' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'vikbooking' . DIRECTORY_SEPARATOR . 'invoices', |
| 319 | 321 | // upload dir path for the scans of the ID/Documents of the customers |
| 320 | 322 | 'idscans' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'vikbooking' . DIRECTORY_SEPARATOR . 'idscans', |
| 323 | + // dir path for the PMS reports data | |
| 324 | + 'pmsdata' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'vikbooking' . DIRECTORY_SEPARATOR . 'pmsdata', | |
| 321 | 325 | // dir path to extend the reports |
| 322 | 326 | 'report' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'vikbooking' . DIRECTORY_SEPARATOR . 'report', |
| 323 | 327 | // dir path to extend the SMS APIs |
| 324 | 328 | 'smsapi' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'vikbooking' . DIRECTORY_SEPARATOR . 'smsapi', |
| @@ -507,8 +511,62 @@ | ||
| 507 | 511 | return JFile::copy($dest, $backup_dirs[$dir_key] . DIRECTORY_SEPARATOR . basename($dest)); |
| 508 | 512 | } |
| 509 | 513 | |
| 510 | 514 | /** |
| 515 | + * Trigger called whenever a mirroring file has been deleted. | |
| 516 | + * Checks if the destination path is recognized, and attempts to | |
| 517 | + * delete the previously backed up file in order to never restore it. | |
| 518 | + * | |
| 519 | + * @param string $dest The path to the file just deleted. | |
| 520 | + * | |
| 521 | + * @return boolean True on success. | |
| 522 | + * | |
| 523 | + * @since 1.8.12 | |
| 524 | + */ | |
| 525 | + public static function triggerDeletionBackup($dest) | |
| 526 | + { | |
| 527 | + // seek the key of the uploaded dir | |
| 528 | + $dir_key = false; | |
| 529 | + foreach (self::getUploadBackupDirs(true) as $key => $path) { | |
| 530 | + if (strpos($dest, $path) !== false) { | |
| 531 | + $dir_key = $key; | |
| 532 | + break; | |
| 533 | + } | |
| 534 | + } | |
| 535 | + if (!$dir_key) { | |
| 536 | + // could not recognize upload dir path from destination file | |
| 537 | + return false; | |
| 538 | + } | |
| 539 | + | |
| 540 | + // always make sure the upload backup dirs are set for bc with those that installed a previous version of the plugin | |
| 541 | + if (!self::installUploadBackup()) { | |
| 542 | + // cannot proceed because backup folders are not set | |
| 543 | + return false; | |
| 544 | + } | |
| 545 | + | |
| 546 | + // import the File class | |
| 547 | + JLoader::import('adapter.filesystem.file'); | |
| 548 | + | |
| 549 | + // get the backup upload dir path for this type of file | |
| 550 | + $backup_dirs = self::getUploadBackupDirs(); | |
| 551 | + if (!isset($backup_dirs[$dir_key])) { | |
| 552 | + // do not proceed | |
| 553 | + return false; | |
| 554 | + } | |
| 555 | + | |
| 556 | + // build the full file path on the mirroring directory | |
| 557 | + $mirroredFilePath = $backup_dirs[$dir_key] . DIRECTORY_SEPARATOR . basename($dest); | |
| 558 | + | |
| 559 | + if (!is_file($mirroredFilePath)) { | |
| 560 | + // do not proceed | |
| 561 | + return false; | |
| 562 | + } | |
| 563 | + | |
| 564 | + // delete the file from its backup dir | |
| 565 | + return JFile::delete($mirroredFilePath); | |
| 566 | + } | |
| 567 | + | |
| 568 | + /** | |
| 511 | 569 | * This method should be called after importing a full backup |
| 512 | 570 | * copy from another Vik Booking installation. It recursively |
| 513 | 571 | * parses all the upload backup directories to mirror. This |
| 514 | 572 | * way, installing a future update will be safe. |
| @@ -735,15 +793,24 @@ | ||
| 735 | 793 | |
| 736 | 794 | $ok = true; |
| 737 | 795 | |
| 738 | 796 | $sql_base = VIKBOOKING_BASE . DIRECTORY_SEPARATOR . 'sql' . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'mysql' . DIRECTORY_SEPARATOR; |
| 797 | + $sqlFiles = glob($sql_base . '*.sql'); | |
| 739 | 798 | |
| 799 | + /** | |
| 800 | + * Make sure the SQL files are properly executed per ascending version rather than alphabetically. | |
| 801 | + * | |
| 802 | + * @since 1.8.3 | |
| 803 | + */ | |
| 804 | + usort($sqlFiles, function($a, $b) { | |
| 805 | + return version_compare(basename($a, '.sql'), basename($b, '.sql')); | |
| 806 | + }); | |
| 807 | + | |
| 740 | 808 | try |
| 741 | 809 | { |
| 742 | - foreach (glob($sql_base . '*.sql') as $file) | |
| 810 | + foreach ($sqlFiles as $file) | |
| 743 | 811 | { |
| 744 | - $name = basename($file); | |
| 745 | - $sql_v = substr($name, 0, strrpos($name, '.')); | |
| 812 | + $sql_v = basename($file, '.sql'); | |
| 746 | 813 | |
| 747 | 814 | if (version_compare($sql_v, $version, '>')) |
| 748 | 815 | { |
| 749 | 816 | // in case the SQL version is newer, execute the queries listed in the file |