Skip to content

Commit

Permalink
Issue #10: Add missing update hook; adjust cron hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
laryn authored Nov 26, 2024
1 parent 787c524 commit 4aa857b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 64 deletions.
61 changes: 0 additions & 61 deletions CHANGELOG.txt

This file was deleted.

35 changes: 35 additions & 0 deletions maillog.install
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,38 @@ function maillog_update_1101() {
cache_clear_all('*', 'cache_views', TRUE);
cache_clear_all('*', 'cache_views_data', TRUE);
}

/**
* Rename the 'idmaillog' field to just 'id'.
*/
function maillog_update_1102() {
if (!db_field_exists('maillog', 'id')) {
// Add the new 'id' field.
$spec = array(
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
'default' => 0,
'description' => "The primary key of this table.",
);
db_add_field('maillog', 'id', $spec);

// Fill in all of the 'id' fields.
db_query("UPDATE {maillog} SET id=idmaillog");

// Drop the 'idmaillog' field.
db_drop_field('maillog', 'idmaillog');

// Change the 'id' field to a serial.
$spec = array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "The primary key of this table.",
);
$keys = array(
'primary key' => array('id'),
);
db_change_field('maillog', 'id', 'id', $spec, $keys);
}
}
6 changes: 3 additions & 3 deletions maillog.module
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@ function maillog_cron() {
// e.g. auto_increment value > 1 or rows deleted directly from the table.
if ($row_limit > 0) {
$min_row = db_select('maillog', 'm')
->fields('m', array('idmaillog'))
->orderBy('idmaillog', 'DESC')
->fields('m', array('id'))
->orderBy('id', 'DESC')
->range($row_limit - 1, 1)
->execute()->fetchField();

// Delete all table entries older than the nth row, if nth row was found.
if ($min_row) {
db_delete('maillog')
->condition('idmaillog', $min_row, '<')
->condition('id', $min_row, '<')
->execute();
}
}
Expand Down

0 comments on commit 4aa857b

Please sign in to comment.