| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking - Libraries |
| 4 |
* @subpackage update |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2018 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
/** |
| 15 |
* Implements the abstract methods to fix an update. |
| 16 |
* |
| 17 |
* Never use exit() and die() functions to stop the flow. |
| 18 |
* Return false instead to break process safely. |
| 19 |
*/ |
| 20 |
class VikBookingUpdateFixer |
| 21 |
{ |
| 22 |
/** |
| 23 |
* The current version. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
protected $version; |
| 28 |
|
| 29 |
/** |
| 30 |
* Class constructor. |
| 31 |
*/ |
| 32 |
public function __construct($version) |
| 33 |
{ |
| 34 |
$this->version = $version; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* This method is called before the SQL installation. |
| 39 |
* |
| 40 |
* @return boolean True to proceed with the update, otherwise false to stop. |
| 41 |
*/ |
| 42 |
public function beforeInstallation() |
| 43 |
{ |
| 44 |
/** |
| 45 |
* Make sure all the necessary (and new) directories have been created. |
| 46 |
* |
| 47 |
* @since 1.5.0 |
| 48 |
*/ |
| 49 |
VikBookingUpdateManager::installUploadBackup(); |
| 50 |
|
| 51 |
if (version_compare($this->version, '1.5.0', '<')) { |
| 52 |
/** |
| 53 |
* For those upgrading to VBO 1.5.0 we need to move the customer upload |
| 54 |
* document directories to the new location. Basically, they have been |
| 55 |
* moved to the new dir /customerdocs inside the plugin's upload dir of WP. |
| 56 |
* |
| 57 |
* @since 1.5.0 |
| 58 |
*/ |
| 59 |
$dbo = JFactory::getDbo(); |
| 60 |
|
| 61 |
$old_custdocs_path = str_replace(DIRECTORY_SEPARATOR . 'customerdocs', '', VBO_CUSTOMERS_PATH); |
| 62 |
$new_custdocs_path = VBO_CUSTOMERS_PATH; |
| 63 |
|
| 64 |
$q = "SELECT `docsfolder` FROM `#__vikbooking_customers` WHERE `docsfolder` IS NOT NULL"; |
| 65 |
$dbo->setQuery($q); |
| 66 |
$dbo->execute(); |
| 67 |
if ($dbo->getNumRows()) { |
| 68 |
$doc_folders = $dbo->loadObjectList(); |
| 69 |
foreach ($doc_folders as $doc_folder) { |
| 70 |
if (empty($doc_folder->docsfolder)) { |
| 71 |
continue; |
| 72 |
} |
| 73 |
// move directory to new path |
| 74 |
$from_dir = $old_custdocs_path . DIRECTORY_SEPARATOR . $doc_folder->docsfolder; |
| 75 |
$to_dir = $new_custdocs_path . DIRECTORY_SEPARATOR . $doc_folder->docsfolder; |
| 76 |
if (JFolder::copy($from_dir, $to_dir, $path = '', $force = true)) { |
| 77 |
JFolder::delete($from_dir); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
if (version_compare($this->version, '1.5.11', '<') && !VikBookingLiteManager::guessPro()) |
| 84 |
{ |
| 85 |
$dbo = JFactory::getDbo(); |
| 86 |
// truncate the payment gateways table |
| 87 |
$dbo->setQuery("TRUNCATE TABLE `#__vikbooking_gpayments`"); |
| 88 |
$dbo->execute(); |
| 89 |
} |
| 90 |
|
| 91 |
if (version_compare($this->version, '1.6.0', '<')) |
| 92 |
{ |
| 93 |
// normalize translation records table name |
| 94 |
VikBooking::getTranslator()->normalizeTnTableNames(); |
| 95 |
} |
| 96 |
|
| 97 |
return true; |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* This method is called after the SQL installation. |
| 102 |
* |
| 103 |
* @return boolean True to proceed with the update, otherwise false to stop. |
| 104 |
*/ |
| 105 |
public function afterInstallation() |
| 106 |
{ |
| 107 |
if (version_compare($this->version, '1.6.1', '<')) |
| 108 |
{ |
| 109 |
// resolve conflicting update checks for older VCM versions (1.8.4) |
| 110 |
if (defined('VIKCHANNELMANAGER_SOFTWARE_VERSION') && version_compare(VIKCHANNELMANAGER_SOFTWARE_VERSION, '1.8.5', '<')) |
| 111 |
{ |
| 112 |
$old_vcm_data = file_get_contents(VCM_ADMIN_PATH . DIRECTORY_SEPARATOR . 'controller.php'); |
| 113 |
$old_vcm_data = str_replace("'forcecheck'", "'force_check'", $old_vcm_data); |
| 114 |
file_put_contents(VCM_ADMIN_PATH . DIRECTORY_SEPARATOR . 'controller.php', $old_vcm_data); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
return true; |
| 119 |
} |
| 120 |
} |
| 121 |
|