UpdateOnChange() public static method

It is called before any UpdateStatus() when renaming/moving a template to avoid a new Id is set for the changed template.
public static UpdateOnChange ( string $p_tplOrig, string $p_tplNew ) : mixed
$p_tplOrig string The original template Name
$p_tplNew string The new template Name
return mixed
Example #1
0
			foreach ($templates as $template) {
				if ($template->move($f_current_folder, $f_destination_folder)) {
					$searchKey = $template->getName();
					$replacementKey = ltrim($f_destination_folder
							. '/' . basename($template->getName()), '/');
					if ($template->getType() != $nonTplTypeId) {
						$searchKey = ' ' . $searchKey;
						$replacementKey = ' ' . $replacementKey;
					}
					$replaceObj = new FileTextSearch();
					$replaceObj->setExtensions(array('tpl','css'));
					$replaceObj->setSearchKey($searchKey);
					$replaceObj->setReplacementKey($replacementKey);
					$replaceObj->findReplace($Campsite['TEMPLATE_DIRECTORY']);
					Template::UpdateOnChange($template->getName(),
								 $f_destination_folder
								 . '/'
								 . basename($template->getName()));
				}
			}
			// Clear compiled templates
			require_once($GLOBALS['g_campsiteDir']."/template_engine/classes/CampTemplate.php");
			CampTemplate::singleton()->clear_compiled_tpl();

			camp_html_add_msg(getGS("Template(s) moved."), "ok");
			camp_html_goto_page($url);
		}
	}
} // END perform the action

$crumbs = array();
$crumbs[] = array(getGS("Configure"), "");
Example #2
0
		$f_new_name .= ".";
	}
	$f_new_name .= $origExtension;
}

$newTemplName = $Campsite['TEMPLATE_DIRECTORY'].'/'.urldecode($f_path)."/$f_new_name";
$exists = file_exists($newTemplName);
if (!$exists) {
	$tpl1_name = urldecode($f_path)."/$f_orig_name";
	$tpl1 = $Campsite['TEMPLATE_DIRECTORY'].'/'.$tpl1_name;
	$tpl2_name = urldecode($f_path)."/$f_new_name";
	$tpl2 = $Campsite['TEMPLATE_DIRECTORY'].'/'.$tpl2_name;
	if (rename($tpl1, $tpl2)) {
	        $relativeOldFilePath = ltrim($tpl1_name, '/');
		$relativeNewFilePath = ltrim($tpl2_name, '/');
		Template::UpdateOnChange($tpl1_name, $tpl2_name);
		// Clear compiled template
		require_once($GLOBALS['g_campsiteDir']."/template_engine/classes/CampTemplate.php");
		CampTemplate::singleton()->clear_compiled_tpl($relativeOldFilePath);
		$logtext = getGS('Template object $1 was renamed to $2', $tpl1_name, $tpl2_name);
		Log::Message($logtext, $g_user->getUserId(), 116);

		// Replace template name in other template files
		$replaceObj = new FileTextSearch();
		$replaceObj->setExtensions(array('tpl','css'));
		$replaceObj->setSearchKey($relativeOldFilePath);
		$replaceObj->setReplacementKey($relativeNewFilePath);
		$replaceObj->findReplace($Campsite['TEMPLATE_DIRECTORY']);
		if ($origExtension == 'tpl') {
			$tpl1_name = ' ' . $relativeOldFilePath;
			$tpl2_name = ' ' . $relativeNewFilePath;