| 1 |
<?php
|
| 2 |
// $Id: ed_classified_delete.inc,v 1.2 2009/09/03 02:58:11 milesgillham Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Node deletion facilities.
|
| 6 |
* Michael Curry, Exodus Development, Inc.
|
| 7 |
* exodusdev@gmail.com
|
| 8 |
* for more information, please visit http://exodusdev.com
|
| 9 |
* Copyright (c) 2006, 2007 Exodus Development, Inc. All Rights Reserved.
|
| 10 |
* Licensed under the terms of the GNU Public License (GPL) version 2. Please see LICENSE.txt for
|
| 11 |
* license terms. Posession and use of this code signifies acceptance of license
|
| 12 |
* terms.
|
| 13 |
*/
|
| 14 |
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Unpublish a node
|
| 18 |
* (Partially) lifted from spam module (jeremy [at] kerneltrap.org)
|
| 19 |
*/
|
| 20 |
|
| 21 |
function _ed_classified_unpublish_ad($nid) {
|
| 22 |
$result = db_query('UPDATE {node} SET status = 0 WHERE nid = %d', $nid);
|
| 23 |
if (_ed_classified_variable_get('log_unpublish', FALSE)) {
|
| 24 |
_edi_wd(t('Unpublished ad nid=%nid', array('%nid' => $nid)), WATCHDOG_NOTICE, l(t('View ad'), "node/$nid"));
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* User entry point to purge old, expired classified ads
|
| 30 |
*/
|
| 31 |
|
| 32 |
function _ed_classified_user_purge() {
|
| 33 |
global $user;
|
| 34 |
$purge_endtime = _ed_classified_purge();
|
| 35 |
drupal_set_message('Purged ads that expired before '. format_date($purge_endtime));
|
| 36 |
return ed_classified_admin_overview($user->uid);
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Purge old, expired classified ads
|
| 41 |
*/
|
| 42 |
|
| 43 |
function _ed_classified_purge() {
|
| 44 |
/*
|
| 45 |
* Purge ads that have expired anytime between the start of time, and nn days ago
|
| 46 |
* TODO: make this a manual process available under the admin/ed_classified menu, with confirmation
|
| 47 |
*/
|
| 48 |
$purge_starttime=0; // is there a better way to do this?
|
| 49 |
$purge_endtime=REQUEST_TIME - _ed_classified_days_to_seconds(_ed_classified_variable_get('ad_expired_purge_age', EDI_CLASSIFIED_VAR_DEF_PURGE_AGE));
|
| 50 |
_ed_classified_purge_ads($purge_starttime, $purge_endtime);
|
| 51 |
// report # of ads purged?
|
| 52 |
// echo 'Purged ads that expired before '.format_date($purge_endtime);
|
| 53 |
return $purge_endtime;
|
| 54 |
}
|
| 55 |
|
| 56 |
|
| 57 |
/**
|
| 58 |
* purge old ads (must have been expired - IOW, unpublished - first.)
|
| 59 |
*/
|
| 60 |
|
| 61 |
function _ed_classified_purge_ads($time_start, $time_end) {
|
| 62 |
$query = _ed_classified_get_aged_ads($time_start, $time_end, 0); // get unpublished ads whose time has come
|
| 63 |
$count = 0;
|
| 64 |
while ($node = db_fetch_object($query)) {
|
| 65 |
_ed_classified_purge_ad($node);
|
| 66 |
$count++;
|
| 67 |
}
|
| 68 |
if ($count>0) {
|
| 69 |
_edi_wd(sprintf(t('Purged %d ads expired between %s and %s'), $count, _edi_safe_date_fmt($time_start), _edi_safe_date_fmt($time_end)));
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
/**
|
| 74 |
* "purge" an expired ad
|
| 75 |
* (This will delete a classified ad that has been 'expired' and is older than the threshold)
|
| 76 |
*/
|
| 77 |
function _ed_classified_purge_ad($node) {
|
| 78 |
if (_ed_classified_variable_get('log_deletions', FALSE)) {
|
| 79 |
$expired = _ed_classified_get_ending_date_string($node->expires_on);
|
| 80 |
_edi_wd(t('Purging ad @title (nid=!nid) which @expired', array('@title' => $node->title, '!nid' => $node->nid, '@expired' => $expired)));
|
| 81 |
}
|
| 82 |
_ed_classified_delete($node->nid);
|
| 83 |
}
|
| 84 |
|
| 85 |
|
| 86 |
/**
|
| 87 |
* Reimplement the node_delete code, because the code in node_delete
|
| 88 |
* performs an access check for node deletion rights
|
| 89 |
* This can be made more efficient, if needed.
|
| 90 |
*/
|
| 91 |
|
| 92 |
function _ed_classified_delete($nid) {
|
| 93 |
$node = node_load($nid);
|
| 94 |
// sanity check: only delete if:
|
| 95 |
// Node found, nid != 0, node is unpublished (stats == 0) and it is truly a classified ad.
|
| 96 |
if ($node && $node->nid != 0 && 0 == $node->status && _ed_classified_node_is_classified($node)) {
|
| 97 |
db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
|
| 98 |
db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
|
| 99 |
|
| 100 |
// Call the node-specific callback (if any):
|
| 101 |
node_invoke($node, 'delete');
|
| 102 |
node_invoke_nodeapi($node, 'delete');
|
| 103 |
|
| 104 |
// Remove this node from the search index if needed.
|
| 105 |
if (function_exists('search_wipe')) {
|
| 106 |
search_wipe($node->nid, 'node');
|
| 107 |
}
|
| 108 |
}
|
| 109 |
}
|