davidarthurs

Topic: Cron Job Newbie (using Hsphere)

I'm hoping to have older posts permanently deleted so as not to bloat the DB. Having read a few other posts would this be the correct way?

1. (server uses Hsphere) http://www.woria.com/cron/addtab/
setup cron tab in Hsphere that points to cron_maintenance.php

Do I keep cron_maintenance.php in tools folder and point to it or does cron_maintenance.php  need to be moved to server root or jobberbase root?

2. cron_maintenance.php should look like this to delete jobs older than 50 days:

<?php
    require_once 'config.php';
    require_once '_includes/class.Maintenance.php';

    $janitor = new Maintenance();
   
    // delete temporary posts older than 1 day
    $janitor->DeleteTemporaryJobs();
    $janitor->DeactivateOldJobs();
?>



and class.Maintenance.php would look like this:



class Maintenance
{
    function __construct()
    { }
   
    // delete temporary posts older than 1 days
    public function DeleteTemporaryJobs()
    {
        global $db;
        $sql = 'DELETE FROM jobs WHERE DATEDIFF(NOW(), created_on) > 0 AND is_temp = 1 AND is_active = 0';
        $db->Execute($sql);
    }
   
      public function DeactivateOldJobs()
    {
        global $db;
        $sql = 'DELETE FROM jobs WHERE DATEDIFF(NOW(), created_on) > 50';
        $db->Execute($sql);
    }

?>

would this be correct?
How do you know if it works? would the cron job email reveal that?

davidarthurs

Re: Cron Job Newbie (using Hsphere)

Any help out there?

hobo

Re: Cron Job Newbie (using Hsphere)

You can see if your cron job works by opening the cron file in your browser:
Visit http://example.com/_tools/cron_maintenance.php (v1.91)

What is your jobberBase version?

davidarthurs

Re: Cron Job Newbie (using Hsphere)

Hi, using have latest version. Currently testing it locally.

Do I keep cron_maintenance.php in tools folder and point to it or does cron_maintenance.php  need to be moved to server root or jobberbase root?

Are the cron_maintenance.php,class.Maintenance.php pages above correct?

hobo

Re: Cron Job Newbie (using Hsphere)

It does not look correct, are you sure the files above are from latest version?

hobo

Re: Cron Job Newbie (using Hsphere)

This is what my _tools/cron_maintenance.php looks like:

Code:

<?php
/**
 * jobber job board platform
 *
 * @author     Filip C.T.E. <http://www.filipcte.ro> <me@filipcte.ro>
 * @license    You are free to edit and use this work, but it would be nice if you always referenced the original author ;)
 *             (see license.txt).
 */

    require_once '../_config/config.php';
    require_once APP_PATH . '_includes/class.Maintenance.php';
  require_once APP_PATH . '_includes/class.Postman.php';

    $janitor = new Maintenance();

    // delete temporary posts older than 2 days
    $janitor->DeleteTemporaryJobs();
    // deactivate jobs older than 30 days + delete jobs older than 60 days.
        $janitor->DeactivateJobs();
    // delete jobs older than 60 days.
        $janitor->DeleteOldJobs();
    // delete applications after 30 days. prevents them showing up on  home page in popular jobs after job expiration.
    $janitor->DeleteOldApps();
?>

And for _includes/class.maintenance.php i have this (adjusted for 50 days):

Code:

<?php
/**
 * jobber job board platform
 *
 * @author     Filip C.T.E. <http://www.filipcte.ro> <me@filipcte.ro>
 * @license    You are free to edit and use this work, but it would be nice if you always referenced the original author ;)
 *             (see license.txt).
 * 
 * Maintenance class handles site/database maintenance operations
 */

class Maintenance
{
    
    function __construct()
    { }
    
