Skip to content

Commit

Permalink
* [Added] Added Tasks component for the 3.0.x API
Browse files Browse the repository at this point in the history
* [Improved] Cleaned up the translations
  • Loading branch information
Andrew Welch committed Jan 17, 2017
1 parent 2a5e152 commit d66870f
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 52 deletions.
5 changes: 5 additions & 0 deletions CHANGLOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# generator-craftplugin Changelog

## 1.1.32 -- 2017.01.16

* [Added] Added Tasks component for the 3.0.x API
* [Improved] Cleaned up the translations

## 1.1.31 -- 2017.01.15

* [Added] Added Utilities component
Expand Down
2 changes: 2 additions & 0 deletions app/templates/api_version_3_0/src/migrations/_Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace <%= pluginVendorName %>\<%= pluginDirName %>\migrations;

use <%= pluginVendorName %>\<%= pluginDirName%>\<%= pluginHandle %>;

use Craft;
use craft\db\Connection;
use craft\db\Migration;
Expand Down
3 changes: 3 additions & 0 deletions app/templates/api_version_3_0/src/models/_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace <%= pluginVendorName %>\<%= pluginDirName %>\models;

use <%= pluginVendorName %>\<%= pluginDirName%>\<%= pluginHandle %>;

use Craft;
use craft\base\Model;

<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%>
Expand Down
3 changes: 3 additions & 0 deletions app/templates/api_version_3_0/src/models/_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace <%= pluginVendorName %>\<%= pluginDirName%>\models;

use <%= pluginVendorName %>\<%= pluginDirName%>\<%= pluginHandle %>;

use Craft;
use craft\base\Model;

<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%>
Expand Down
3 changes: 3 additions & 0 deletions app/templates/api_version_3_0/src/records/_Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace <%= pluginVendorName %>\<%= pluginDirName %>\records;

use <%= pluginVendorName %>\<%= pluginDirName%>\<%= pluginHandle %>;

use Craft;
use craft\db\ActiveRecord;

<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%>
Expand Down
154 changes: 109 additions & 45 deletions app/templates/api_version_3_0/src/tasks/_Task.php
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] %>');
}
}
21 changes: 17 additions & 4 deletions app/templates/api_version_3_0/src/translations/_en.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
/**
* <%= pluginName %> plugin for Craft CMS 3.x
*
* <%= pluginName %> Translation
* <%= pluginDescription %>
*
* @author <%= pluginAuthorName %>
* @copyright <%= copyrightNotice %>
* @link <%= pluginAuthorUrl %>
* @copyright <%= copyrightNotice %>
*/

<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%>
/**
* <%= pluginName %> en Translation
*
* http://www.yiiframework.com/doc-2.0/guide-tutorial-i18n.html
*
* @author <%= pluginAuthorName %>
* @package <%= pluginHandle %>
* @since <%= pluginVersion %>
*/
<% } else { -%>
/**
* @author <%= pluginAuthorName %>
* @package <%= pluginHandle %>
* @since <%= pluginVersion %>
*/

return array(
'Translate me' => 'To this',
);
4 changes: 2 additions & 2 deletions app/templates/target_apis/api_version_3_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@
{
"src": "src/tasks/_Task.php",
"destDir": "src/tasks/",
"dest": "Task.php",
"dest": ".php",
"requires": ["tasks"],
"subPrefix": "taskName",
"prefix": true
"prefix": false
},
{
"src": "src/utilities/_Utility.php",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-craftplugin",
"version": "1.1.31",
"version": "1.1.32",
"description": "generator-craftplugin is a Yeoman generator for Craft CMS plugins",
"main": "app/index.js",
"files": [
Expand Down

0 comments on commit d66870f

Please sign in to comment.