This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation



Accessible through the system section of the dashboard, jobs are ways of automating certain processes available to concrete5. These jobs can be run from the dashboard, or easily cronned and run from the server at specified intervals.

Examples of Jobs

concrete5 ships with three jobs: Reindex Search Engine, Generate sitemap.xml and Run Mail Importers. Each of these tasks is suited for a job, in that they need to be run periodically, require no user input and may take a little bit of time to run.

Creating Your Own Job

Creating your own job is as simple as creating a new class in the Job format, and adding it to the jobs/ directory in your local web root. This job will then appear on the Jobs page in your site's dashboard, can then be installed and run easily.

Step 1. Create the File

In your local jobs/ directory, create a file in the typical concrete5 handle format. (all lowercase, with underscores separating spaces. e.g. "index_search.php" or "clear_cache_files.php")

Create a class in this file

Within this file, take the name of your file (minus .php) and camelcase it, and use that as your job’s class name, while extending the Job class.

	class ClearCacheFiles extends Job

Specify the Job name and description

Within this file, define the method getJobName() and getJobDescription(), with each returning the relevant piece of information about the job.

Define the run() function

Inside a run() function of your Job, define whatever programming logic you wish to execute when the Job is run.

Setup error handling and output

Within your run() method, handle errors by using the throw() method and native PHP exception support. Any exceptions that occur within your job will cease the job from running and be reported to the administrator when they next visit the Jobs page in the dashboard.

If you would like to return custom output for the status of your job, simply return a string from your run() method.

Installing a Job with a Package

As of concrete 5.4, addon developers may install Jobs with their packages. To do this, simply include the job file in a jobs/ directory within the package, and execute the following code from within your package's install() command:

	Loader::model("job"); 	Job::installByPackage("your_job_handle", $pkg);

Any jobs installed in this way will automatically be removed if your package is uninstalled.

Loading Conversation