General developer forum

Task is not being added when I upgrade my plugin

 
Picture of BAT BAT
Task is not being added when I upgrade my plugin
 

Okay, I think I am following the documentation on:

https://docs.moodle.org/dev/Task_API


But every time I upgrade my block the server->schedule_task doesn't show my block.

Here is my code:  <myblock>/classes/taskrecord_transcripts.php

<?php 

namespace block_autoteach\task;

class record_transcripts extends \core\task\schedule_task

{

public function get_name()      { 

        return "Record and Reset Course (AutoTeach)";

        }

public function execute()         {

                set_config('Reset_Chron','1','autoteach');

        }

}

?>

Here is my <plugin folder>/db/tasks.php

<?php 

$tasks = array(array(

        'classname' =>'block_autoteach\task\record_transcripts',

        'blocking'=>"0",

        'minute'=>"*",

        'hour'=>"*",

        'day'=>"*",

        'dayofweek'=>"*",

        'month' =>"*",

        'disable'=>'0'

));?>



I do not understand what I am missing do I need to make a function has_tasks()? (Like I did for settings?)  Any help would be appreciated.   

I have also made sure the web-server owns the files, and I tried making both files executable as well.  It has to be something silly I am missing.


Thanks,
BAT

 
Average of ratings: -
Picture of Rex Lorenzo
Re: Task is not being added when I upgrade my plugin
Core developersParticularly helpful MoodlersPlugin developersPlugins guardiansTesters

I think the Moodle autoclass loading is not picking up your class. In the classes folder your file needs to be in a subfolder called task I believe.

https://docs.moodle.org/dev/Automatic_class_loading

 
Average of ratings: -
Picture of BAT BAT
Re: Task is not being added when I upgrade my plugin
 

Sorry typo, I have the folder called task.


Here is my code:  <myblock>/classes/task/record_transcripts.php

 
Average of ratings: -
Picture of Andreas Grabs
Re: Task is not being added when I upgrade my plugin
Core developersParticularly helpful MoodlersPlugin developersTranslators

Hi,

If your code above is exactly your code, you have a typo in it.

Your code part:

class record_transcripts extends \core\task\schedule_task

The correct code part:

class record_transcripts extends \core\task\scheduled_task

Maybe that's why the class is not loaded.

Best regards
Andreas

 
Average of ratings: -
Picture of BAT BAT
Re: Task is not being added when I upgrade my plugin
 

Wow, I missed that.  Thank you.  I am still having problems getting it to load.   IS there a specific naming convention I need for the file inside the folder?   

I know it is using my blocks namespace inside php.   

I have it named as record_transcripts.php right now. does it need to be autoteach_record_transcripts... or something like that?


Thanks again for the syntax check!  

BAT

 
Average of ratings: -
Picture of Andreas Grabs
Re: Task is not being added when I upgrade my plugin
Core developersParticularly helpful MoodlersPlugin developersTranslators

I don't know what you are missing sad. The code seems ok to me.

I would check the following things (and please don't use the closing php tags "?>" in your code!):

Try to load your class by your self.
<?php
// This is a testfile to check whether an existing class is loaded.
require_once('config.php');
if (class_exists('block_autoteach\task\record_transcripts')) {
    echo 'ok';
}
Increase the version of your plugin so the db/tasks.php is read.

Best regards
Andreas


 
Average of ratings: -
Picture of BAT BAT
Re: Task is not being added when I upgrade my plugin
 

It doesn't like the require_once('config.php') line.   It just gives me a white page if I have it.  

It will not recognize the function either.  

I am using Moodle 3.4.


Thanks,

BAT

 
Average of ratings: -
Picture of BAT BAT
Re: Task is not being added when I upgrade my plugin
 

I have the same file name and the class name.  

I, stupidly, forgot to set my crontab.  So now cron is actually running.  However, I am still not loading my task.


~BAT

 
Average of ratings: -
Picture of BAT BAT
Re: Task is not being added when I upgrade my plugin
 

What file should this go under?


Thanks,
BAT

 
Average of ratings: -
Picture of BAT BAT
Re: Task is not being added when I upgrade my plugin
 

Wow, I missed that.  Thank you.  I am still having problems getting it to load.   IS there a specific naming convention I need for the file inside the folder?   

I know it is using my blocks namespace inside php.   

I have it named as record_transcripts.php right now. does it need to be autoteach_record_transcripts... or something like that?


Thanks again for the syntax check!  

BAT

 
Average of ratings: -
Picture of Darko Miletić
Re: Task is not being added when I upgrade my plugin
Core developersParticularly helpful Moodlers

The file name and class name must be identical. If class is named foo filename must be foo.php

 
Average of ratings: -
Picture of Darko Miletić
Re: Task is not being added when I upgrade my plugin
Core developersParticularly helpful Moodlers

The file name and class name must be identical. If class is named foo filename must be foo.php

 
Average of ratings: -