/** * Applies the Patch Package * * @param array $d * @return boolean */ function applyPatch(&$d) { global $vm_mainframe, $vmLogger, $mosConfig_absolute_path, $db, $sess, $VM_LANG; $updatepackage = vmget($_SESSION, 'vm_updatepackage'); if (empty($updatepackage)) { $vmLogger->err($VM_LANG->_('VM_UPDATE_ERR_DOWNLOAD')); return false; } $patchdir = vmUpdate::getPackageDir($updatepackage); // RickG - Save the location of the patch file JRequest::setVar('patchdir', $patchdir); $packageContents = vmUpdate::getPatchContents($updatepackage); if (!vmUpdate::verifyPackage($packageContents)) { return false; } $errors = 0; foreach ($packageContents['fileArr'] as $fileentry) { $file = $fileentry['filename']; $patch_file = $patchdir . '/' . $file; $orig_file = $mosConfig_absolute_path . '/' . $file; if (file_exists($orig_file)) { if (!is_writable($orig_file) && !@chmod($orig_file, 0644)) { $vmLogger->err(sprintf($VM_LANG->_('VM_UPDATE_ERR_FILE_UNWRITABLE'), $mosConfig_absolute_path . '/' . $file)); $errors++; } } else { if ($fileentry['copy_policy'] == 'only_if_exists') { continue; } $dirname = is_dir($patch_file) ? $orig_file : dirname($orig_file); if (is_dir($patch_file) || !file_exists($dirname)) { if (!vmUpdate::mkdirR($dirname, 0755)) { $vmLogger->err(sprintf($VM_LANG->_('VM_UPDATE_ERR_DIR_UNWRITABLE'), $dirname)); $errors++; } } elseif (!is_writable($mosConfig_absolute_path . '/' . dirname($file)) && !@chmod($mosConfig_absolute_path . '/' . dirname($file), 0755)) { $vmLogger->err(sprintf($VM_LANG->_('VM_UPDATE_ERR_DIR_UNWRITABLE'), $mosConfig_absolute_path . '/' . $file)); $errors++; } } } if ($errors > 0) { return false; } foreach ($packageContents['fileArr'] as $fileentry) { $file = $fileentry['filename']; $patch_file = $patchdir . '/' . $file; $orig_file = $mosConfig_absolute_path . '/' . $file; if (!file_exists($orig_file) && $fileentry['copy_policy'] == 'only_if_exists') { continue; } if (is_dir($patch_file) || !file_exists(dirname($orig_file))) { $dirname = is_dir($patch_file) ? $orig_file : dirname($orig_file); if (!vmUpdate::mkdirR($dirname, 755)) { $vmLogger->crit('Failed to create a necessary directory'); } } elseif (!@copy($patch_file, $orig_file)) { $vmLogger->crit(sprintf($VM_LANG->_('VM_UPDATE_ERR_OVERWRITE_FAILED'), $file)); return false; } else { $vmLogger->debug(sprintf($VM_LANG->_('VM_UPDATE_FILE_OVERWROTE'), $file)); } } foreach ($packageContents['queryArr'] as $query) { if ($db->query($query) === false) { $vmLogger->crit(sprintf($VM_LANG->_('VM_UPDATE_ERR_QUERY_FAILED'), $query)); } else { $vmLogger->debug(sprintf($VM_LANG->_('VM_UPDATE_QUERY_EXECUTED'), $query)); } } // RickG - Run the install file if it exists if ($packageContents['installfile']) { include $packageContents['installfile']; com_vminstall($patchdir); } $db->query('UPDATE `#__components` SET `params` = \'RELEASE=' . $packageContents['toversion'] . '\\nDEV_STATUS=stable\' WHERE `name` = \'virtuemart_version\''); $_SESSION['vmupdatemessage'] = sprintf($VM_LANG->_('VM_UPDATE_SUCCESS'), $packageContents['forversion'], $packageContents['toversion']); // Delete the patch package file vmUpdate::removePackageFile($d); if (vmIsXHR()) { $vm_mainframe->addResponseScript('parent.loadPage("' . $GLOBALS['sess']->url($_SERVER['PHP_SELF'] . '?page=admin.update_result', false, false) . '");'); } else { // Redirect to the Result Page and display the Update Message there vmRedirect($sess->url($_SERVER['PHP_SELF'] . '?page=admin.update_result', false, false)); } }
* VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. * * http://virtuemart.net * */ global $VM_LANG; if (vmget($_SESSION, 'vm_updatepackage') == null) { $vmLogger->err($VM_LANG->_('VM_UPDATE_NOTDOWNLOADED')); return; } require_once CLASSPATH . 'update.class.php'; $packageContents = vmUpdate::getPatchContents(vmget($_SESSION, 'vm_updatepackage')); if ($packageContents === false) { $vmLogger->flush(); // An Error should be logged before return; } vmCommonHTML::loadMooTools(); $formObj = new formFactory($VM_LANG->_('VM_UPDATE_PREVIEW_LBL')); $formObj->startForm(); $vm_mainframe->addStyleDeclaration(".writable { color:green;}\n.unwritable { color:red;font-weight:bold; }"); vmUpdate::stepBar(2); ?> <a name="warning"></a> <div class="shop_warning"> <span style="font-style: italic;"><?php echo $VM_LANG->_('VM_UPDATE_WARNING_TITLE');