In my custom form module submit handler, I have written the following code:
function mymodule_form_submit($form, $form_state) {
db_insert('bds_user_expiry')->fields(array(
'uid' =>$user_id,
'active_user'=>strtotime("now"),
))->execute();
drupal_set_message(t('You have successfully set the expiry date'));
}
}
Here bds_user_expiry
is my custom table name. When I click on submit button $user_id and the current time will be stored in my table.Now I want to define this scenario in hook_cron_queue_info()
so that whenever cron runs this snippet will also run. For this first I have to define hook_cron()
, issue is how can I define the above function in hook_cron
,
function mymodule_form_submit($form, $form_state) {
function my_module_cron(){
$result=db_insert('bds_user_expiry')->fields(array(
'uid' =>$user_id,
'active_user'=>strtotime("now"),
))->execute();
$result=db_query($query);
$queue=DrupalQueue::get("item");
foreach($result as $data){
$queue->createItem($data);
}
}
}
Is this right? Can I define hook_cron in submit handler?
UPDATED(To check if my snippet runs with cron or not)
Following code is written in my custom module file.
when cron runs value of uid from bds_user_expiry
will be inserted in my_cron_table
just to check if my code is working with cron or not, but neither it gives me any error nor successful result.
function user_form_expiry_form_cron(){
$new=db_select('bds_user_expiry', 'b')
->fields('b',array('uid'))
->execute()->fetchassoc();
//print_r($new);
$result=db_query($new);
$queue=DrupalQueue::get("item");
foreach($result as $data){
$queue->createItem($data);
}
}
function user_form_expiry_cron_form_queue_info(){
$queues=array();
$queues['item']=array(
"worker callback"=>"myfunc",
);
return $queues;
}
function myfunc($data){
db_insert('my_cron_table')->fields(array(
'uid' =>$data,
))->execute();
}