You are here

function subscriptions_cron in Subscriptions 5

Implementation of cron job.

File

./subscriptions.module, line 713

Code

function subscriptions_cron() {
  if (variable_get('subscriptions_usecron', 0)) {

    // get all currently held node updates
    $result = db_query('SELECT * FROM {subscriptions_holding}');
    while ($row = db_fetch_object($result)) {
      $proceed = TRUE;
      if (variable_get('subscriptions_testpost', 0)) {
        $proceed = subscriptions_testpost($row->content, $row->ptype);
      }
      if ($proceed) {

        // do send
        if ($row->ptype == 'comment') {
          $content = unserialize($row->content);

          // we check the comment status and don't send or delete it
          // if it hasn't been approved
          $comment = db_fetch_array(db_query("SELECT * FROM comments WHERE cid = %d", $content['cid']));
          if ($comment['status'] != 1) {
            subscriptions_heldcomments($content, $row->pid);

            // delete processed row
            db_query('DELETE FROM {subscriptions_holding} WHERE rid = %d', $row->rid);
          }
        }

        // row type == 'comment'
        if ($row->ptype == 'node') {
          subscriptions_heldnodes($row->content, $row->pid);

          // delete processed row
          db_query('DELETE FROM {subscriptions_holding} WHERE rid = %d', $row->rid);
        }

        // row type == 'node'
      }
      else {

        // do delete
        db_query('DELETE FROM {subscriptions_holding} WHERE rid = %d', $row->rid);
      }
    }

    // for each row in results set
  }

  // if using cron to send notifications
}