Skip to main content
replaced http://drupal.stackexchange.com/ with https://drupal.stackexchange.com/
Source Link

If you want to execute the same snippet of code, you might refactor it into a separate function, and call it from both mymodule_form_submit and mymodule_cron. Something like the following:

function _mymodule_set_expiry_date() {
  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'));
}

And then, on your hooks:

function mymodule_form_submit($form, $form_state) {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

function mymodule_cron() {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

You can see the following question on Drupal Answers for a more detailed explanation about hook_cron and hook_cron_queue_info: how to use hook_cron_queue_info in a custom module?how to use hook_cron_queue_info in a custom module?

Hope that helps,

If you want to execute the same snippet of code, you might refactor it into a separate function, and call it from both mymodule_form_submit and mymodule_cron. Something like the following:

function _mymodule_set_expiry_date() {
  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'));
}

And then, on your hooks:

function mymodule_form_submit($form, $form_state) {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

function mymodule_cron() {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

You can see the following question on Drupal Answers for a more detailed explanation about hook_cron and hook_cron_queue_info: how to use hook_cron_queue_info in a custom module?

Hope that helps,

If you want to execute the same snippet of code, you might refactor it into a separate function, and call it from both mymodule_form_submit and mymodule_cron. Something like the following:

function _mymodule_set_expiry_date() {
  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'));
}

And then, on your hooks:

function mymodule_form_submit($form, $form_state) {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

function mymodule_cron() {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

You can see the following question on Drupal Answers for a more detailed explanation about hook_cron and hook_cron_queue_info: how to use hook_cron_queue_info in a custom module?

Hope that helps,

added 236 characters in body
Source Link
dinopmi
  • 2.6k
  • 16
  • 17

If you want to execute the same snippet of code, you might refactor it into a separate function, and call it from both mymodule_form_submit and mymodule_cron. Something like the following:

function _mymodule_set_expiry_date() {
  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'));
}

And then, on your hooks:

function mymodule_form_submit($form, $form_state) {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

function mymodule_cron() {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

You can see the following question on Drupal Answers for a more detailed explanation about hook_cron and hook_cron_queue_info: how to use hook_cron_queue_info in a custom module?

Hope that helps,

If you want to execute the same snippet of code, you might refactor it into a separate function, and call it from both mymodule_form_submit and mymodule_cron. Something like the following:

function _mymodule_set_expiry_date() {
  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'));
}

And then, on your hooks:

function mymodule_form_submit($form, $form_state) {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

function mymodule_cron() {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

Hope that helps,

If you want to execute the same snippet of code, you might refactor it into a separate function, and call it from both mymodule_form_submit and mymodule_cron. Something like the following:

function _mymodule_set_expiry_date() {
  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'));
}

And then, on your hooks:

function mymodule_form_submit($form, $form_state) {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

function mymodule_cron() {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

You can see the following question on Drupal Answers for a more detailed explanation about hook_cron and hook_cron_queue_info: how to use hook_cron_queue_info in a custom module?

Hope that helps,

Source Link
dinopmi
  • 2.6k
  • 16
  • 17

If you want to execute the same snippet of code, you might refactor it into a separate function, and call it from both mymodule_form_submit and mymodule_cron. Something like the following:

function _mymodule_set_expiry_date() {
  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'));
}

And then, on your hooks:

function mymodule_form_submit($form, $form_state) {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

function mymodule_cron() {
  _mymodule_set_expiry_date();
  // ... rest of your code
}

Hope that helps,