| @@ -107,8 +107,10 @@ | ||
| 107 | 107 | * @return boolean True to proceed with the update, otherwise false to stop. |
| 108 | 108 | */ |
| 109 | 109 | public function afterInstallation() |
| 110 | 110 | { |
| 111 | + $dbo = JFactory::getDbo(); | |
| 112 | + | |
| 111 | 113 | /** |
| 112 | 114 | * Unpublish overrides and obtain tracking list. |
| 113 | 115 | * |
| 114 | 116 | * @since 1.6.5 |
| @@ -125,8 +127,91 @@ | ||
| 125 | 127 | { |
| 126 | 128 | $old_vcm_data = file_get_contents(VCM_ADMIN_PATH . DIRECTORY_SEPARATOR . 'controller.php'); |
| 127 | 129 | $old_vcm_data = str_replace("'forcecheck'", "'force_check'", $old_vcm_data); |
| 128 | 130 | file_put_contents(VCM_ADMIN_PATH . DIRECTORY_SEPARATOR . 'controller.php', $old_vcm_data); |
| 131 | + } | |
| 132 | + } | |
| 133 | + | |
| 134 | + if (version_compare($this->version, '1.7.0', '<')) | |
| 135 | + { | |
| 136 | + /** | |
| 137 | + * Install the new "tinyurl" Shortcode. | |
| 138 | + */ | |
| 139 | + $model = JModel::getInstance('vikbooking', 'shortcode', 'admin'); | |
| 140 | + | |
| 141 | + $shortcode = new stdClass; | |
| 142 | + $shortcode->createdby = JFactory::getUser()->id; | |
| 143 | + $shortcode->createdon = JFactory::getDate()->toSql(); | |
| 144 | + $shortcode->title = 'COM_VIKBOOKING_TINYURL_VIEW_DEFAULT_TITLE'; | |
| 145 | + $shortcode->name = 'Tiny URL'; | |
| 146 | + $shortcode->type = 'tinyurl'; | |
| 147 | + $shortcode->shortcode = '[vikbooking view="tinyurl" lang="*"]'; | |
| 148 | + | |
| 149 | + try { | |
| 150 | + $sh_id = $model->save($shortcode); | |
| 151 | + | |
| 152 | + if ($sh_id) { | |
| 153 | + // assign the shortcode to a new page | |
| 154 | + $model->addPage($sh_id); | |
| 155 | + } | |
| 156 | + } catch (Throwable $e) { | |
| 157 | + // do nothing, but prevent fatal errors | |
| 158 | + } | |
| 159 | + | |
| 160 | + /** | |
| 161 | + * Normalize invoice and check-in document names for OTA bookings. | |
| 162 | + * | |
| 163 | + * @since 1.7.0 | |
| 164 | + */ | |
| 165 | + $fixing_invoices = JFolder::files(implode(DIRECTORY_SEPARATOR, [VBO_SITE_PATH, 'helpers', 'invoices', 'generated']), '[0-9]+_\.pdf$', $recursive = false, $fullpath = true); | |
| 166 | + $fixing_checkdocs = JFolder::files(implode(DIRECTORY_SEPARATOR, [VBO_SITE_PATH, 'helpers', 'checkins', 'generated']), '[0-9]+_\.pdf$', $recursive = false, $fullpath = true); | |
| 167 | + foreach (array_merge($fixing_invoices, $fixing_checkdocs) as $fix_doc) { | |
| 168 | + $doc_bid = (int) preg_replace('/[^0-9]/', '', basename($fix_doc)); | |
| 169 | + if (!$doc_bid) { | |
| 170 | + continue; | |
| 171 | + } | |
| 172 | + // whether it's an invoice or a check-in document | |
| 173 | + $is_invoice = strpos($fix_doc, 'invoices') !== false; | |
| 174 | + // get the OTA booking ID | |
| 175 | + $dbo->setQuery( | |
| 176 | + $dbo->getQuery(true) | |
| 177 | + ->select($dbo->qn('idorderota')) | |
| 178 | + ->from($dbo->qn('#__vikbooking_orders')) | |
| 179 | + ->where($dbo->qn('id') . ' = ' . $doc_bid) | |
| 180 | + , 0, 1); | |
| 181 | + $idorderota = $dbo->loadResult(); | |
| 182 | + if (!$idorderota) { | |
| 183 | + // delete file for security reason if the booking does not exist | |
| 184 | + JFile::delete($fix_doc); | |
| 185 | + continue; | |
| 186 | + } | |
| 187 | + // build new safe document name | |
| 188 | + $safe_fname = $doc_bid . '_' . $idorderota . '.pdf'; | |
| 189 | + $safe_fpath = str_replace(basename($fix_doc), $safe_fname, $fix_doc); | |
| 190 | + // rename document file | |
| 191 | + rename($fix_doc, $safe_fpath); | |
| 192 | + // update db reference | |
| 193 | + if ($is_invoice) { | |
| 194 | + // invoice | |
| 195 | + $q = $dbo->getQuery(true) | |
| 196 | + ->update($dbo->qn('#__vikbooking_invoices')) | |
| 197 | + ->set($dbo->qn('file_name') . ' = ' . $dbo->q($safe_fname)) | |
| 198 | + ->where($dbo->qn('idorder') . ' = ' . $doc_bid) | |
| 199 | + ->where($dbo->qn('file_name') . ' = ' . $dbo->q(basename($fix_doc))); | |
| 200 | + } else { | |
| 201 | + // check-in document | |
| 202 | + $q = $dbo->getQuery(true) | |
| 203 | + ->update($dbo->qn('#__vikbooking_customers_orders')) | |
| 204 | + ->set($dbo->qn('checkindoc') . ' = ' . $dbo->q($safe_fname)) | |
| 205 | + ->where($dbo->qn('idorder') . ' = ' . $doc_bid) | |
| 206 | + ->where($dbo->qn('checkindoc') . ' = ' . $dbo->q(basename($fix_doc))); | |
| 207 | + } | |
| 208 | + $dbo->setQuery($q); | |
| 209 | + $dbo->execute(); | |
| 210 | + if (VBOPlatformDetection::isWordPress()) { | |
| 211 | + // trigger files mirroring | |
| 212 | + VikBookingUpdateManager::triggerUploadBackup($safe_fpath); | |
| 213 | + } | |
| 129 | 214 | } |
| 130 | 215 | } |
| 131 | 216 | |
| 132 | 217 | return true; |