diff --git a/views_natural_sort.module b/views_natural_sort.module index 1c8128c94ad8ce10eafb71cedc03bf868d08c675..ec80446d3c004af2b4f1d28d37277903b5295209 100644 --- a/views_natural_sort.module +++ b/views_natural_sort.module @@ -84,11 +84,21 @@ function views_natural_sort_node_update($node) { _views_natural_sort_store_node($node); } +/** + * Implementation of hook_node_delete(). + * + * This keep sour natural sort index clean. + */ +function views_natural_sort_node_delete($node) { + _views_natural_sort_remove_node($node); +} + /** * Helper function for writing node data to our sort index. * * @param $node * A drupal node object containing at least a nid and title. + * * @return int * MergeQuery::STATUS_UPDATE or MergeQuery::STATUS_INSERT */ @@ -106,6 +116,21 @@ function _views_natural_sort_store_node($node) { ->execute(); } +/** + * Helper function for removing node data from our sort index. + * + * @param $node + * A drupal node object containing at least a nid. + * + * @return int + * The number of rows deleted. + */ +function _views_natural_sort_remove_node($node) { + return db_delete('views_natural_sort') + ->condition('nid', $node->nid) + ->execute(); +} + /** * Encodes a string into an ascii-sortable such: * - Leading articles in common languages are ingored: The A An El La Le Il