/** * Saves a backup of the given file * * @param unknown_type $filename */ function backup($file) { static $maxbackups = 10; //also creates the folder if it does not exists $existingBackups = SugarBackup::backupList($file); //if we exceed the max backups lets clear out the oldest if (count($existingBackups) > $maxbackups) { SugarBackup::deleteOldestBackup($file, $existingBackups); } return copy($file, 'custom/backup/' . dirname($file) . '/' . basename($file) . '[' . time() . ']'); }
/** * The contents of this file are subject to the SugarCRM Public License Version * 1.1.3 ("License"); You may not use this file except in compliance with the * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * All copies of the Covered Code must include on each user interface screen: * (i) the "Powered by SugarCRM" logo and * (ii) the SugarCRM copyright notice * in the same form as they appear in the distribution. See full license for * requirements. * * The Original Code is: SugarCRM Open Source * The Initial Developer of the Original Code is SugarCRM, Inc. * Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.; * All Rights Reserved. * Contributor(s): ______________________________________. */ $the_module = $_SESSION['studio']['module']; ob_clean(); require_once 'modules/Studio/parsers/StudioParser.php'; $fileDef = StudioParser::getFiles($the_module, $_SESSION['studio']['selectedFileId']); $workingFile = StudioParser::getWorkingFile($fileDef['template_file']); //BACKUP EXISTING FILE require_once 'modules/Studio/SugarBackup.php'; SugarBackup::backup($fileDef['template_file']); copy($workingFile, $fileDef['template_file']); sugar_cleanup(true);
function parseOldestFile($file) { ob_clean(); require_once 'modules/Studio/SugarBackup.php'; $file = str_replace('custom/working/', '', $file); $filebk = SugarBackup::oldestBackup($file); $oldMatches = array(); $oldLabels = array(); // echo $filebk; if ($filebk) { $content = file_get_contents($filebk); $positions = $this->parsePositions($content, true); for ($i = 0; $i < sizeof($positions); $i++) { $position = $positions[$i]; //used for reverse lookups to figure out where the associated slot is $slotLookup[$position[2]][$position[3]] = array('position' => $i, 'value' => $position[4]); $names = $this->parseNames($position[4]); $labels = $this->parseLabels($position[4]); foreach ($names as $name) { $oldMatches[$name[1]] = $position[0]; } foreach ($labels as $label) { $oldLabels[$label[0]] = $position[2]; } } } foreach ($oldLabels as $key => $value) { $oldLabels[$key] = $slotLookup[$value]['b']['value']; } $this->oldLabels = $oldLabels; $this->oldMatches = $oldMatches; }