From: Roland Häder Date: Mon, 7 Feb 2011 00:26:20 +0000 (+0000) Subject: Hourly reset introduced X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1c2d077de1940e35b00ad895e75039949c979cae;p=mailer.git Hourly reset introduced --- diff --git a/.gitattributes b/.gitattributes index 73a840f443..01a58d6ce4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -225,6 +225,8 @@ inc/gen_refback.php -text svneol=unset#text/plain inc/gen_sql_patches.php -text svneol=unset#text/plain inc/handler.php -text svneol=unset#text/plain inc/header.php -text svneol=unset#text/plain +inc/hourly/.htaccess svneol=native#text/plain +inc/hourly/hourly_ -text inc/img/.htaccess -text svneol=unset#text/plain inc/inc-functions.php svneol=native#text/plain inc/install-functions.php -text svneol=unset#text/plain diff --git a/inc/extensions/ext-sql_patches.php b/inc/extensions/ext-sql_patches.php index 6c292f952e..16a1380147 100644 --- a/inc/extensions/ext-sql_patches.php +++ b/inc/extensions/ext-sql_patches.php @@ -41,10 +41,10 @@ if (!defined('__SECURITY')) { } // END - if // Version number -setThisExtensionVersion('0.7.4'); +setThisExtensionVersion('0.7.5'); // Version history array (add more with , '0.1.0' and so on) -setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9', '0.4.0', '0.4.1', '0.4.2', '0.4.3', '0.4.4', '0.4.5', '0.4.6', '0.4.7', '0.4.8', '0.4.9', '0.5.0', '0.5.1', '0.5.2', '0.5.3', '0.5.4', '0.5.5', '0.5.6', '0.5.7', '0.5.8', '0.5.9', '0.6.0', '0.6.1', '0.6.2', '0.6.3', '0.6.4', '0.6.4', '0.6.5', '0.6.6', '0.6.7', '0.6.8', '0.6.9', '0.7.0', '0.7.1', '0.7.2', '0.7.3', '0.7.4')); +setExtensionVersionHistory(array('0.0', '0.0.1', '0.0.2', '0.0.3', '0.0.4', '0.0.5', '0.0.6', '0.0.7', '0.0.8', '0.0.9', '0.1.0', '0.1.1', '0.1.2', '0.1.3', '0.1.4', '0.1.5', '0.1.6', '0.1.7', '0.1.8', '0.1.9', '0.2.0', '0.2.1', '0.2.2', '0.2.3', '0.2.4', '0.2.5', '0.2.6', '0.2.7', '0.2.8', '0.2.9', '0.3.0', '0.3.1', '0.3.2', '0.3.3', '0.3.4', '0.3.5', '0.3.6', '0.3.7', '0.3.8', '0.3.9', '0.4.0', '0.4.1', '0.4.2', '0.4.3', '0.4.4', '0.4.5', '0.4.6', '0.4.7', '0.4.8', '0.4.9', '0.5.0', '0.5.1', '0.5.2', '0.5.3', '0.5.4', '0.5.5', '0.5.6', '0.5.7', '0.5.8', '0.5.9', '0.6.0', '0.6.1', '0.6.2', '0.6.3', '0.6.4', '0.6.4', '0.6.5', '0.6.6', '0.6.7', '0.6.8', '0.6.9', '0.7.0', '0.7.1', '0.7.2', '0.7.3', '0.7.4', '0.7.5')); // Keep this extension always active! setExtensionAlwaysActive('Y'); @@ -761,6 +761,13 @@ INDEX (`ip`) // Update notes (these will be set as task text!) setExtensionUpdateNotes("Spalten in Filtertabelle gekürzt (SQL-Fehler wegen zu grossem Schlüssel)."); break; + + case '0.7.5': // SQL queries for v0.7.5 + addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_config` ADD `last_hour` TINYINT(2) UNSIGNED NOT NULL DEFAULT 00"); + + // Update notes (these will be set as task text!) + setExtensionUpdateNotes("Aktuelle Stunde hinzugefügt (ist nicht konfigurierbar)."); + break; } // END - switch break; diff --git a/inc/filter-functions.php b/inc/filter-functions.php index e2f2b84694..613760b858 100644 --- a/inc/filter-functions.php +++ b/inc/filter-functions.php @@ -105,6 +105,7 @@ ORDER BY registerFilter('init', 'SET_CURRENT_DATE'); registerFilter('init', 'INIT_RANDOM_NUMBER'); registerFilter('init', 'CHECK_REPOSITORY_REVISION'); + registerFilter('init', 'RUN_HOURLY_RESET'); registerFilter('init', 'RUN_DAILY_RESET'); registerFilter('init', 'TRIGGER_SENDING_POOL'); registerFilter('init', 'DETERMINE_USERNAME'); @@ -158,6 +159,9 @@ ORDER BY // Generic extension update filters registerFilter('extension_update', 'UPDATE_EXTENSION_DATA'); + // Do hourly reset stuff, keep this entry first in this chain: + registerFilter('hourly', 'RUN_HOURLY_INCLUDES'); + // Do reset stuff, keep this entry first in this chain: registerFilter('reset', 'RUN_RESET_INCLUDES'); diff --git a/inc/filters.php b/inc/filters.php index 9a42401776..5de86582f3 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -558,6 +558,26 @@ function FILTER_UPDATE_EXTENSION_DATA ($ext_name) { unset($GLOBALS['update_ver'][$ext_name]); } +// Load more hourly reset scripts +function FILTER_RUN_HOURLY_INCLUDES () { + // Is the reset set or old sql_patches? + if (((!isHourlyResetEnabled()) || (!isExtensionInstalledAndNewer('sql_patches', '0.7.5'))) && (isHtmlOutputMode())) { + // Then abort here + debug_report_bug(__FUNCTION__, __LINE__, 'Cannot run reset! enabled='.intval(isHourlyResetEnabled()).',ext_newer[sql_patches:0.7.5]='.intval(isExtensionInstalledAndNewer('sql_patches', '0.7.5')).' Please report this bug. Thanks'); + } // END - if + + // Get more hourly reset scripts + setIncludePool('hourly', getArrayFromDirectory('inc/hourly/', 'hourly_')); + + // Update database + if ((!isConfigEntrySet('DEBUG_RESET')) || (!isDebugResetEnabled())) { + updateConfiguration('last_hour', getHour()); + } // END - if + + // Run the filter + runFilterChain('load_includes', 'hourly'); +} + // Load more reset scripts function FILTER_RUN_RESET_INCLUDES () { // Is the reset set or old sql_patches? @@ -570,7 +590,9 @@ function FILTER_RUN_RESET_INCLUDES () { setIncludePool('reset', getArrayFromDirectory('inc/daily/', 'daily_')); // Update database - if ((!isConfigEntrySet('DEBUG_RESET')) || (getConfig('DEBUG_RESET') != 'Y')) updateConfiguration('last_update', 'UNIX_TIMESTAMP()'); + if ((!isConfigEntrySet('DEBUG_RESET')) || (!isDebugResetEnabled())) { + updateConfiguration('last_update', 'UNIX_TIMESTAMP()'); + } // END - if // Is the config entry set? if (isExtensionInstalledAndNewer('sql_patches', '0.4.2')) { @@ -736,15 +758,31 @@ function FILTER_CHECK_REPOSITORY_REVISION () { // Filter for running daily reset function FILTER_RUN_DAILY_RESET () { // Only execute this filter if installed - if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalled('sql_patches'))) return; + if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalled('sql_patches'))) { + return; + } // END - if // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D - if (((getDay(getConfig('last_update')) != getDay()) || ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y'))) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestParameterSet('register')) && (!isCssOutputMode())) { + if (((getDay(getConfig('last_update')) != getDay()) || (isDebugResetEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestParameterSet('register')) && (!isCssOutputMode())) { // Tell every module we are in reset-mode! doReset(); } // END - if } +// Filter for running hourly reset +function FILTER_RUN_HOURLY_RESET () { + // Only execute this filter if installed + if ((isInstallationPhase()) || (!isInstalled()) || (!isAdminRegistered()) || (!isExtensionInstalledAndNewer('sql_patches', '0.7.5'))) { + return; + } // END - if + + // Shall we run the reset scripts? If a day has changed, maybe also a week/month has changed... Simple! :D + if (((getConfig('last_hour') != getHour()) || (isDebugResetEnabled())) && (!isInstallationPhase()) && (isAdminRegistered()) && (!isGetRequestParameterSet('register')) && (!isCssOutputMode())) { + // Tell every module we are in reset-mode! + doHourly(); + } // END - if +} + // Filter for loading more runtime includes (not for installation) function FILTER_LOAD_RUNTIME_INCLUDES () { // Load more includes diff --git a/inc/functions.php b/inc/functions.php index e07307acb5..1c748c4455 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2005,6 +2005,15 @@ function doReset () { runFilterChain('reset'); } +// Enables the reset mode (hourly, weekly and monthly) and runs it +function doHourly () { + // Enable the hourly reset mode + $GLOBALS['hourly_enabled'] = true; + + // Run filters (one always!) + runFilterChain('hourly'); +} + // Our shutdown-function function shutdown () { // Call the filter chain 'shutdown' diff --git a/inc/hourly/.htaccess b/inc/hourly/.htaccess new file mode 100644 index 0000000000..3a42882788 --- /dev/null +++ b/inc/hourly/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/hourly/hourly_ b/inc/hourly/hourly_ new file mode 100644 index 0000000000..f46c742f5e --- /dev/null +++ b/inc/hourly/hourly_ @@ -0,0 +1,58 @@ + diff --git a/inc/monthly/monthly_ b/inc/monthly/monthly_ index a89ba3155a..e2ba61f33a 100644 --- a/inc/monthly/monthly_ +++ b/inc/monthly/monthly_ @@ -39,7 +39,7 @@ if (!defined('__SECURITY')) { die(); } elseif ((isCssOutputMode()) || (isResetModeEnabled())) { - // Do not execute when script is in CSS mode or no daily reset + // Do not execute when script is in CSS mode or no hourly reset return; } elseif (!isExtensionActive('')) { logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.'); diff --git a/inc/monthly/monthly_beg.php b/inc/monthly/monthly_beg.php index 43f6a24111..b0478424df 100644 --- a/inc/monthly/monthly_beg.php +++ b/inc/monthly/monthly_beg.php @@ -39,7 +39,7 @@ if (!defined('__SECURITY')) { die(); } elseif ((isCssOutputMode()) || (!isResetModeEnabled())) { - // Do not execute when script is in CSS mode or no daily reset + // Do not execute when script is in CSS mode or no hourly reset return; } elseif ((!isExtensionActive('beg')) || (!isBegRallyeEnabled())) { logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.'); diff --git a/inc/monthly/monthly_bonus.php b/inc/monthly/monthly_bonus.php index df9512b6b3..35d5b1e7d4 100644 --- a/inc/monthly/monthly_bonus.php +++ b/inc/monthly/monthly_bonus.php @@ -39,7 +39,7 @@ if (!defined('__SECURITY')) { die(); } elseif ((isCssOutputMode()) || (!isResetModeEnabled())) { - // Do not execute when script is in CSS mode or no daily reset + // Do not execute when script is in CSS mode or no hourly reset return; } elseif (!isExtensionActive('bonus')) { logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.'); diff --git a/inc/monthly/monthly_newsletter.php b/inc/monthly/monthly_newsletter.php index 556d1dd761..462d6a65bb 100644 --- a/inc/monthly/monthly_newsletter.php +++ b/inc/monthly/monthly_newsletter.php @@ -39,7 +39,7 @@ if (!defined('__SECURITY')) { die(); } elseif ((isCssOutputMode()) || (!isResetModeEnabled())) { - // Do not execute when script is in CSS mode or no daily reset + // Do not execute when script is in CSS mode or no hourly reset return; } elseif (!isExtensionActive('newsletter')) { logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.'); diff --git a/inc/monthly/monthly_surfbar.php b/inc/monthly/monthly_surfbar.php index e84c71c5af..83f98c9516 100644 --- a/inc/monthly/monthly_surfbar.php +++ b/inc/monthly/monthly_surfbar.php @@ -39,7 +39,7 @@ if (!defined('__SECURITY')) { die(); } elseif ((isCssOutputMode()) || (!isResetModeEnabled())) { - // Do not execute when script is in CSS mode or no daily reset + // Do not execute when script is in CSS mode or no hourly reset return; } elseif (!isExtensionActive('surfbar')) { logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension disabled.'); diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index d2ff5ffdd6..eee9e64f0b 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -370,6 +370,12 @@ function isAdminRegistered () { return $GLOBALS[__FUNCTION__]; } +// Checks wether the hourly reset mode is active +function isHourlyResetEnabled () { + // Now simply check it + return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === true)); +} + // Checks wether the reset mode is active function isResetModeEnabled () { // Now simply check it @@ -388,6 +394,18 @@ function isDebugModeEnabled () { return $GLOBALS[__FUNCTION__]; } +// Checks wether the debug reset is enabled +function isDebugResetEnabled () { + // Is cache set? + if (!isset($GLOBALS[__FUNCTION__])) { + // Simply check it + $GLOBALS[__FUNCTION__] = ((isConfigEntrySet('DEBUG_RESET')) && (getConfig('DEBUG_RESET') == 'Y')); + } // END - if + + // Return it + return $GLOBALS[__FUNCTION__]; +} + // Checks wether SQL debugging is enabled function isSqlDebuggingEnabled () { // Is cache set? @@ -1230,12 +1248,31 @@ function getMonth ($timestamp = null) { return $GLOBALS[__FUNCTION__][$timestamp]; } +// Getter for current hour (default) +function getHour ($timestamp = null) { + // Is it cached? + if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { + // null is time() + if (is_null($timestamp)) { + $timestamp = time(); + } // END - if + + // Then create it + $GLOBALS[__FUNCTION__][$timestamp] = date('H', $timestamp); + } // END - if + + // Return cache + return $GLOBALS[__FUNCTION__][$timestamp]; +} + // Getter for current day (default) function getDay ($timestamp = null) { // Is it cached? if (!isset($GLOBALS[__FUNCTION__][$timestamp])) { // null is time() - if (is_null($timestamp)) $timestamp = time(); + if (is_null($timestamp)) { + $timestamp = time(); + } // END - if // Then create it $GLOBALS[__FUNCTION__][$timestamp] = date('d', $timestamp);