(Enhancement for developers) Use a timestamp defined at compile time to workaround client-side caching problems during development.

SVN:trunk[5690]
This commit is contained in:
Denis Flaven
2018-04-18 13:45:08 +00:00
parent d32db977eb
commit 9c3b053727
9 changed files with 41 additions and 24 deletions

View File

@@ -298,7 +298,7 @@ EOF;
if (!$oPage->IsPrintableVersion())
{
$sMenuTitle = Dict::S('UI:ConfigureThisList');
$sHtml = '<div class="itop_popup toolkit_menu" id="tk_'.$this->iListId.'"><ul><li><img src="../images/toolkit_menu.png?itopversion='.ITOP_VERSION.'"><ul>';
$sHtml = '<div class="itop_popup toolkit_menu" id="tk_'.$this->iListId.'"><ul><li><img src="../images/toolkit_menu.png?t='.utils::GetCacheBusterTimestamp().'"><ul>';
$oMenuItem1 = new JSPopupMenuItem('iTop::ConfigureList', $sMenuTitle, "$('#datatable_dlg_".$this->iListId."').dialog('open');");
$aActions = array(

View File

@@ -828,9 +828,9 @@ EOF
// jQuery scripts may face some spurious problems (like failing on a 'reload')
foreach ($this->a_linked_stylesheets as $a_stylesheet) {
if (strpos($a_stylesheet['link'], '?') === false) {
$s_stylesheet = $a_stylesheet['link'] . "?itopversion=" . ITOP_VERSION;
$s_stylesheet = $a_stylesheet['link'] . "?t=".utils::GetCacheBusterTimestamp();
} else {
$s_stylesheet = $a_stylesheet['link'] . "&itopversion=" . ITOP_VERSION;
$s_stylesheet = $a_stylesheet['link'] . "&t=".utils::GetCacheBusterTimestamp();
}
if ($a_stylesheet['condition'] != "") {
$sHtml .= "<!--[if {$a_stylesheet['condition']}]>\n";
@@ -841,7 +841,7 @@ EOF
}
}
// special stylesheet for printing, hides the navigation gadgets
$sHtml .= "<link rel=\"stylesheet\" media=\"print\" type=\"text/css\" href=\"../css/print.css?itopversion=" . ITOP_VERSION . "\" />\n";
$sHtml .= "<link rel=\"stylesheet\" media=\"print\" type=\"text/css\" href=\"../css/print.css?t=".utils::GetCacheBusterTimestamp() . "\" />\n";
if ($this->GetOutputFormat() == 'html') {
$sHtml .= $this->output_dict_entries(true); // before any script so that they can benefit from the translations
@@ -849,9 +849,9 @@ EOF
// Make sure that the URL to the script contains the application's version number
// so that the new script do NOT get reloaded from the cache when the application is upgraded
if (strpos($s_script, '?') === false) {
$s_script .= "?itopversion=" . ITOP_VERSION;
$s_script .= "?t=".utils::GetCacheBusterTimestamp();
} else {
$s_script .= "&itopversion=" . ITOP_VERSION;
$s_script .= "&t=".utils::GetCacheBusterTimestamp();
}
$sHtml .= "<script type=\"text/javascript\" src=\"$s_script\"></script>\n";
}
@@ -907,7 +907,7 @@ EOF
$sHtml .= "</style>\n";
}
$sHtml .= "<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"iTop\" href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/opensearch.xml.php\" />\n";
$sHtml .= "<link rel=\"shortcut icon\" href=\"" . utils::GetAbsoluteUrlAppRoot() . "images/favicon.ico?itopversion=" . ITOP_VERSION . "\" />\n";
$sHtml .= "<link rel=\"shortcut icon\" href=\"" . utils::GetAbsoluteUrlAppRoot() . "images/favicon.ico?t=".utils::GetCacheBusterTimestamp(). "\" />\n";
$sHtml .= "</head>\n";
$sBodyClass = "";
@@ -1049,9 +1049,9 @@ EOF;
$sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help');
//$sLogOffMenu = "<span id=\"logOffBtn\" style=\"height:55px;padding:0;margin:0;\"><img src=\"../images/onOffBtn.png\"></span>";
$sDisplayIcon = utils::GetAbsoluteUrlAppRoot() . 'images/itop-logo.png?itopversion=' . ITOP_VERSION;
$sDisplayIcon = utils::GetAbsoluteUrlAppRoot() . 'images/itop-logo.png?t=' . utils::GetCacheBusterTimestamp();
if (file_exists(MODULESROOT . 'branding/main-logo.png')) {
$sDisplayIcon = utils::GetAbsoluteUrlModulesRoot() . 'branding/main-logo.png?itopversion=' . ITOP_VERSION;
$sDisplayIcon = utils::GetAbsoluteUrlModulesRoot() . 'branding/main-logo.png?t=' . utils::GetCacheBusterTimestamp();
}
$sHtml .= $sNorthPane;
@@ -1077,7 +1077,7 @@ EOF;
$sHtml .= ' </div>';
$sHtml .= ' </div> <!-- /inner menu -->';
$sHtml .= ' </div> <!-- /menu -->';
$sHtml .= ' <div class="footer ui-layout-south"><div id="combodo_logo"><a href="http://www.combodo.com" title="www.combodo.com" target="_blank"><img src="../images/logo-combodo.png?itopversion=' . ITOP_VERSION . '"/></a></div></div>';
$sHtml .= ' <div class="footer ui-layout-south"><div id="combodo_logo"><a href="http://www.combodo.com" title="www.combodo.com" target="_blank"><img src="../images/logo-combodo.png?t=' . utils::GetCacheBusterTimestamp() . '"/></a></div></div>';
$sHtml .= '<!-- End of the left pane -->';
$sHtml .= '</div>';
@@ -1104,7 +1104,7 @@ EOF;
$sHtml .= ' <div id="global-search"><form action="' . utils::GetAbsoluteUrlAppRoot() . 'pages/UI.php">';
$sHtml .= ' <table id="top-left-buttons-area"><tr>';
$sHtml .= ' <td id="top-left-global-search-cell"><div id="global-search-area"><input id="global-search-input" type="text" name="text" placeholder="' . $sText . '"></input><div ' . $sOnClick . ' id="global-search-image"><input type="hidden" name="operation" value="full_text"/></div></div></td>';
$sHtml .= ' <td id="top-left-help-cell"><a id="help-link" href="' . $sOnlineHelpUrl . '" target="_blank"><img title="' . Dict::S('UI:Help') . '" src="../images/help.png?itopversion=' . ITOP_VERSION . '"/></td>';
$sHtml .= ' <td id="top-left-help-cell"><a id="help-link" href="' . $sOnlineHelpUrl . '" target="_blank"><img title="' . Dict::S('UI:Help') . '" src="../images/help.png?t=' . utils::GetCacheBusterTimestamp() . '"/></td>';
$sHtml .= ' <td id="top-left-logoff-cell">' . self::FilterXSS($sLogOffMenu) . '</td>';
$sHtml .= ' </tr></table></form></div>';
$sHtml .= ' </td>';
@@ -1112,7 +1112,7 @@ EOF;
$sHtml .= ' </table>';
// $sHtml .= ' <div id="global-search"><form action="'.utils::GetAbsoluteUrlAppRoot().'pages/UI.php"><table><tr><td></td><td><div id="global-search-area"><input id="global-search-input" type="text" name="text" placeholder="'.$sText.'"></input><div '.$sOnClick.' id="global-search-image"></div></div></td>';
// $sHtml .= '<td><a id="help-link" href="'.$sOnlineHelpUrl.'" target="_blank"><img title="'.Dict::S('UI:Help').'" src="../images/help.png?itopversion='.ITOP_VERSION.'"/></td>';
// $sHtml .= '<td><a id="help-link" href="'.$sOnlineHelpUrl.'" target="_blank"><img title="'.Dict::S('UI:Help').'" src="../images/help.png?t='.utils::GetCacheBusterTimestamp().'"/></td>';
// $sHtml .= '<td>'.self::FilterXSS($sLogOffMenu).'</td><td><input type="hidden" name="operation" value="full_text"/></td></tr></table></form></div>';
// $sHtml .= ' <div id="itop-breadcrumb"></div>';

View File

@@ -98,10 +98,10 @@ class LoginWebPage extends NiceWebPage
}
$sVersionShort = Dict::Format('UI:iTopVersion:Short', ITOP_APPLICATION, ITOP_VERSION);
$sIconUrl = Utils::GetConfig()->Get('app_icon_url');
$sDisplayIcon = utils::GetAbsoluteUrlAppRoot().'images/'.$sLogo.'?itopversion='.ITOP_VERSION;
$sDisplayIcon = utils::GetAbsoluteUrlAppRoot().'images/'.$sLogo.'?t='.utils::GetCacheBusterTimestamp();
if (file_exists(MODULESROOT.'branding/'.$sBrandingLogo))
{
$sDisplayIcon = utils::GetAbsoluteUrlModulesRoot().'branding/'.$sBrandingLogo.'?itopversion='.ITOP_VERSION;
$sDisplayIcon = utils::GetAbsoluteUrlModulesRoot().'branding/'.$sBrandingLogo.'?t='.utils::GetCacheBusterTimestamp();
}
$this->add("<div id=\"login-logo\"><a href=\"".htmlentities($sIconUrl, ENT_QUOTES, 'UTF-8')."\"><img title=\"$sVersionShort\" src=\"$sDisplayIcon\"></a></div>\n");
}

