Commit 74cf718a by Scott

Delete expired cache button

parent 5af87666
......@@ -160,8 +160,7 @@ class Q2A_Storage_FileCacheDriver
if (is_readable($file)) {
$fp = fopen($file, 'r');
$key = fgets($fp);
$expiry = fgets($fp);
// fclose($fp);
$expiry = (int) trim(fgets($fp));
if (is_numeric($expiry) && time() > $expiry) {
$wasDeleted = $this->deleteFile($file);
}
......
......@@ -33,7 +33,7 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
$state = qa_post_text('state');
$stoptime = time() + 3;
while (qa_recalc_perform_step($state) && (time() < $stoptime))
while (qa_recalc_perform_step($state) && time() < $stoptime)
;
$message = qa_recalc_get_message($state);
......
......@@ -523,23 +523,23 @@ function qa_recalc_perform_step(&$state)
qa_recalc_transition($state, 'doblobstodb_complete');
break;
case 'docachetrim':
qa_recalc_transition($state, 'docachetrim_process');
break;
case 'docacheclear':
qa_recalc_transition($state, 'docacheclear_process');
break;
case 'docachetrim_process':
case 'docacheclear_process':
$cacheDriver = Q2A_Storage_CacheFactory::getCacheDriver();
$cacheStats = $cacheDriver->getStats();
$limit = min($cacheStats['files'], 20);
if ($next > $length) {
qa_recalc_transition($state, 'docacheclear_error');
break;
}
if ($cacheStats['files'] > 0) {
$deleted = $cacheDriver->clear($limit, $next);
if ($cacheStats['files'] > 0 && $next <= $length) {
$deleted = $cacheDriver->clear($limit, $next, ($operation === 'docachetrim_process'));
$done += $deleted;
$next += $limit - $deleted; // if some files were not deleted, skip them next time
$next += $limit - $deleted; // skip files that weren't deleted on next iteration
$continue = true;
} else {
qa_recalc_transition($state, 'docacheclear_complete');
......@@ -554,7 +554,7 @@ function qa_recalc_perform_step(&$state)
if ($continue)
$state = $operation . "\t" . $length . "\t" . $next . "\t" . $done;
return $continue && ($done < $length);
return $continue && $done < $length;
}
......@@ -784,11 +784,6 @@ function qa_recalc_get_message($state)
$message = qa_recalc_progress_lang('admin/caching_delete_progress', $done, $length);
break;
case 'docacheclear_error':
$message = qa_lang('admin/caching_delete_error');
break;
case 'docachetrim_complete':
case 'docacheclear_complete':
$message = qa_lang('admin/caching_delete_complete');
break;
......
......@@ -56,7 +56,6 @@ return array(
'caching_cleanup' => 'Caching clean-up operations',
'caching_delete_all' => 'Delete entire cache',
'caching_delete_complete' => 'Cache successfully deleted',
'caching_delete_error' => 'There was an error deleting some cache files',
'caching_delete_expired' => 'Delete expired cache',
'caching_delete_progress' => 'Deleted ^1 of ^2 cache files...',
'caching_dir_error' => 'The directory ^ defined as QA_CACHE_DIRECTORY is not writable by the web server.',
......
......@@ -1815,6 +1815,11 @@ switch ($adminsection) {
),
'buttons' => array(
'delete_expired' => array(
'label' => qa_lang_html('admin/caching_delete_expired'),
'tags' => 'name="docachetrim" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/delete_stop')) . ', \'cachetrim_note\');"',
'note' => '<span id="cachetrim_note"></span>',
),
'delete_all' => array(
'label' => qa_lang_html('admin/caching_delete_all'),
'tags' => 'name="docacheclear" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/delete_stop')) . ', \'cacheclear_note\');"',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment