Template::UpdateOnChange PHP Method

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
    public static function UpdateOnChange($p_tplOrig, $p_tplNew)
    {
        global $Campsite;
        global $g_ado_db;
        // Remove beginning slashes
        $p_tplOrig = ltrim($p_tplOrig, '/');
        $p_tplNew = ltrim($p_tplNew, '/');
        if (is_file($Campsite['TEMPLATE_DIRECTORY'] . "/" . $p_tplNew)) {
            $sql = "SELECT * FROM Templates WHERE Name = '{$p_tplOrig}'";
            $row = $g_ado_db->GetRow($sql);
            if (!$row) {
                return false;
            }
            $id = $row['Id'];
            $sql = "UPDATE Templates SET Name = '{$p_tplNew}' WHERE Id = '{$id}'";
            $g_ado_db->Execute($sql);
        }
    }

Usage Example

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"), "");
All Usage Examples Of Template::UpdateOnChange