Want to run a cron for seding emails to certain users

Hi all,

I just wanna run a cron (daily) to send emails to some specific people who has not logged in for the last 1 month

i have can get the array of users with entity prev_last_login in a separate file located in views/default/page/elements/

My question is,  can i call this array in a function notlogin_cron($hook, $entity_type, $returnvalue, $params)

or should i put all code in the notlogin.php to above function to have a cron running?

Plus.. i have installed croncheck plugin.. its not showing the last time of the cron run.. its show  like 208 days ago... (?? means cron not running?)

Please help.. thank you for your help

  • The easiest way to do this would be to pass a custom where clause to elgg_get_entities in a cron hook:

    $one_month_ago_ts = strtotime("-1 month");

    $users = elgg_get_entities(array(

    'type' => 'user',

    'where' => "last_action < $one_month_ago_ts",

    'limit' => 50

  • Thank you Bret for your reply...

    i made a code like this as u suggested...

    But still cron triggering is not happening..

    Added following code to Aathira_init()

    elgg_register_plugin_hook_handler('cron', 'daily', 'Aathira_notloggedin_mailer');

     

    Then made a fuction for cron trigger

    function Aathira_notloggedin_mailer($hook, $entity_type, $returnvalue, $params){
        global $CONFIG;
        $siteaddress = elgg_get_site_url();
        $sitename = elgg_get_site_entity()->name;
        $site = get_entity($CONFIG->site_guid);
        if (($site) && (isset($site->email))) {
        $from = $site->email;
        } else {
        $from = 'noreply@' . get_site_domain($CONFIG->site_guid);
        }

        $one_month_ago_ts = strtotime("-1 month");
        $users = elgg_get_entities(array(
        'type' => 'user',
        'where' => "last_action < $one_month_ago_ts",
        'limit' =>'50'
        ));

            foreach ($users as $user){
                $nli_name = $nli_user->name;
                $nli_email = $nli_user->email;
                $message = sprintf(elgg_echo('Aathira:notloggedin_message'), $nli_name, $nli_day, $sitename, $siteaddress);
                elgg_send_email($from, $nli_email, elgg_echo('Aathira:notloggedin_message:subject'), $message);

        }

    }

  • I had an idea for a profile to somehow cripple after some time with no update, like turning black and white from color until the log in or update....evil me!

  • I have another code for sending a birthday wish every day.. can anyone point out the mistakes that i made i this ....(sorry, i am not a professional)

     

    function Aathira_init() {
        elgg_register_plugin_hook_handler('cron', 'daily', 'Aathira_bday_mailer');

    }

    function Aathira_bday_mailer($hook, $entity_type, $returnvalue, $params){

        $from = 'admin_ann@gmail.com';

                $options = array(
                'metadata_names' => $bday,
                'types' => 'user',
        'limit' => false,
        'full_view' => false,
        'pagination' => false,
        'list_type' => 'gallery',
        'gallery_class' => 'elgg-gallery-users',
                );

            $bd_users = elgg_get_entities_from_metadata($options);
            $bd_today = date('j, F', strtotime('now'));

            foreach ($bd_users as $bd_user){
                $bd_name = $bd_user->name;
                $bd_email = $bd_user->email;
                $bd_day = date('j, F', strtotime($bd_user->$bday));
            if ($bd_day == $bd_today){
                $message = sprintf(elgg_echo('Aathira:bday_message'), $bd_name, $bd_day, $sitename, $siteaddress);
                elgg_send_email($from, $bd_email, elgg_echo('Aathira:bday_message:subject'), $message);
            }
        }
        return true;
    }

    Thankyou very much

  • 1) post elgg.Vr# always ;-) nobody seems to do that ;-)
    2) post error messages if any - not simply 'does not work' ;)
    3) what is '$bday' inside funcn ? not defined ?
    4) check/review all parms @ ..-from_metadata - i think u got some bad/.missing  parms there !

    'metadata_names'  => -- needs 'metadata_values' => -- also
    but => better to use 'metadata_name_value_pairs' - just read thru someotherougn for examples of 'how-to' code this.



  • weelll - i suppose that the problem's got fixed, seeing as there's no further interjections yet... ;-P

     

  • not yet...

    var $bday will get it from the settings.. everthing is correct and its fetching all members with birthday... if you give a view to that arry it will show members...

    but its not sending mails.. or cron is not running...

  • may be the wallgarden is blocking the cron as this page says...

    http://trac.elgg.org/ticket/4394

  • after upgrading to 1.8.4 also this problem is not solved.. can any one help me out?