PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.6
VikBooking Hotel Booking Engine & PMS v1.6.6
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
vikbooking / libraries / update / fixer.php

fixer.php in VikBooking Hotel Booking Engine & PMS 1.6.6, at libraries/update/fixer.php

230 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 /**
108 * Unpublish overrides and obtain tracking list.
109 *
110 * @since 1.6.5
111 */
112 $track = $this->deactivateBreakingOverrides();
113
114 // register breaking changes, if any
115 VikBookingInstaller::registerBreakingChanges($track);
116
117 if (version_compare($this->version, '1.6.1', '<'))
118 {
119 // resolve conflicting update checks for older VCM versions (1.8.4)
120 if (defined('VIKCHANNELMANAGER_SOFTWARE_VERSION') && version_compare(VIKCHANNELMANAGER_SOFTWARE_VERSION, '1.8.5', '<'))
121 {
122 $old_vcm_data = file_get_contents(VCM_ADMIN_PATH . DIRECTORY_SEPARATOR . 'controller.php');
123 $old_vcm_data = str_replace("'forcecheck'", "'force_check'", $old_vcm_data);
124 file_put_contents(VCM_ADMIN_PATH . DIRECTORY_SEPARATOR . 'controller.php', $old_vcm_data);
125 }
126 }
127
128 return true;
129 }
130
131 /**
132 * Returns a list of possible overrides that may
133 * break the site for backward compatibility errors.
134 *
135 * @return array The list of overrides, grouped by client.
136 *
137 * @since 1.6.5
138 */
139 protected function getBreakingOverrides()
140 {
141 // define initial overrides lookup
142 $lookup = [
143 'admin' => [],
144 'site' => [],
145 'layouts' => [],
146 'widgets' => [],
147 ];
148
149 // check whether the current version (before the update)
150 // was prior than 1.6.5 version
151 if (version_compare($this->version, '1.6.5', '<'))
152 {
153 // multitasking layout must be updated to support the Service Worker
154 $lookup['layouts'][] = VBO_ADMIN_PATH . '/layouts/sidepanel/multitasking.php';
155 }
156
157 /**
158 * NOTE: it is possible to use the code below to automatically deactivate all the existing overrides:
159 * `$lookup = JModel::getInstance('vikbooking', 'overrides', 'admin')->getAllOverrides();`
160 */
161
162 return $lookup;
163 }
164
165 /**
166 * Helper function used to deactivate any overrides that
167 * may corrupt the system because of breaking changes.
168 *
169 * @return array The list of unpublished overrides.
170 *
171 * @since 1.6.5
172 */
173 protected function deactivateBreakingOverrides()
174 {
175 // load list of breaking overrides
176 $lookup = $this->getBreakingOverrides();
177
178 $track = [];
179
180 // get models to manage the overrides
181 $listModel = JModel::getInstance('vikbooking', 'overrides', 'admin');
182 $itemModel = JModel::getInstance('vikbooking', 'override', 'admin');
183
184 foreach ($lookup as $client => $files)
185 {
186 // do not need to load the whole tree in case
187 // the client doesn't report any files
188 if ($files)
189 {
190 $tree = $listModel->getTree($client);
191
192 foreach ($files as $file)
193 {
194 // clean file path
195 $file = JPath::clean($file);
196
197 // check whether the specified file is supported
198 if ($node = $listModel->isSupported($tree, $file))
199 {
200 // skip in case the path has been already unpublished
201 if (in_array($node['override'], isset($track[$client]) ? $track[$client] : []))
202 {
203 continue;
204 }
205
206 // override found, check whether we have an existing
207 // and published override
208 if ($node['has'] && $node['published'])
209 {
210 // deactivate the override
211 if ($itemModel->publish($node['override'], 0))
212 {
213 if (!isset($track[$client]))
214 {
215 $track[$client] = [];
216 }
217
218 // track the unpublished file for later use
219 $track[$client][] = $node['override'];
220 }
221 }
222 }
223 }
224 }
225 }
226
227 return $track;
228 }
229 }
230