2

I cant really figure this out.

I have a module which interacts with the webform module which just works perfectly fine.

But now I wanted to create a cron which updates certain submissions, but the cron function claims that suddenly the webform function webform_get_submission is undefined although all other mymodule functions use webform functions without any issues. How come?

// a whole lot functions which use webform functions
// [...]

function mymmodule_cron() {
    $conf = mymmodule_defaults();

    // check cron run
    if(true /* for testing */){

        // set writable User
        global $user;
        $original_user = $user;
        $old_state = drupal_save_session(FALSE);
        $user = user_load(1);

        // fancy sql statement
        $sql = array();
        // [...]
        $sql = join(" ",$sql);
        $result = db_query($sql);

        $queue = DrupalQueue::get('mymmodule_cron_archiveanon');

        foreach ($result as $row) {
            $row->anon = true;
            $queue->createItem($row);           
        }      

        // restore default user
        $user = $original_user;
        drupal_save_session($old_state); 
    }

}

function mymmodule_cron_archiveanon_wrapper($item){
    $node = node_load($item->nid);

    if( function_exists('webform_get_submission')) {
        die("Yep."); 
        // $submission = webform_get_submission($item->nid, $item->sid);
    }
    else {
        die("Nope.");
        // dies here
    }

    // custom function
    // mymmodule_contract_archive($node, $submission, $item->anon);

}

1 Answer 1

4

That function is in a file that isn't included by default; you just need to include it yourself:

module_load_include('inc', 'webform', 'includes/webform.submissions');
7
  • but why do the other webform functions work?
    – Alex
    Commented Jul 18, 2013 at 8:36
  • There aren't any other calls to webform functions in your code
    – Clive
    Commented Jul 18, 2013 at 8:41
  • i commented them out, see the very first line. within the cron function, there is not. so are you implying that i must, only for the cron function, include the module although all other hooks and function dont need to?
    – Alex
    Commented Jul 18, 2013 at 8:45
  • Not necessarily just the cron functions - if a file's not included in the context you're in, and you need a function within, you have to include it that's just PHP's way of splitting code into different files. I can't comment as to why some of the functions you're calling are available as you haven't mentioned which one's you're using, or what context you're calling them in
    – Clive
    Commented Jul 18, 2013 at 8:50
  • The context is that a webform form is opened, then all my functions get called and alter the webform. I will try out to include the file although I dont think this is an elegant solution! Thanks for your help so far
    – Alex
    Commented Jul 18, 2013 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.