Commit 94a0a91c authored by Steven Jones's avatar Steven Jones

Issue #1185690 by Steven Jones: Fixed hosting_task_log() entries are not deleted when task is.

parent a2469cc5
......@@ -111,6 +111,8 @@ function hosting_task_schema() {
),
'indexes' => array(
'type' => array('type'),
'vid_lid' => array('vid', 'lid'),
'nid' => array('nid'),
),
'primary key' => array('lid'),
);
......@@ -253,16 +255,23 @@ function hosting_task_update_6005() {
function hosting_task_update_6006() {
$ret = array();
// Add nid field
// Add nid field.
$field = array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
db_add_field($ret, 'hosting_task_log', 'nid', $field);
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
// Add some useful indexes.
$indexes = array(
'indexes' => array(
'vid_lid' => array('vid', 'lid'),
'nid' => array('nid'),
),
);
db_add_field($ret, 'hosting_task_log', 'nid', $field, $indexes);
// Populate nid field
// Populate nid field.
$query = "SELECT nid, vid FROM {hosting_task}";
$result = db_query($query);
while ($task = db_fetch_object($result)) {
......@@ -270,13 +279,9 @@ function hosting_task_update_6006() {
db_query($query, $task->nid, $task->vid);
}
// Remove orphaned logs
$query = "SELECT DISTINCT h.vid FROM {hosting_task_log} h LEFT OUTER JOIN {node_revisions} n ON h.vid = n.vid WHERE n.vid IS NULL";
$result = db_query($query);
while ($revision = db_fetch_object($result)) {
$query = "DELETE FROM {hosting_task_log} WHERE vid = %d";
db_query($query, $revision->vid);
}
// Remove orphaned logs, which will have nid == 0 now.
$query = "DELETE FROM {hosting_task_log} WHERE nid = %d";
db_query($query, 0);
return $ret;
}
......@@ -292,11 +292,31 @@ function hosting_task_hosting_queues() {
}
/**
* Insert an entry in the task log
* Insert an entry in the task log.
*
* @param $vid
* The vid of the task to add an entry for.
* @param $type
* The type of log entry being added.
* @param $message
* The message for this log entry.
* @param $error
* (optional) The error code associated to this log entry.
* @param $timestamp
* (optional) The UNIX timestamp of this log message, this defaults to the
* current time.
*/
function hosting_task_log($vid, $type, $message, $error = '', $timestamp = null ) {
$timestamp = ($timestamp) ? $timestamp : mktime();
db_query("INSERT INTO {hosting_task_log} (vid, type, message, error, timestamp) VALUES (%d, '%s', '%s', '%s', %d)", $vid, $type, $message, $error, $timestamp);
function hosting_task_log($vid, $type, $message, $error = '', $timestamp = NULL) {
// We keep track of nids we've looked up in this request, for faster lookups.
static $nids = array();
$timestamp = ($timestamp) ? $timestamp : time();
// We need to insert the nid in addition to the vid, so look it up.
if (!isset($nids[$vid])) {
$nids[$vid] = (int)db_result(db_query('SELECT nid FROM {hosting_task} WHERE vid = %d', $vid));
}
db_query("INSERT INTO {hosting_task_log} (vid, nid, type, message, error, timestamp) VALUES (%d, %d, '%s', '%s', '%s', %d)", $vid, $nids[$vid], $type, $message, $error, $timestamp);
}
/**
......@@ -738,7 +758,7 @@ function hosting_task_view($node, $teaser = FALSE, $page = FALSE) {
* Display table containing the logged information for this task
*/
function _hosting_task_log_table($vid) {
$result = db_query("SELECT * FROM {hosting_task_log} WHERE vid=%d", $vid);
$result = db_query("SELECT * FROM {hosting_task_log} WHERE vid = %d ORDER BY lid", $vid);
if ($result) {
$header = array('data' => 'Log message');
while ($entry = db_fetch_object($result)) {
......
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