Commit 740cbbd2 authored by Nigel McNie's avatar Nigel McNie
Browse files

Add a cronjob that cleans up old exports.

(cherry picked from commit a42825eb8b44a0299ded915136a6c928fff21437)
parent 568ee869
...@@ -5,5 +5,4 @@ See individual plugin directories for TODOs relating to them. This list isn't ...@@ -5,5 +5,4 @@ See individual plugin directories for TODOs relating to them. This list isn't
exhaustive, it's mostly for Nigel's short term planning benefit. exhaustive, it's mostly for Nigel's short term planning benefit.
Admin export UI Admin export UI
Clean up exports sitting around on disk
Split creation of archives from the export() method so it can be implemented in the base class Split creation of archives from the export() method so it can be implemented in the base class
...@@ -86,13 +86,6 @@ abstract class PluginExport extends Plugin { ...@@ -86,13 +86,6 @@ abstract class PluginExport extends Plugin {
*/ */
abstract public function export(); abstract public function export();
/**
* Clean up after yourself - removing any temp files etc
*
* TODO: not used anywhere yet. Cleanup may not need an API method.
*/
abstract public function cleanup();
// MAIN CLASS DEFINITION // MAIN CLASS DEFINITION
/** /**
...@@ -254,7 +247,7 @@ abstract class PluginExport extends Plugin { ...@@ -254,7 +247,7 @@ abstract class PluginExport extends Plugin {
// Now set up the temporary export directories // Now set up the temporary export directories
$this->exportdir = get_config('dataroot') $this->exportdir = get_config('dataroot')
. 'export/temporary/' . 'export/'
. $this->user->get('id') . '/' . $this->user->get('id') . '/'
. $this->exporttime . '/'; . $this->exporttime . '/';
if (!check_dir_exists($this->exportdir)) { if (!check_dir_exists($this->exportdir)) {
...@@ -342,4 +335,32 @@ abstract class PluginExport extends Plugin { ...@@ -342,4 +335,32 @@ abstract class PluginExport extends Plugin {
} }
} }
/**
* Looks in the export staging area in dataroot and deletes old, unneeded
* exports.
*/
function export_cleanup_old_exports() {
require_once('file.php');
$basedir = get_config('dataroot') . 'export/';
$exportdir = new DirectoryIterator($basedir);
$mintime = time() - (12 * 60 * 60); // delete exports older than 12 hours
// The export dir contains one directory for each user who has created
// an export, named after their UID
foreach ($exportdir as $userdir) {
if ($userdir->isDot()) continue;
// Each user's directory contains one directory for each export
// they made, named as the unix timestamp of the time they
// generated it
$udir = new DirectoryIterator($basedir . $userdir->getFilename());
foreach ($udir as $dir) {
if ($dir->isDot()) continue;
if ($dir->getCTime() < $mintime) {
rmdirr($basedir . $userdir->getFilename() . '/' . $dir->getFilename());
}
}
}
}
?> ?>
...@@ -50,6 +50,7 @@ define('MAXRUNAGE', 300); ...@@ -50,6 +50,7 @@ define('MAXRUNAGE', 300);
require(dirname(dirname(__FILE__)).'/init.php'); require(dirname(dirname(__FILE__)).'/init.php');
require_once(get_config('docroot') . 'artefact/lib.php'); require_once(get_config('docroot') . 'artefact/lib.php');
require_once(get_config('docroot') . 'import/lib.php'); require_once(get_config('docroot') . 'import/lib.php');
require_once(get_config('docroot') . 'export/lib.php');
require_once(get_config('docroot') . 'lib/activity.php'); require_once(get_config('docroot') . 'lib/activity.php');
// This is here for debugging purposes, it allows us to fake the time to test // This is here for debugging purposes, it allows us to fake the time to test
......
...@@ -704,6 +704,7 @@ function core_install_firstcoredata_defaults() { ...@@ -704,6 +704,7 @@ function core_install_firstcoredata_defaults() {
'recalculate_quota' => array('15', '2', '*', '*', '*'), 'recalculate_quota' => array('15', '2', '*', '*', '*'),
'import_process_queue' => array('*/5', '*', '*', '*', '*'), 'import_process_queue' => array('*/5', '*', '*', '*', '*'),
'cron_send_registration_data' => array(rand(0, 59), rand(0, 23), '*', '*', rand(0, 6)), 'cron_send_registration_data' => array(rand(0, 59), rand(0, 23), '*', '*', rand(0, 6)),
'export_cleanup_old_exports' => array('0', '3,13', '*', '*', '*'),
); );
foreach ($cronjobs as $callfunction => $times) { foreach ($cronjobs as $callfunction => $times) {
$cron = new StdClass; $cron = new StdClass;
......
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