    // delete temporary posts older than 2 days
    public function DeleteTemporaryJobs()
    {
        global $db;
        $sql = 'DELETE FROM '.DB_PREFIX.'jobs WHERE created_on < DATE_SUB(NOW(), INTERVAL 1 DAY) AND is_temp = 1 AND is_active = 0';
        $db->Execute($sql);
    }
    public function DeactivateJobs()
          {      

          $postMan = new Postman();

          global $db;

          $notifmin = 47; //the day when you want notification to be sent prior to the ad expiring
          $notifmax = 50; //the day the ad actually expires
          $dayscount = $notifmax - $notifmin;

          $sql = 'SELECT * FROM '.DB_PREFIX.'jobs WHERE DATEDIFF(NOW(), created_on) = '. $notifmin. ' AND is_active = 1';
          $row = $db->QueryArray($sql);
          #print_r($row); // this will print the array of the ad that was deactivated
          foreach ( $row as $rows )
              {
              $ademail = trim(strtolower($rows['poster_email']));
              $adname = trim($rows['title']);
              $adcomp = trim($rows['company']);
              $adurl = BASE_URL . URL_JOB . "/" . $rows['id'] . "/";
              //$postMan->MailExpiringAd($ademail, $adname, $adcomp, $adurl, $dayscount);
          }
          /**
           * that finishes up notify the expiring ones.  Now, lets delete the old ones
           */
          
          $sql = 'update '.DB_PREFIX.'jobs set is_active = 0 WHERE DATEDIFF(NOW(), created_on) >= ' . $notifmax . ' AND is_active = 1';
          $db->query($sql);
          
      }

    public function DeleteOldJobs()
    {
        global $db;
        $sql = 'DELETE FROM '.DB_PREFIX.'jobs WHERE DATEDIFF(NOW(), created_on) > 50';
        $db->Execute($sql);
    }
    public function DeleteOldApps()
    {
        global $db;
        $sql = 'DELETE FROM '.DB_PREFIX.'jobs_applications WHERE DATEDIFF(NOW(), created_on) > 50';
        $db->Execute($sql);
    }
}
?>

You can keep the files where they are, just make sure to point to them correctly.
I have some extra stuff in my class.mainenance.php file for notifying when ads are expiring.

Last edited by hobo (2010-08-23 12:03:43)

davidarthurs

Re: Cron Job Newbie (using Hsphere)

hobo wrote:

It does not look correct, are you sure the files above are from latest version?

No not sure - I copied from a thread found via the forum.

Thanks for posting that cron info. Will try that. Maybe cron info should be a sticky or go into the wiki?

To actually run the cron job do you just put the correct absolute path into hsphere?

http://www.woria.com/cron/addtab/

so cron_maintenance.php can be kept in tools directory and doesn't need to go anywhere else on server?

what would they look like without the expiring notifications?

Last edited by davidarthurs (2010-08-23 12:08:46)

hobo

Re: Cron Job Newbie (using Hsphere)

Try using this:
_tools/cron_maintenance.php

Code:

<?php
/**
 * jobber job board platform
 *
 * @author     Filip C.T.E. <http://www.filipcte.ro> <me@filipcte.ro>
 * @license    You are free to edit and use this work, but it would be nice if you always referenced the original author ;)
 *             (see license.txt).
 */

    require_once '../_config/config.php';
    require_once APP_PATH . '_includes/class.Maintenance.php';


    $janitor = new Maintenance();

    // delete temporary posts older than 2 days
    $janitor->DeleteTemporaryJobs();
    // deactivate jobs older than 30 days + delete jobs older than 60 days.
        $janitor->DeactivateJobs();
    // delete jobs older than 60 days.
        $janitor->DeleteOldJobs();
?>

and _includes/class.maintenance.php

Code:


<?php
/**
 * jobber job board platform
 *
 * @author     Filip C.T.E. <http://www.filipcte.ro> <me@filipcte.ro>
 * @license    You are free to edit and use this work, but it would be nice if you always referenced the original author ;)
 *             (see license.txt).
 * 
 * Maintenance class handles site/database maintenance operations
 */

class Maintenance
{
    
    function __construct()
    { }
    
    // delete temporary posts older than 2 days
    public function DeleteTemporaryJobs()
    {
        global $db;
        $sql = 'DELETE FROM '.DB_PREFIX.'jobs WHERE created_on < DATE_SUB(NOW(), INTERVAL 1 DAY) AND is_temp = 1 AND is_active = 0';
        $db->Execute($sql);
    }

 

    public function DeleteOldJobs()
    {
        global $db;
        $sql = 'DELETE FROM '.DB_PREFIX.'jobs WHERE DATEDIFF(NOW(), created_on) > 50';
        $db->Execute($sql);
    }
}
?>

Last edited by hobo (2010-08-23 13:00:11)

davidarthurs

Re: Cron Job Newbie (using Hsphere)

thanks hobo will try that.