View File

@@ -265,7 +265,7 @@ EOF
// the input for the auto-complete
$sHTMLValue .= "<input class=\"field_autocomplete\" count=\"".$oAllowedValues->Count()."\" type=\"text\" id=\"label_$this->iId\" value=\"$sDisplayValue\"/>";
$sHTMLValue .= "<span class=\"field_input_btn\"><img id=\"mini_search_{$this->iId}\" style=\"border:0;vertical-align:middle;cursor:pointer;\" src=\"../images/mini_search.gif?itopversion=".ITOP_VERSION."\" onClick=\"oACWidget_{$this->iId}.Search();\"/></span>";
$sHTMLValue .= "<span class=\"field_input_btn\"><img id=\"mini_search_{$this->iId}\" style=\"border:0;vertical-align:middle;cursor:pointer;\" src=\"../images/mini_search.gif?t=".utils::GetCacheBusterTimestamp()."\" onClick=\"oACWidget_{$this->iId}.Search();\"/></span>";
// another hidden input to store & pass the object's Id
$sHTMLValue .= "<input type=\"hidden\" id=\"$this->iId\" name=\"{$sAttrFieldPrefix}{$sFieldName}\" value=\"".htmlentities($value, ENT_QUOTES, 'UTF-8')."\" />\n";
@@ -289,7 +289,7 @@ EOF
}
if ($bExtensions && MetaModel::IsHierarchicalClass($this->sTargetClass) !== false)
{
$sHTMLValue .= "<span class=\"field_input_btn\"><img id=\"mini_tree_{$this->iId}\" style=\"border:0;vertical-align:middle;cursor:pointer;\" src=\"../images/mini_tree.gif?itopversion=".ITOP_VERSION."\" onClick=\"oACWidget_{$this->iId}.HKDisplay();\"/></span>";
$sHTMLValue .= "<span class=\"field_input_btn\"><img id=\"mini_tree_{$this->iId}\" style=\"border:0;vertical-align:middle;cursor:pointer;\" src=\"../images/mini_tree.gif?t=".utils::GetCacheBusterTimestamp()."\" onClick=\"oACWidget_{$this->iId}.HKDisplay();\"/></span>";
$oPage->add_ready_script(
<<<EOF
if ($('#ac_tree_{$this->iId}').length == 0)
@@ -303,7 +303,7 @@ EOF
{
$sCallbackName = (MetaModel::IsAbstract($this->sTargetClass)) ? 'SelectObjectClass' : 'CreateObject';
$sHTMLValue .= "<span class=\"field_input_btn\"><img id=\"mini_add_{$this->iId}\" style=\"border:0;vertical-align:middle;cursor:pointer;\" src=\"../images/mini_add.gif?itopversion=".ITOP_VERSION."\" onClick=\"oACWidget_{$this->iId}.{$sCallbackName}();\"/></span>";
$sHTMLValue .= "<span class=\"field_input_btn\"><img id=\"mini_add_{$this->iId}\" style=\"border:0;vertical-align:middle;cursor:pointer;\" src=\"../images/mini_add.gif?t=".utils::GetCacheBusterTimestamp()."\" onClick=\"oACWidget_{$this->iId}.{$sCallbackName}();\"/></span>";
$oPage->add_ready_script(
<<<EOF
if ($('#ajax_{$this->iId}').length == 0)

View File

@@ -1887,4 +1887,19 @@ class utils
}
return $aCleanHeaders;
}
/**
* Return a string based on compilation time or (if not available because the datamodel has not been loaded)
* the version of iTop. This string is useful to prevent browser side caching of content that may vary at each
* (re)installation of iTop (especially during development).
* @return string
*/
public function GetCacheBusterTimestamp()
{
if(!defined('COMPILATION_TIMESTAMP'))
{
return ITOP_VERSION;
}
return COMPILATION_TIMESTAMP;
}
}

View File

@@ -541,11 +541,11 @@ class WebPage implements Page
// so that the new script do NOT get reloaded from the cache when the application is upgraded
if (strpos($s_script, '?') === false)
{
$s_script .= "?itopversion=".ITOP_VERSION;
$s_script .= "?t=".utils::GetCacheBusterTimestamp();
}
else
{
$s_script .= "&itopversion=".ITOP_VERSION;
$s_script .= "&t=".utils::GetCacheBusterTimestamp();
}
echo "<script type=\"text/javascript\" src=\"$s_script\"></script>\n";
}
@@ -562,11 +562,11 @@ class WebPage implements Page
{
if (strpos($a_stylesheet['link'], '?') === false)
{
$s_stylesheet = $a_stylesheet['link']."?itopversion=".ITOP_VERSION;
$s_stylesheet = $a_stylesheet['link']."?t=".utils::GetCacheBusterTimestamp();
}
else
{
$s_stylesheet = $a_stylesheet['link']."&itopversion=".ITOP_VERSION;
$s_stylesheet = $a_stylesheet['link']."&t=".utils::GetCacheBusterTimestamp();
}
if ($a_stylesheet['condition'] != "")
{
@@ -590,7 +590,7 @@ class WebPage implements Page
}
if (class_exists('MetaModel') && MetaModel::GetConfig())
{
echo "<link rel=\"shortcut icon\" href=\"".utils::GetAbsoluteUrlAppRoot()."images/favicon.ico?itopversion=".ITOP_VERSION."\" />\n";
echo "<link rel=\"shortcut icon\" href=\"".utils::GetAbsoluteUrlAppRoot()."images/favicon.ico?t=".utils::GetCacheBusterTimestamp()."\" />\n";
}
echo "</head>\n";
echo "<body>\n";

View File

@@ -1276,7 +1276,7 @@ EOF
$oPage->add('<div style="margin-left: 120px;">');
$oPage->add('<table>');
$oPage->add('<tr>');
$oPage->add('<td><a href="http://www.combodo.com" title="www.combodo.com" target="_blank" style="background: none;"><img src="../images/logo-combodo.png?itopversion='.ITOP_VERSION.'" style="float: right;"/></a></td>');
$oPage->add('<td><a href="http://www.combodo.com" title="www.combodo.com" target="_blank" style="background: none;"><img src="../images/logo-combodo.png?t='.utils::GetCacheBusterTimestamp().'" style="float: right;"/></a></td>');
$oPage->add('<td style="padding-left: 20px;">');
$oPage->add($sVersionString.'<br/>');
$oPage->add(Dict::S('UI:About:DataModel').': '.$sDataModelVersion.'<br/>');

View File

@@ -65,6 +65,8 @@ class MFCompiler
$this->sMainPHPCode .= "/**\n";
$this->sMainPHPCode .= " * This file was automatically generated by the compiler on ".date('Y-m-d H:i:s')." -- DO NOT EDIT\n";
$this->sMainPHPCode .= " */\n";
$this->sMainPHPCode .= "\n";
$this->sMainPHPCode .= "define('COMPILATION_TIMESTAMP', '".microtime(true)."');\n";
$this->aSnippets = array();
$this->aRelations = array();
}

View File

@@ -268,7 +268,7 @@ h3.clickable.open {
public function output()
{
$this->s_content = "<div id=\"header\"><h1><a href=\"http://www.combodo.com/itop\" target=\"_blank\"><img title=\"iTop by Combodo\" src=\"../images/itop-logo.png?itopversion=".ITOP_VERSION."\"></a>&nbsp;".htmlentities($this->s_title, ENT_QUOTES, 'UTF-8')."</h1>\n</div><div id=\"setup\">{$this->s_content}\n</div>\n";
$this->s_content = "<div id=\"header\"><h1><a href=\"http://www.combodo.com/itop\" target=\"_blank\"><img title=\"iTop by Combodo\" src=\"../images/itop-logo.png?t=".utils::GetCacheBusterTimestamp()."\"></a>&nbsp;".htmlentities($this->s_title, ENT_QUOTES, 'UTF-8')."</h1>\n</div><div id=\"setup\">{$this->s_content}\n</div>\n";
return parent::output();
}