X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FConfig.php;h=9237db624a24b3a65d911b0499f083b50791ccbc;hb=16bd56a4590b6ded39eaa6abaa15e7904e410445;hp=b03664e68a3760dda67c0cbf9823a8deca9616e4;hpb=4c12c9b771bde931077f56685b632bd34504b238;p=civicrm-core.git diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index b03664e68a..9237db624a 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -803,24 +803,36 @@ class CRM_Core_Config extends CRM_Core_Config_Variables { /** * Clear leftover temporary tables. + * + * This is called on upgrade, during tests and site move, from the cron and via clear caches in the UI. + * + * Currently the UI clear caches does not pass a time interval - which may need review as it does risk + * ripping the tables out from underneath a current action. This was considered but + * out-of-scope for CRM-16167 + * + * @param string|bool $timeInterval + * Optional time interval for mysql date function.g '2 day'. This can be used to prevent + * tables created recently from being deleted. */ - public static function clearTempTables() { - // CRM-5645 - $dao = CRM_Core_DAO::executeQuery("SELECT DATABASE();"); + public static function clearTempTables($timeInterval = FALSE) { + + $dao = new CRM_Core_DAO(); $query = " -SELECT TABLE_NAME as tableName -FROM INFORMATION_SCHEMA.TABLES -WHERE TABLE_SCHEMA = %1 -AND - ( TABLE_NAME LIKE 'civicrm_import_job_%' - OR TABLE_NAME LIKE 'civicrm_export_temp%' - OR TABLE_NAME LIKE 'civicrm_task_action_temp%' - OR TABLE_NAME LIKE 'civicrm_report_temp%' - ) -"; - - $params = array(1 => array($dao->database(), 'String')); - $tableDAO = CRM_Core_DAO::executeQuery($query, $params); + SELECT TABLE_NAME as tableName + FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_SCHEMA = %1 + AND ( + TABLE_NAME LIKE 'civicrm_import_job_%' + OR TABLE_NAME LIKE 'civicrm_export_temp%' + OR TABLE_NAME LIKE 'civicrm_task_action_temp%' + OR TABLE_NAME LIKE 'civicrm_report_temp%' + ) + "; + if ($timeInterval) { + $query .= " AND CREATE_TIME < DATE_SUB(NOW(), INTERVAL {$timeInterval})"; + } + + $tableDAO = CRM_Core_DAO::executeQuery($query, array(1 => array($dao->database(), 'String'))); $tables = array(); while ($tableDAO->fetch()) { $tables[] = $tableDAO->tableName; @@ -877,4 +889,17 @@ AND return CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting(array('BackOffice')); } + /** + * Resets the singleton, so that the next call to CRM_Core_Config::singleton() + * reloads completely. + * + * While normally we could call the singleton function with $force = TRUE, + * this function addresses a very specific use-case in the CiviCRM installer, + * where we cannot yet force a reload, but we want to make sure that the next + * call to this object gets a fresh start (ex: to initialize the DAO). + */ + public function free() { + self::$_singleton = NULL; + } + }