-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [Added] Added Tasks component for the 3.0.x API
* [Improved] Cleaned up the translations
- Loading branch information
Andrew Welch
committed
Jan 17, 2017
1 parent
2a5e152
commit d66870f
Showing
9 changed files
with
145 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,150 @@ | ||
<?php | ||
/** | ||
* <%= pluginName %> plugin for Craft CMS 3.x | ||
* | ||
* <%= pluginDescription %> | ||
* | ||
* @link <%= pluginAuthorUrl %> | ||
* @copyright <%= copyrightNotice %> | ||
*/ | ||
|
||
namespace <%= pluginVendorName %>\<%= pluginDirName %>\tasks; | ||
|
||
use <%= pluginVendorName %>\<%= pluginDirName%>\<%= pluginHandle %>; | ||
|
||
// WARNING: Not converted to Craft 3 yet | ||
use Craft; | ||
use craft\base\Task; | ||
|
||
<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%> | ||
/** | ||
* <%= pluginName %> plugin for Craft CMS | ||
* <%= taskName[index] %> Task | ||
* | ||
* <%= pluginHandle %><%= taskName[index] %> Task | ||
* Tasks let you run background processing for things that take a long time, | ||
* dividing them up into steps. For example, Asset Transforms are regenerated | ||
* using Tasks. | ||
* | ||
<% if ((typeof codeComments !== 'undefined') && (codeComments)){ -%> | ||
* --snip-- | ||
* Tasks let you run background processing for things that take a long time, dividing them up into steps. For | ||
* example, Asset Transforms are regenerated using Tasks. | ||
* | ||
* Keep in mind that tasks only get timeslices to run when Craft is handling requests on your website. If you | ||
* need a task to be run on a regular basis, write a Controller that triggers it, and set up a cron job to | ||
* Keep in mind that tasks only get timeslices to run when Craft is handling | ||
* requests on your website. If you need a task to be run on a regular basis, | ||
* write a Controller that triggers it, and set up a cron job to | ||
* trigger the controller. | ||
* | ||
* The pattern used to queue up a task for running is: | ||
* | ||
* use <%= pluginVendorName %>\<%= pluginDirName %>\tasks\<%= taskName[index] %> as <%= taskName[index] %>Task; | ||
* | ||
* $tasks = Craft::$app->getTasks(); | ||
* if (!$tasks->areTasksPending(<%= taskName[index] %>Task::class)) { | ||
* $tasks->createTask(<%= taskName[index] %>Task::class); | ||
* } | ||
* | ||
* https://craftcms.com/classreference/services/TasksService | ||
* --snip-- | ||
* | ||
<% } -%> | ||
* @author <%= pluginAuthorName %> | ||
* @copyright <%= copyrightNotice %> | ||
* @link <%= pluginAuthorUrl %> | ||
* @package <%= pluginHandle %> | ||
* @since <%= pluginVersion %> | ||
*/ | ||
|
||
namespace Craft; | ||
|
||
class <%= pluginHandle %><%= taskName[index] %>Task extends BaseTask | ||
<% } else { -%> | ||
/** | ||
* @author <%= pluginAuthorName %> | ||
* @package <%= pluginHandle %> | ||
* @since <%= pluginVersion %> | ||
*/ | ||
<% } -%> | ||
class <%= taskName[index] %> extends Task | ||
{ | ||
// Public Properties | ||
// ========================================================================= | ||
|
||
<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%> | ||
/** | ||
<% if ((typeof codeComments !== 'undefined') && (codeComments)){ -%> | ||
* Defines the settings. | ||
* Some attribute | ||
* | ||
<% } -%> | ||
* @access protected | ||
* @return array | ||
* @var string | ||
*/ | ||
<% } else { -%> | ||
/** | ||
* @var string | ||
*/ | ||
<% } -%> | ||
public $someAttribute = 'Some Default'; | ||
|
||
protected function defineSettings() | ||
{ | ||
return array( | ||
'someSetting' => AttributeType::String, | ||
); | ||
} | ||
// Public Methods | ||
// ========================================================================= | ||
|
||
<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%> | ||
/** | ||
<% if ((typeof codeComments !== 'undefined') && (codeComments)){ -%> | ||
* Returns the default description for this task. | ||
* Returns the validation rules for attributes. | ||
* | ||
<% } -%> | ||
* @return string | ||
* Validation rules are used by [[validate()]] to check if attribute values are valid. | ||
* Child classes may override this method to declare different validation rules. | ||
* | ||
* More info: http://www.yiiframework.com/doc-2.0/guide-input-validation.html | ||
* | ||
* @return array | ||
*/ | ||
<% } else { -%> | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getDescription() | ||
<% } -%> | ||
public function rules() | ||
{ | ||
return '<%= pluginHandle %><%= taskName[index] %> Tasks'; | ||
return [ | ||
['someAttribute', 'string'], | ||
['someAttribute', 'default', 'value' => 'Some Default'], | ||
]; | ||
} | ||
|
||
<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%> | ||
/** | ||
<% if ((typeof codeComments !== 'undefined') && (codeComments)){ -%> | ||
* Gets the total number of steps for this task. | ||
* Returns the total number of steps for this task. | ||
* | ||
<% } -%> | ||
* @return int | ||
* @return int The total number of steps for this task | ||
*/ | ||
public function getTotalSteps() | ||
<% } else { -%> | ||
/** | ||
* @inheritdoc | ||
*/ | ||
<% } -%> | ||
public function getTotalSteps(): int | ||
{ | ||
return 1; | ||
} | ||
|
||
<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%> | ||
/** | ||
<% if ((typeof codeComments !== 'undefined') && (codeComments)){ -%> | ||
* Runs a task step. | ||
* | ||
<% } -%> | ||
* @param int $step | ||
* @return bool | ||
* @param int $step The step to run | ||
* | ||
* @return bool|string True if the step was successful, false or an error message if not | ||
*/ | ||
<% } else { -%> | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function runStep($step) | ||
<% } -%> | ||
public function runStep(int $step) | ||
{ | ||
return true; | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%> | ||
/** | ||
* Returns a default description for [[getDescription()]], if [[description]] isn’t set. | ||
* | ||
* @return string The default task description | ||
*/ | ||
<% } else { -%> | ||
/** | ||
* @inheritdoc | ||
*/ | ||
<% } -%> | ||
protected function defaultDescription(): string | ||
{ | ||
return Craft::t('<%= pluginDirName %>', '<%= taskName[index] %>'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters