Commit 99e16250 authored by Alastair Pharo's avatar Alastair Pharo Committed by Alastair Pharo
Browse files

Added cron job for blog files that are pending, and a new table

parent aa190baf
......@@ -49,5 +49,25 @@
<KEY NAME="filefk" TYPE="foreign" FIELDS="file" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
<!-- This table keeps track of files that are to be associated with a blog
post, but for which the post has not yet been created, or the association
has not yet been confirmed. No file should ever be in both this table and
artefact_blog_blogpost_file.
This table only keeps track of files that are specifically uploaded for a
blog post, not ones that have been uploaded already some other way, that
the user wants to associate with a blog post. -->
<TABLE NAME="artefact_blog_blogpost_file_pending">
<FIELDS>
<FIELD NAME="file" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="when" TYPE="datetime" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="blogpost_file_pending_pk" TYPE="primary" FIELDS="file" />
<KEY NAME="filefk" TYPE="foreign" FIELDS="file" REFTABLE="artefact" REFFIELDS="id" />
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
......@@ -31,13 +31,25 @@ function xmldb_artefact_blog_upgrade($oldversion=0) {
$status = true;
// There was no database prior to this version.
if ($oldversion < 2006120501) {
if ($status && $oldversion < 2006120501) {
$status = $status && install_from_xmldb_file(
get_config('docroot') .
'artefact/blog/db/install.xml'
);
}
if ($status && $oldversion < 2006121501) {
$table = new XMLDBTable('artefact_blog_blogpost_file_pending');
$table->addFieldInfo('file', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL);
$table->addFieldInfo('when', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
$table->addKeyInfo('blogpost_file_pending_pk', XMLDB_KEY_PRIMARY, array('file'));
$table->addKeyInfo('filefk', XMLDB_KEY_FOREIGN, array('file'), 'artefact', array('id'));
$status = $status && create_table($table);
}
return $status;
}
......
......@@ -31,6 +31,11 @@ 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',
......@@ -54,6 +59,34 @@ class PluginArtefactBlog extends PluginArtefact {
public static function get_toplevel_artefact_types() {
return array('blog');
}
public static function get_cron() {
return array(
(object)array(
'callfunction' => 'clean_post_files',
'minute' => '1'
)
);
}
/**
* This function cleans out any files that have been uploaded, but which
* 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 artefact_blog_blogpost_file_pending
WHERE when + ?::INTERVAL < CURRENT_TIMESTAMP", array(self::maxpending)))
|| ($files = array());
foreach ($files as $file) {
$file_obj = new ArtefactTypeFile($file->file);
$file_obj->delete();
}
}
}
/**
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2006120501;
$config->version = 2006121501;
$config->release = '0.1';
?>
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