Commit 10949ff7 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Blog file cleanup

parent 6e30f218
......@@ -31,11 +31,6 @@ defined('INTERNAL') || die();
*/
class PluginArtefactBlog extends PluginArtefact {
/**
* This is a postgresql time constant.
*/
const maxpending = '10 minutes';
public static function get_artefact_types() {
return array(
'blog',
......@@ -64,7 +59,8 @@ class PluginArtefactBlog extends PluginArtefact {
return array(
(object)array(
'callfunction' => 'clean_post_files',
'minute' => '1'
'hour' => '4',
'minute' => '40'
)
);
}
......@@ -74,18 +70,36 @@ class PluginArtefactBlog extends PluginArtefact {
* are not associated with a blog, because of an aborted blog creation.
*/
public static function clean_post_files() {
safe_require('artefact', 'file');
($files = get_records_sql_array("
SELECT file
FROM " . get_config('dbprefix') . "artefact_blog_blogpost_file_pending
WHERE when + ?::INTERVAL < CURRENT_TIMESTAMP", array(self::maxpending)))
|| ($files = array());
$bloguploadbase = get_config('dataroot') . ArtefactTypeBlogPost::$blogattachmentroot;
if (!$basedir = opendir($bloguploadbase)) {
throw new Exception('Unable to read blog upload directory '.$bloguploadbase);
}
foreach ($files as $file) {
$file_obj = new ArtefactTypeFile($file->file);
$file_obj->delete();
$currenttime = time();
// Read through all the upload session directories
while (false !== ($sessionupload = readdir($basedir))) {
if ($sessionupload != "." && $sessionupload != "..") {
$sessionupload = $bloguploadbase . $sessionupload;
$subdir = opendir($sessionupload);
// Remove all files older than the session timeout plus two hours.
while (false !== ($uploadfile = readdir($subdir))) {
if ($uploadfile != "." && $uploadfile != "..") {
$uploadfile = $sessionupload . '/' . $uploadfile;
if ($currenttime - filemtime($uploadfile) > get_config('session_timeout') + 7200) {
unlink($uploadfile);
}
}
}
closedir($subdir);
rmdir($sessionupload);
}
}
closedir($basedir);
}
}
......
Supports Markdown
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