function UninstallAvailable($patch_list, $patch_to_check) { foreach ($patch_list as $more_recent_patch) { if ($more_recent_patch->id == $patch_to_check->id) { break; } $patch_to_check_backup_path = clean_path(remove_file_extension(from_html($patch_to_check->filename))) . '-restore'; $more_recent_patch_backup_path = clean_path(remove_file_extension(from_html($more_recent_patch->filename))) . '-restore'; if ($this->foundConflict($patch_to_check_backup_path, $more_recent_patch_backup_path) && $more_recent_patch->date_entered >= $patch_to_check->date_entered) { return false; } } return true; }
public function testremove_file_extension() { //execute the method and test if it returns expected values //no file extension $expected = ''; $actual = remove_file_extension('fileNoExt'); $this->assertSame($expected, $actual); //simple file extension $expected = 'file1'; $actual = remove_file_extension('file1.txt'); $this->assertSame($expected, $actual); //complex filename $expected = 'file2.ext1'; $actual = remove_file_extension('file2.ext1.ext2'); $this->assertSame($expected, $actual); }
/** * Decide on which Webception configuration file to load * based on the 'test' query string parameter. * * If the test config is not found, it falls back to the default file. * * @param object $app Slim's App object. * @return array Array of the application config. */ function get_webception_config($app) { $config = FALSE; $test_type = $app->request()->params('test'); $webception_config = $app->config('webception'); // If the test query string parameter is set, // a test config will be loaded. if ($test_type !== NULL) { // Sanitize the test type. $test_type = trim(strtolower(remove_file_extension($test_type))); // Filter the test type into the test string. $test_config = sprintf($webception_config['test'], $test_type); // Load the config if it can be found if (file_exists($test_config)) { $config = (require_once $test_config); } } if ($config == FALSE) { $config = (require_once $webception_config['config']); } return $config; }
function getPackagesInStaging($view = 'module') { global $sugar_config; global $current_language; $uh = new UpgradeHistory(); $base_upgrade_dir = "upload://upgrades"; $base_tmp_upgrade_dir = sugar_cached("upgrades/temp"); $uContent = findAllFiles($base_upgrade_dir, array(), false, 'zip'); $upgrade_contents = array(); $content_values = array_values($uContent); $alreadyProcessed = array(); foreach ($content_values as $val) { if (empty($alreadyProcessed[$val])) { $upgrade_contents[] = $val; $alreadyProcessed[$val] = true; } } $upgrades_available = 0; $packages = array(); $mod_strings = return_module_language($current_language, "Administration"); foreach ($upgrade_contents as $upgrade_content) { if (!preg_match('#.*\\.zip$#', strtolower($upgrade_content)) || preg_match("#.*./zips/.*#", strtolower($upgrade_content))) { continue; } $the_base = basename($upgrade_content); $the_md5 = md5_file($upgrade_content); $md5_matches = $uh->findByMd5($the_md5); $file_install = $upgrade_content; if (empty($md5_matches)) { $target_manifest = remove_file_extension($upgrade_content) . '-manifest.php'; require_once $target_manifest; $name = empty($manifest['name']) ? $upgrade_content : $manifest['name']; $version = empty($manifest['version']) ? '' : $manifest['version']; $published_date = empty($manifest['published_date']) ? '' : $manifest['published_date']; $icon = ''; $description = empty($manifest['description']) ? 'None' : $manifest['description']; $uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes'; $type = $this->getUITextForType($manifest['type']); $manifest_type = $manifest['type']; $dependencies = array(); if (isset($manifest['dependencies'])) { $dependencies = $manifest['dependencies']; } //check dependencies first if (!empty($dependencies)) { $uh = new UpgradeHistory(); $not_found = $uh->checkDependencies($dependencies); if (!empty($not_found) && count($not_found) > 0) { $file_install = 'errors_' . $mod_strings['ERR_UW_NO_DEPENDENCY'] . "[" . implode(',', $not_found) . "]"; } } if ($view == 'default' && $manifest_type != 'patch') { continue; } if ($view == 'module' && $manifest_type != 'module' && $manifest_type != 'theme' && $manifest_type != 'langpack') { continue; } if (empty($manifest['icon'])) { $icon = $this->getImageForType($manifest['type']); } else { $path_parts = pathinfo($manifest['icon']); $icon = "<img src=\"" . remove_file_extension($upgrade_content) . "-icon." . $path_parts['extension'] . "\">"; } $upgrades_available++; $packages[] = array('name' => $name, 'version' => $version, 'published_date' => $published_date, 'description' => $description, 'uninstallable' => $uninstallable, 'type' => $type, 'file' => fileToHash($upgrade_content), 'file_install' => fileToHash($upgrade_content)); } //fi } //rof return $packages; }
} } } logThis('finished check to see if current_db_version in $_SESSION equals target_db_version in $_SESSION'); //Look for chance folder and delete it if found. Bug 23595 if (function_exists('deleteChance')) { logThis('running deleteChance() function'); @deleteChance(); } //also add the cache cleaning here. if (function_exists('deleteCache')) { logThis('running deleteCache() function'); @deleteCache(); } //add tabs $from_dir = remove_file_extension($install_file) . "-restore"; logThis('call addNewSystemTabsFromUpgrade(' . $from_dir . ')'); addNewSystemTabsFromUpgrade($from_dir); logThis('finished addNewSystemTabsFromUpgrade'); //run fix on dropdown lists that may have been incorrectly named //fix_dropdown_list(); /////////////////////////////////////////////////////////////////////////////// //// REGISTER UPGRADE logThis('Registering upgrade with UpgradeHistory'); if (!didThisStepRunBefore('commit', 'upgradeHistory')) { set_upgrade_progress('commit', 'in_progress', 'upgradeHistory', 'in_progress'); if (empty($errors)) { $file_action = "copied"; // if error was encountered, script should have died before now $new_upgrade = new UpgradeHistory(); $new_upgrade->filename = $install_file;
/** * gets valid patch file names that exist in upload/upgrade/patch/ */ function getValidPatchName($returnFull = true) { global $base_upgrade_dir; global $mod_strings; global $uh; global $sugar_version; global $sugar_config; $uh = new UpgradeHistory(); list($base_upgrade_dir, $base_tmp_upgrade_dir) = getUWDirs(); $return = array(); // scan for new files (that are not installed) logThis('finding new files for upgrade'); $upgrade_content = ''; $upgrade_contents = findAllFiles($base_upgrade_dir, array(), false, 'zip'); //other variations of zip file i.e. ZIP, zIp,zIP,Zip,ZIp,ZiP $ready = "<ul>\n"; $ready .= "\n\t\t<table>\n\t\t\t<tr>\n\t\t\t\t<td></td>\n\t\t\t\t<td align=left>\n\t\t\t\t\t<b>{$mod_strings['LBL_ML_NAME']}</b>\n\t\t\t\t</td>\n\t\t\t\t<td align=left>\n\t\t\t\t\t<b>{$mod_strings['LBL_ML_TYPE']}</b>\n\t\t\t\t</td>\n\t\t\t\t<td align=left>\n\t\t\t\t\t<b>{$mod_strings['LBL_ML_VERSION']}</b>\n\t\t\t\t</td>\n\t\t\t\t<td align=left>\n\t\t\t\t\t<b>{$mod_strings['LBL_ML_PUBLISHED']}</b>\n\t\t\t\t</td>\n\t\t\t\t<td align=left>\n\t\t\t\t\t<b>{$mod_strings['LBL_ML_UNINSTALLABLE']}</b>\n\t\t\t\t</td>\n\t\t\t\t<td align=left>\n\t\t\t\t\t<b>{$mod_strings['LBL_ML_DESCRIPTION']}</b>\n\t\t\t\t</td>\n\t\t\t</tr>"; $disabled = ''; // assume old patches are there. $upgradeToVersion = array(); // fill with valid patches - we will only use the latest qualified found patch // cn: bug 10609 - notices for uninitialized variables $icon = ''; $name = ''; $type = ''; $version = ''; $published_date = ''; $uninstallable = ''; $description = ''; $disabled = ''; foreach ($upgrade_contents as $upgrade_content) { if (!preg_match("#.*\\.zip\$#i", $upgrade_content)) { continue; } $the_base = basename($upgrade_content); $the_md5 = md5_file($upgrade_content); $md5_matches = $uh->findByMd5($the_md5); /* If a patch is in the /patch dir AND has no record in the upgrade_history table we assume that it's the one we want. * Edge-case: manual upgrade with a FTP of a patch; UH table has no entry for it. Assume nothing. :( */ if (0 == sizeof($md5_matches)) { $target_manifest = remove_file_extension($upgrade_content) . '-manifest.php'; require_once $target_manifest; if (empty($manifest['version'])) { logThis("*** Potential error: patch found with no version [ {$upgrade_content} ]"); continue; } if (!isset($manifest['type']) || $manifest['type'] != 'patch') { logThis("*** Potential error: patch found with either no 'type' or non-patch type [ {$upgrade_content} ]"); continue; } $upgradeToVersion[$manifest['version']] = urlencode($upgrade_content); $name = empty($manifest['name']) ? $upgrade_content : $manifest['name']; $version = empty($manifest['version']) ? '' : $manifest['version']; $published_date = empty($manifest['published_date']) ? '' : $manifest['published_date']; $icon = ''; $description = empty($manifest['description']) ? 'None' : $manifest['description']; $uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes'; $type = getUITextForType($manifest['type']); $manifest_type = $manifest['type']; if (empty($manifest['icon'])) { $icon = getImageForType($manifest['type']); } else { $path_parts = pathinfo($manifest['icon']); $icon = "<!--not_in_theme!--><img src=\"" . remove_file_extension($upgrade_content) . "-icon." . $path_parts['extension'] . "\">"; } } } // cn: bug 10488 use the NEWEST upgrade/patch available when running upgrade wizard. ksort($upgradeToVersion); $upgradeToVersion = array_values($upgradeToVersion); $newest = array_pop($upgradeToVersion); $_SESSION['install_file'] = urldecode($newest); // in-case it was there from a prior. logThis("*** UW using [ {$_SESSION['install_file']} ] as source for patch files."); $cleanUpgradeContent = urlencode($_SESSION['install_file']); // cn: 10606 - cannot upload a patch file since this returned always. if (!empty($cleanUpgradeContent)) { $ready .= "<tr><td>{$icon}</td><td>{$name}</td><td>{$type}</td><td>{$version}</td><td>{$published_date}</td><td>{$uninstallable}</td><td>{$description}</td>\n"; $ready .= <<<eoq \t <td> \t\t\t\t<form action="index.php" method="post"> \t\t\t\t\t<input type="hidden" name="module" value="UpgradeWizard"> \t\t\t\t\t<input type="hidden" name="action" value="index"> \t\t\t\t\t<input type="hidden" name="step" value="{$_REQUEST['step']}"> \t\t\t\t\t<input type="hidden" name="run" value="delete"> \t \t\t<input type=hidden name="install_file" value="{$cleanUpgradeContent}" /> \t \t\t<input type=submit value="{$mod_strings['LBL_BUTTON_DELETE']}" /> \t\t\t\t</form> \t\t\t</td></table> eoq; $disabled = "DISABLED"; } if (empty($cleanUpgradeContent)) { $ready .= "<tr><td colspan='7'><i>None</i></td>\n"; $ready .= "</table>\n"; } $ready .= "<br></ul>\n"; $return['ready'] = $ready; $return['disabled'] = $disabled; if ($returnFull) { return $return; } }
function disable_copy() { //when we disable we want to copy the -restore files back into the file system //but we should check the version in the module install against the version on the file system //if they match then we can copy the file back, but otherwise we should ask the user. // $GLOBALS['log']->debug('ModuleInstaller.php->disable_copy()'); if (isset($GLOBALS['mi_overwrite_files']) && $GLOBALS['mi_overwrite_files']) { // $GLOBALS['log']->debug('ModuleInstaller.php->disable_copy():mi_overwrite_files=true'); if (!empty($this->installdefs['copy'])) { // $GLOBALS['log']->debug('ModuleInstaller.php->disable_copy(): installdefs not empty'); foreach ($this->installdefs['copy'] as $cp) { $cp['to'] = clean_path(str_replace('<basepath>', $this->base_dir, $cp['to'])); $backup_path = clean_path(remove_file_extension(urldecode(hashToFile($_REQUEST['install_file']))) . "-restore/" . $cp['to']); // bug 16966 tyoung - replaced missing assignment to $backup_path //check if this file exists in the -restore directory // $GLOBALS['log']->debug("ModuleInstaller.php->disable_copy(): backup_path=".$backup_path); if (file_exists($backup_path)) { //since the file exists, then we want do an md5 of the install version and the file system version $from = str_replace('<basepath>', $this->base_dir, $cp['from']); //if(is_file($from) && md5_file($from) == md5_file($cp['to'])){ //since the files are the same then we can safely move back from the -restore //directory into the file system $GLOBALS['log']->debug("DISABLE COPY:: FROM: " . $backup_path . " TO: " . $cp['to']); $this->copy_path($backup_path, $cp['to']); /*}else{ //since they are not equal then we need to prompt the user }*/ } //fi } //rof } //fi } //fi }
/** * gets valid patch file names that exist in upload/upgrade/patch/ */ function getValidPatchName($returnFull = true) { global $base_upgrade_dir; global $mod_strings; global $uh; $return = array(); // scan for new files (that are not installed) logThis('finding new files for upgrade'); $upgrade_content = ''; $upgrade_contents = findAllFiles($base_upgrade_dir, array(), false); $upgrades_available = 0; $ready = "<ul>\n"; $ready .= "\n\t\t<table>\n\t\t\t<tr>\n\t\t\t\t<th></th>\n\t\t\t\t<th align=left>\n\t\t\t\t\t{$mod_strings['LBL_ML_NAME']}\n\t\t\t\t</th>\n\t\t\t\t<th>\n\t\t\t\t\t{$mod_strings['LBL_ML_TYPE']}\n\t\t\t\t</th>\n\t\t\t\t<th>\n\t\t\t\t\t{$mod_strings['LBL_ML_VERSION']}\n\t\t\t\t</th>\n\t\t\t\t<th>\n\t\t\t\t\t{$mod_strings['LBL_ML_PUBLISHED']}\n\t\t\t\t</th>\n\t\t\t\t<th>\n\t\t\t\t\t{$mod_strings['LBL_ML_UNINSTALLABLE']}\n\t\t\t\t</th>\n\t\t\t\t<th>\n\t\t\t\t\t{$mod_strings['LBL_ML_DESCRIPTION']}\n\t\t\t\t</th>\n\t\t\t</tr>"; $disabled = ''; foreach ($upgrade_contents as $upgrade_content) { if (!preg_match("#.*\\.zip\$#i", $upgrade_content)) { continue; } $upgrade_content = clean_path($upgrade_content); $the_base = basename($upgrade_content); $the_md5 = md5_file($upgrade_content); $md5_matches = $uh->findByMd5($the_md5); if (0 == sizeof($md5_matches)) { $target_manifest = remove_file_extension($upgrade_content) . '-manifest.php'; require_once $target_manifest; $name = empty($manifest['name']) ? $upgrade_content : $manifest['name']; $version = empty($manifest['version']) ? '' : $manifest['version']; $published_date = empty($manifest['published_date']) ? '' : $manifest['published_date']; $icon = ''; $description = empty($manifest['description']) ? 'None' : $manifest['description']; $uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes'; $type = getUITextForType($manifest['type']); $manifest_type = $manifest['type']; if ($manifest_type != 'patch') { continue; } if (empty($manifest['icon'])) { $icon = getImageForType($manifest['type']); } else { $path_parts = pathinfo($manifest['icon']); $icon = "<img src=\"" . remove_file_extension($upgrade_content) . "-icon." . $path_parts['extension'] . "\">"; } $upgrades_available++; if ($upgrades_available > 1) { logThis('ERROR: found more than 1 qualified upgrade file! Stopping upgrade.'); $stop = true; // more than 1 upgrade?!? } else { logThis('found a valid upgrade file: ' . $upgrade_content); $_SESSION['install_file'] = $upgrade_content; // in-case it was there from a prior. $stop = false; } $ready .= "<tr><td>{$icon}</td><td>{$name}</td><td>{$type}</td><td>{$version}</td><td>{$published_date}</td><td>{$uninstallable}</td><td>{$description}</td>\n"; $cleanUpgradeContent = urlencode($upgrade_content); $ready .= <<<eoq \t <td> \t\t\t\t\t<form action="index.php" method="post"> \t\t\t\t\t\t<input type="hidden" name="module" value="UpgradeWizard"> \t\t\t\t\t\t<input type="hidden" name="action" value="index"> \t\t\t\t\t\t<input type="hidden" name="step" value="{$_REQUEST['step']}"> \t\t\t\t\t\t<input type="hidden" name="run" value="delete"> \t \t\t<input type=hidden name="install_file" value="{$cleanUpgradeContent}" /> \t \t\t<input type=submit value="{$mod_strings['LBL_BUTTON_DELETE']}" /> \t\t\t\t\t</form> \t\t\t\t</td> eoq; $disabled = "DISABLED"; } } $ready .= "</table>\n"; if ($upgrades_available == 0) { $ready .= "<i>None</i><br>\n"; } $ready .= "</ul>\n"; $return['ready'] = $ready; $return['disabled'] = $disabled; if ($returnFull) { return $return; } }
/** * searches upgrade dir for lang pack files. * * @return string HTML of available lang packs */ function getLangPacks($display_commit = true, $types = array('langpack'), $notice_text = '') { global $mod_strings; global $next_step; global $base_upgrade_dir; if (empty($notice_text)) { $notice_text = $mod_strings['LBL_LANG_PACK_READY']; } $ret = "<tr><td colspan=7 align=left>{$notice_text}</td></tr>"; //$ret .="<table width='100%' cellpadding='0' cellspacing='0' border='0'>"; $ret .= "<tr>\n <td width='20%' ><b>{$mod_strings['LBL_ML_NAME']}</b></td>\n <td width='15%' ><b>{$mod_strings['LBL_ML_VERSION']}</b></td>\n <td width='15%' ><b>{$mod_strings['LBL_ML_PUBLISHED']}</b></td>\n <td width='15%' ><b>{$mod_strings['LBL_ML_UNINSTALLABLE']}</b></td>\n <td width='20%' ><b>{$mod_strings['LBL_ML_DESCRIPTION']}</b></td>\n <td width='7%' ></td>\n <td width='1%' ></td>\n <td width='7%' ></td>\n </tr>\n"; $files = array(); // duh, new installs won't have the upgrade folders if (!is_dir($base_upgrade_dir)) { mkdir_recursive($base_upgrade_dir); } $subdirs = array('full', 'langpack', 'module', 'patch', 'theme', 'temp'); foreach ($subdirs as $subdir) { mkdir_recursive("{$base_upgrade_dir}/{$subdir}"); } $files = findAllFiles($base_upgrade_dir, $files); $hidden_input = ''; unset($_SESSION['hidden_input']); foreach ($files as $file) { if (!preg_match("#.*\\.zip\$#", $file)) { continue; } // skip installed lang packs if (isset($_SESSION['INSTALLED_LANG_PACKS']) && in_array($file, $_SESSION['INSTALLED_LANG_PACKS'])) { continue; } // handle manifest.php $target_manifest = remove_file_extension($file) . '-manifest.php'; $license_file = remove_file_extension($file) . '-license.txt'; include $target_manifest; if (!empty($types)) { if (!in_array(strtolower($manifest['type']), $types)) { continue; } } $md5_matches = array(); if ($manifest['type'] == 'module') { $uh = new UpgradeHistory(); $upgrade_content = clean_path($file); $the_base = basename($upgrade_content); $the_md5 = md5_file($upgrade_content); $md5_matches = $uh->findByMd5($the_md5); } if ($manifest['type'] != 'module' || 0 == sizeof($md5_matches)) { $name = empty($manifest['name']) ? $file : $manifest['name']; $version = empty($manifest['version']) ? '' : $manifest['version']; $published_date = empty($manifest['published_date']) ? '' : $manifest['published_date']; $icon = ''; $description = empty($manifest['description']) ? 'None' : $manifest['description']; $uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes'; $manifest_type = $manifest['type']; $commitPackage = getPackButton('commit', $target_manifest, $file, $next_step); $deletePackage = getPackButton('remove', $target_manifest, $file, $next_step); //$ret .="<table width='100%' cellpadding='0' cellspacing='0' border='0'>"; $ret .= "<tr>"; $ret .= "<td width='20%' >" . $name . "</td>"; $ret .= "<td width='15%' >" . $version . "</td>"; $ret .= "<td width='15%' >" . $published_date . "</td>"; $ret .= "<td width='15%' >" . $uninstallable . "</td>"; $ret .= "<td width='20%' >" . $description . "</td>"; if ($display_commit) { $ret .= "<td width='7%'>{$commitPackage}</td>"; } $ret .= "<td width='1%'></td>"; $ret .= "<td width='7%'>{$deletePackage}</td>"; $ret .= "</td></tr>"; $clean_field_name = "accept_lic_" . str_replace('.', '_', urlencode(basename($file))); if (is_file($license_file)) { //rrs $ret .= "<tr><td colspan=6>"; $ret .= getLicenseDisplay('commit', $target_manifest, $file, $next_step, $license_file, $clean_field_name); $ret .= "</td></tr>"; $hidden_input .= "<input type='hidden' name='{$clean_field_name}' id='{$clean_field_name}' value='no'>"; } else { $hidden_input .= "<input type='hidden' name='{$clean_field_name}' id='{$clean_field_name}' value='yes'>"; } } //fi } //rof $_SESSION['hidden_input'] = $hidden_input; if (count($files) > 0) { $ret .= "</tr><td colspan=7>"; $ret .= "<form name='commit' action='install.php' method='POST'>\n <input type='hidden' name='current_step' value='{$next_step}'>\n <input type='hidden' name='goto' value='Re-check'>\n <input type='hidden' name='languagePackAction' value='commit'>\n <input type='hidden' name='install_type' value='custom'>\n </form>\n "; $ret .= "</td></tr>"; } else { $ret .= "</tr><td colspan=7><i>{$mod_strings['LBL_LANG_NO_PACKS']}</i></td></tr>"; } return $ret; }
unlinkTempFiles(); die($mod_strings['ERR_UW_NOT_ACCEPTIBLE_TYPE']); } } elseif ($view == "default") { if ($upgrade_zip_type != "patch") { unlinkTempFiles(); die($mod_strings['ERR_UW_ONLY_PATCHES']); } } $base_filename = pathinfo($tempFile, PATHINFO_BASENAME); mkdir_recursive("{$base_upgrade_dir}/{$upgrade_zip_type}"); $target_path = "{$base_upgrade_dir}/{$upgrade_zip_type}/{$base_filename}"; $target_manifest = remove_file_extension($target_path) . "-manifest.php"; if (isset($manifest['icon']) && $manifest['icon'] != "") { $icon_location = extractFile($tempFile, $manifest['icon']); copy($icon_location, remove_file_extension($target_path) . "-icon." . pathinfo($icon_location, PATHINFO_EXTENSION)); } if (rename($tempFile, $target_path)) { copy($manifest_file, $target_manifest); $GLOBALS['ML_STATUS_MESSAGE'] = $base_filename . $mod_strings['LBL_UW_UPLOAD_SUCCESS']; } else { $GLOBALS['ML_STATUS_MESSAGE'] = $mod_strings['ERR_UW_UPLOAD_ERROR']; } } else { unlinkTempFiles(); die($mod_strings['ERR_UW_NO_MANIFEST']); } } } else { if ($run == $mod_strings['LBL_UW_BTN_DELETE_PACKAGE']) { if (!empty($_REQUEST['install_file'])) {
function UninstallAvailable($patch_list, $patch_to_check) { //before we even go through the list, let us try to see if we find a match. $history_object = $this->checkForExisting($patch_to_check); if ($history_object != null) { if (!empty($history_object->id_name) && !empty($patch_to_check->id_name) && strcmp($history_object->id_name, $patch_to_check->id_name) == 0 || strcmp($history_object->name, $patch_to_check->name) == 0) { //we have found a match //if the patch_to_check version is greater than the found version return $this->is_right_version_greater(explode('.', $history_object->version), explode('.', $patch_to_check->version)); } else { return true; } } //we will only go through this loop if we have not found another UpgradeHistory object //with a matching unique_key in the database foreach ($patch_list as $more_recent_patch) { if ($more_recent_patch->id == $patch_to_check->id) { break; } //we will only resort to checking the files if we cannot find the unique_keys //or the unique_keys do not match $patch_to_check_backup_path = clean_path(remove_file_extension(from_html($patch_to_check->filename))) . '-restore'; $more_recent_patch_backup_path = clean_path(remove_file_extension(from_html($more_recent_patch->filename))) . '-restore'; if ($this->foundConflict($patch_to_check_backup_path, $more_recent_patch_backup_path) && $more_recent_patch->date_entered >= $patch_to_check->date_entered) { return false; } } return true; }
\t\t</th> \t\t<th> \t\t\t{$mod_strings['LBL_ML_ACTION']} \t\t</th> \t</tr> eoq; foreach ($installeds as $installed) { $form_action = ''; $filename = from_html($installed->filename); $date_entered = $installed->date_entered; $type = $installed->type; $version = $installed->version; $upgrades_installed++; $link = ""; $view = 'default'; $target_manifest = remove_file_extension($filename) . "-manifest.php"; // cn: bug 9174 - cleared out upgrade dirs, or corrupt entries in upgrade_history give us bad file paths if (is_file($target_manifest)) { require_once "{$target_manifest}"; $name = empty($manifest['name']) ? $filename : $manifest['name']; $description = empty($manifest['description']) ? $mod_strings['LBL_UW_NONE'] : $manifest['description']; if (isset($manifest['icon']) && $manifest['icon'] != "") { $manifest_copy_files_to_dir = isset($manifest['copy_files']['to_dir']) ? clean_path($manifest['copy_files']['to_dir']) : ""; $manifest_copy_files_from_dir = isset($manifest['copy_files']['from_dir']) ? clean_path($manifest['copy_files']['from_dir']) : ""; $manifest_icon = clean_path($manifest['icon']); $icon = "<img src=\"" . $manifest_copy_files_to_dir . ($manifest_copy_files_from_dir != "" ? substr($manifest_icon, strlen($manifest_copy_files_from_dir) + 1) : $manifest_icon) . "\">"; } else { $icon = getImageForType($manifest['type']); } $uwHistory .= "<form action=\"" . $form_action . "_prepare\" method=\"post\">\n" . "<tr><td>{$icon}</td><td>{$name}</td><td>{$type}</td><td>{$version}</td><td>{$date_entered}</td><td>{$description}</td><td>{$link}</td></tr>\n" . "</form>\n"; }
function getPackagesInStaging($view = 'module') { global $sugar_config; global $current_language; $uh = new UpgradeHistory(); $base_upgrade_dir = $sugar_config['upload_dir'] . "/upgrades"; $base_tmp_upgrade_dir = "{$base_upgrade_dir}/temp"; $uContent = findAllFiles("{$base_upgrade_dir}", array(), false, 'zip', $base_tmp_upgrade_dir); //other variations of zip file i.e. ZIP, zIp,zIP,Zip,ZIp,ZiP $extns = array('ZIP', 'ZIp', 'ZiP', 'Zip', 'zIP', 'zIp', 'ziP'); foreach ($extns as $extn) { $uContent = array_merge($uContent, findAllFiles("{$base_upgrade_dir}", array(), false, $extn, $base_tmp_upgrade_dir)); } $upgrade_contents = array(); $content_values = array_values($uContent); $alreadyProcessed = array(); foreach ($content_values as $val) { if (empty($alreadyProcessed[$val])) { $upgrade_contents[] = $val; $alreadyProcessed["{$val}"] = true; } } $upgrades_available = 0; $packages = array(); $mod_strings = return_module_language($current_language, "Administration"); foreach ($upgrade_contents as $upgrade_content) { if (!preg_match("#.*\\.zip\$#", strtolower($upgrade_content)) || preg_match("#.*./zips/.*#", strtolower($upgrade_content))) { continue; } $upgrade_content = clean_path($upgrade_content); // Bug 22285 - fix for UNC paths if (substr($upgrade_content, 0, 2) == '\\\\') { $upgrade_content = '\\\\' . $upgrade_content; } $the_base = basename($upgrade_content); $the_md5 = md5_file($upgrade_content); $md5_matches = $uh->findByMd5($the_md5); $file_install = $upgrade_content; if (0 == sizeof($md5_matches)) { $target_manifest = remove_file_extension($upgrade_content) . '-manifest.php'; require_once $target_manifest; $name = empty($manifest['name']) ? $upgrade_content : $manifest['name']; $version = empty($manifest['version']) ? '' : $manifest['version']; $published_date = empty($manifest['published_date']) ? '' : $manifest['published_date']; $icon = ''; $description = empty($manifest['description']) ? 'None' : $manifest['description']; $uninstallable = empty($manifest['is_uninstallable']) ? 'No' : 'Yes'; $type = $this->getUITextForType($manifest['type']); $manifest_type = $manifest['type']; $dependencies = array(); if (isset($manifest['dependencies'])) { $dependencies = $manifest['dependencies']; } //check dependencies first if (!empty($dependencies)) { $uh = new UpgradeHistory(); $not_found = $uh->checkDependencies($dependencies); if (!empty($not_found) && count($not_found) > 0) { $file_install = 'errors_' . $mod_strings['ERR_UW_NO_DEPENDENCY'] . "[" . implode(',', $not_found) . "]"; } //fi } if ($view == 'default' && $manifest_type != 'patch') { continue; } if ($view == 'module' && $manifest_type != 'module' && $manifest_type != 'theme' && $manifest_type != 'langpack') { continue; } if (empty($manifest['icon'])) { $icon = $this->getImageForType($manifest['type']); } else { $path_parts = pathinfo($manifest['icon']); $icon = "<img src=\"" . remove_file_extension($upgrade_content) . "-icon." . $path_parts['extension'] . "\">"; } $upgrades_available++; // uploaded file in cache/upload $fileS = explode('/', $upgrade_content); $c = count($fileS); $fileName = isset($fileS[$c - 1]) && !empty($fileS[$c - 1]) ? $fileS[$c - 1] : $fileS[$c - 2]; $upload_file = $sugar_config['upload_dir'] . $fileName; $upgrade_content = urlencode($upgrade_content); $upload_content = urlencode($upload_file); $packages[] = array('name' => $name, 'version' => $version, 'published_date' => $published_date, 'description' => $description, 'uninstallable' => $uninstallable, 'type' => $type, 'file_install' => fileToHash($file_install), 'file' => fileToHash($upgrade_content), 'upload_file' => $upload_content); } //fi } //rof return $packages; }
function buildInstallGrid($view) { $uh = new UpgradeHistory(); $installeds = $uh->getAll(); $upgrades_installed = 0; $installed_objects = array(); foreach ($installeds as $installed) { $filename = from_html($installed->filename); $date_entered = $installed->date_entered; $type = $installed->type; $version = $installed->version; $upgrades_installed++; $link = ""; switch ($type) { case "theme": case "langpack": case "module": case "patch": $manifest_file = extractManifest($filename); require_once $manifest_file; $name = empty($manifest['name']) ? $filename : $manifest['name']; $description = empty($manifest['description']) ? $mod_strings['LBL_UW_NONE'] : $manifest['description']; if (($upgrades_installed == 0 || $uh->UninstallAvailable($installeds, $installed)) && is_file($filename) && !empty($manifest['is_uninstallable'])) { $link = urlencode($filename); } else { $link = 'false'; } break; default: break; } if ($view == 'default' && $type != 'patch') { continue; } if ($view == 'module' && $type != 'module' && $type != 'theme' && $type != 'langpack') { continue; } $target_manifest = remove_file_extension($filename) . "-manifest.php"; require_once "{$target_manifest}"; if (isset($manifest['icon']) && $manifest['icon'] != "") { $manifest_copy_files_to_dir = isset($manifest['copy_files']['to_dir']) ? clean_path($manifest['copy_files']['to_dir']) : ""; $manifest_copy_files_from_dir = isset($manifest['copy_files']['from_dir']) ? clean_path($manifest['copy_files']['from_dir']) : ""; $manifest_icon = clean_path($manifest['icon']); $icon = "<img src=\"" . $manifest_copy_files_to_dir . ($manifest_copy_files_from_dir != "" ? substr($manifest_icon, strlen($manifest_copy_files_from_dir) + 1) : $manifest_icon) . "\">"; } else { $icon = getImageForType($manifest['type']); } $installed_objects[] = array('icon' => $icon, 'name' => $name, 'type' => $type, 'version' => $version, 'date_entered' => $date_entered, 'description' => $description, 'file' => $link); //print( "<form action=\"" . $form_action . "_prepare\" method=\"post\">\n" ); //print( "<tr><td>$icon</td><td>$name</td><td>$type</td><td>$version</td><td>$date_entered</td><td>$description</td><td>$link</td></tr>\n" ); //print( "</form>\n" ); } }
if ($upgrade_zip_type != "patch") { logThis('ERROR: incorrect patch type found: ' . $upgrade_zip_type); unlinkTempFiles(); $out = "<b><span class='error'>{$mod_strings['ERR_UW_ONLY_PATCHES']}</span></b><br />"; break; } $base_filename = preg_replace("#\\\\#", "/", $base_filename); $base_filename = basename($base_filename); mkdir_recursive("{$base_upgrade_dir}/{$upgrade_zip_type}"); $target_path = "{$base_upgrade_dir}/{$upgrade_zip_type}/{$base_filename}"; $target_manifest = remove_file_extension($target_path) . "-manifest.php"; if (isset($manifest['icon']) && $manifest['icon'] != "") { logThis('extracting icons.'); $icon_location = extractFile($tempFile, $manifest['icon']); $path_parts = pathinfo($icon_location); copy($icon_location, remove_file_extension($target_path) . "-icon." . $path_parts['extension']); } if (copy($tempFile, $target_path)) { logThis('copying manifest.php to final destination.'); copy($manifest_file, $target_manifest); $out .= "<b>{$base_filename} {$mod_strings['LBL_UW_FILE_UPLOADED']}.</b><br>\n"; } else { logThis('ERROR: cannot copy manifest.php to final destination.'); $out .= "<b><span class='error'>{$mod_strings['ERR_UW_UPLOAD_ERR']}</span></b><br />"; break; } } else { logThis('ERROR: no manifest.php file found!'); unlinkTempFiles(); $out = "<b><span class='error'>{$mod_strings['ERR_UW_NO_MANIFEST']}</span></b><br />"; break;
} } } logThis('finished check to see if current_db_version in $_SESSION equals target_db_version in $_SESSION'); //Look for chance folder and delete it if found. Bug 23595 if (function_exists('deleteChance')) { logThis('running deleteChance() function'); @deleteChance(); } //also add the cache cleaning here. if (function_exists('deleteCache')) { logThis('running deleteCache() function'); @deleteCache(); } //add tabs $from_dir = clean_path(remove_file_extension($install_file) . "-restore"); logThis('call addNewSystemTabsFromUpgrade(' . $from_dir . ')'); addNewSystemTabsFromUpgrade($from_dir); logThis('finished addNewSystemTabsFromUpgrade'); //run fix on dropdown lists that may have been incorrectly named //fix_dropdown_list(); /////////////////////////////////////////////////////////////////////////////// //// REGISTER UPGRADE logThis('Registering upgrade with UpgradeHistory'); if (!didThisStepRunBefore('commit', 'upgradeHistory')) { set_upgrade_progress('commit', 'in_progress', 'upgradeHistory', 'in_progress'); if (empty($errors)) { $file_action = "copied"; // if error was encountered, script should have died before now $new_upgrade = new UpgradeHistory(); $new_upgrade->filename = $install_file;
function langPackUnpack($unpack_type = 'langpack', $full_file = '') { global $sugar_config; global $base_upgrade_dir; global $base_tmp_upgrade_dir; $manifest = array(); if (!empty($full_file)) { $tempFile = $full_file; $base_filename = urldecode($tempFile); $base_filename = preg_replace("#\\\\#", "/", $base_filename); $base_filename = basename($base_filename); } else { $tempFile = getcwd() . '/' . $sugar_config['upload_dir'] . $_FILES['language_pack']['name']; $base_filename = $_FILES['language_pack']['name']; } $manifest_file = extractManifest($tempFile, $base_tmp_upgrade_dir); if ($unpack_type == 'module') { $license_file = extractFile($tempFile, 'LICENSE.txt', $base_tmp_upgrade_dir); } if (is_file($manifest_file)) { if ($unpack_type == 'module' && is_file($license_file)) { copy($license_file, getcwd() . '/' . $sugar_config['upload_dir'] . 'upgrades/' . $unpack_type . '/' . remove_file_extension($base_filename) . "-license.txt"); } copy($manifest_file, getcwd() . '/' . $sugar_config['upload_dir'] . 'upgrades/' . $unpack_type . '/' . remove_file_extension($base_filename) . "-manifest.php"); require_once $manifest_file; validate_manifest($manifest); $upgrade_zip_type = $manifest['type']; // exclude the bad permutations /*if($upgrade_zip_type != "langpack") { unlinkTempFiles($manifest_file, $tempFile); die( "You can only upload module packs, theme packs, and language packs on this page." ); }*/ //$base_filename = urldecode( $_REQUEST['language_pack_escaped'] ); $base_filename = preg_replace("#\\\\#", "/", $base_filename); $base_filename = basename($base_filename); mkdir_recursive("{$base_upgrade_dir}/{$upgrade_zip_type}"); $target_path = getcwd() . "/{$base_upgrade_dir}/{$upgrade_zip_type}/{$base_filename}"; $target_manifest = remove_file_extension($target_path) . "-manifest.php"; if (isset($manifest['icon']) && $manifest['icon'] != "") { $icon_location = extractFile($tempFile, $manifest['icon'], $base_tmp_upgrade_dir); $path_parts = pathinfo($icon_location); copy($icon_location, remove_file_extension($target_path) . "-icon." . $path_parts['extension']); } // move file from cache/upload to cache/upload/langpack if (copy($tempFile, $target_path)) { copy($manifest_file, $target_manifest); unlink($tempFile); // remove tempFile return "The file {$base_filename} has been uploaded.<br>\n"; } else { unlinkTempFiles($manifest_file, $tempFile); return "There was an error uploading the file, please try again!<br>\n"; } } else { die("The zip file is missing a manifest.php file. Cannot proceed."); } unlinkTempFiles($manifest_file, ''); }
function getDiffFiles($unzip_dir, $install_file, $is_install = true, $previous_version = '') { //require_once($unzip_dir . '/manifest.php'); global $installdefs; if (!empty($previous_version)) { //check if the upgrade path exists if (!empty($upgrade_manifest)) { if (!empty($upgrade_manifest['upgrade_paths'])) { if (!empty($upgrade_manifest['upgrade_paths'][$previous_version])) { $installdefs = $upgrade_manifest['upgrade_paths'][$previous_version]; } } //fi } //fi } //fi $modified_files = array(); if (!empty($installdefs['copy'])) { foreach ($installdefs['copy'] as $cp) { $cp['to'] = clean_path(str_replace('<basepath>', $unzip_dir, $cp['to'])); $restore_path = remove_file_extension(urldecode($install_file)) . "-restore/"; $backup_path = clean_path($restore_path . $cp['to']); //check if this file exists in the -restore directory if (file_exists($backup_path)) { //since the file exists, then we want do an md5 of the install version and the file system version $from = $backup_path; $needle = $restore_path; if (!$is_install) { $from = str_replace('<basepath>', $unzip_dir, $cp['from']); $needle = $unzip_dir; } $files_found = md5DirCompare($from . '/', $cp['to'] . '/', array('.svn'), false); if (count($files_found > 0)) { foreach ($files_found as $key => $value) { $modified_files[] = str_replace($needle, '', $key); } } } //fi } //rof } //fi return $modified_files; }
function uninstall_copy() { if (isset($this->installdefs['copy'])) { foreach ($this->installdefs['copy'] as $cp) { $cp['to'] = clean_path(str_replace('<basepath>', $this->base_dir, $cp['to'])); $GLOBALS['log']->debug('Unlink ' . $cp['to']); /* BEGIN - RESTORE POINT - by MR. MILK August 31, 2005 02:22:11 PM */ //rmdir_recursive($cp['to']); $backup_path = clean_path(remove_file_extension(urldecode($_REQUEST['install_file'])) . "-restore/" . $cp['to']); $this->copy_path($backup_path, $cp['to'], $backup_path, true); /* END - RESTORE POINT - by MR. MILK August 31, 2005 02:22:18 PM */ } $backup_path = clean_path(remove_file_extension(urldecode($_REQUEST['install_file'])) . "-restore"); rmdir_recursive($backup_path); } }