Skip to content

Commit b9a79d9

Browse files
committed
Merge branch 'release/2.0.1'
2 parents bf7194d + 416f7e7 commit b9a79d9

File tree

10 files changed

+85
-48
lines changed

10 files changed

+85
-48
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Release Notes for Webhooks for Craft CMS
22

3+
## 2.0.1 - 2019-03-20
4+
5+
### Fixed
6+
- Fixed a bug where it wasn’t possible to create or edit webhooks if a plugin contained an invalid class. ([#8](https://github.com/craftcms/webhooks/issues/8))
7+
- Fixed a SQL error that would occur on installs that had been updated from Webhooks 1.x.
8+
- Fixed a SQL error that occurred when attempting to uninstall Webhooks.
9+
310
## 2.0.0 - 2019-03-19
411

512
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "craftcms/webhooks",
33
"description": "Post webhooks when events are triggered in Craft CMS.",
4-
"version": "2.0.0",
4+
"version": "2.0.1",
55
"type": "craft-plugin",
66
"keywords": [
77
"html",

src/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Plugin extends \craft\base\Plugin
4848
/**
4949
* @inheritdoc
5050
*/
51-
public $schemaVersion = '2.0.0';
51+
public $schemaVersion = '2.0.1';
5252

5353
// Public Methods
5454
// =========================================================================

src/WebhookHelper.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class WebhookHelper
3535
*/
3636
public static function classSuggestions(): array
3737
{
38-
$data = Craft::$app->getCache()->getOrSet('webhooks.classSuggestions', function() {
38+
return Craft::$app->getCache()->getOrSet('webhooks.classSuggestions', function() {
3939
$classes = [];
4040
foreach (self::_findClasses() as $class) {
4141
$classes[] = [
@@ -47,12 +47,6 @@ public static function classSuggestions(): array
4747
}, null, new FileDependency([
4848
'fileName' => Craft::$app->getPath()->getVendorPath() . '/composer/autoload_real.php',
4949
]));
50-
51-
return [
52-
[
53-
'data' => $data,
54-
],
55-
];
5650
}
5751

5852
/**

src/controllers/WebhooksController.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,13 @@ public function actionEdit(int $id = null, int $groupId = null, Webhook $webhook
7979
}
8080
}
8181

82-
// Autosuggest classes
83-
$classSuggestions = WebhookHelper::classSuggestions();
84-
8582
Craft::$app->getView()->registerAssetBundle(EditAsset::class);
8683

8784
return $this->renderTemplate('webhooks/_manage/edit', compact(
8885
'groupOptions',
8986
'webhook',
9087
'title',
91-
'crumbs',
92-
'classSuggestions'
88+
'crumbs'
9389
));
9490
}
9591

@@ -169,6 +165,16 @@ public function actionDelete(): Response
169165
return $this->redirectToPostedUrl();
170166
}
171167

168+
/**
169+
* Returns the available sender classes.
170+
*/
171+
public function actionClassSuggestions(): Response
172+
{
173+
return $this->asJson([
174+
'classes' => WebhookHelper::classSuggestions(),
175+
]);
176+
}
177+
172178
/**
173179
* Returns the available events for a component class.
174180
*/

src/migrations/Install.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public function safeUp()
7777
public function safeDown()
7878
{
7979
// Drop the DB table
80+
$this->dropTableIfExists('{{%webhookrequests}}');
8081
$this->dropTableIfExists('{{%webhooks}}');
8182
$this->dropTableIfExists('{{%webhookgroups}}');
82-
$this->dropTableIfExists('{{%webhookrequests}}');
8383
}
8484
}

src/migrations/m190112_00000_json_payload.php

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace craft\webhooks\migrations;
4+
5+
use Craft;
6+
use craft\db\Migration;
7+
8+
/**
9+
* m190320_182458_payload_template_col migration.
10+
*/
11+
class m190320_182458_payload_template_col extends Migration
12+
{
13+
/**
14+
* @inheritdoc
15+
*/
16+
public function safeUp()
17+
{
18+
if (!$this->db->columnExists('{{%webhooks}}', 'payloadTemplate')) {
19+
$this->addColumn('{{%webhooks}}', 'payloadTemplate', $this->mediumText()->after('eventAttributes'));
20+
}
21+
}
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
public function safeDown()
27+
{
28+
echo "m190320_182458_payload_template_col cannot be reverted.\n";
29+
return false;
30+
}
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{% extends '_includes/forms/autosuggest' %}
2+
3+
{% block data %}
4+
{{ parent() }}
5+
this.updateSuggestions()
6+
{#data.inputProps.onInputChange = this.myOnInputChange;#}
7+
8+
{% endblock %}
9+
10+
11+
{% block methods %}
12+
{{ parent() }}
13+
updateSuggestions() {
14+
Craft.postActionRequest('webhooks/webhooks/class-suggestions', {}, $.proxy(function(response, textStatus) {
15+
if (textStatus === 'success') {
16+
this.suggestions = [
17+
{
18+
data: response.classes
19+
}
20+
];
21+
}
22+
}, this));
23+
},
24+
{% endblock %}

src/templates/_manage/edit.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,20 @@
4141
errors: webhook.getErrors('name')
4242
}) }}
4343

44-
{{ forms.autosuggestField({
45-
label: 'Sender Class'|t('webhooks'),
46-
required: true,
47-
instructions: 'The class name the sender must be an instance of.'|t('webhooks'),
44+
{% set classInput = include('webhooks/_manage/class-autosuggest', {
4845
id: 'class',
4946
name: 'class',
5047
class: 'code ltr',
51-
suggestions: classSuggestions,
5248
placeholder: 'craft\\elements\\Entry',
5349
value: webhook.class,
5450
errors: webhook.getErrors('class')
55-
}) }}
51+
}, with_context = false) %}
52+
{{ forms.field({
53+
label: 'Sender Class'|t('webhooks'),
54+
required: true,
55+
instructions: 'The class name the sender must be an instance of.'|t('webhooks'),
56+
errors: webhook.getErrors('class')
57+
}, classInput) }}
5658

5759
{% set eventInput = include('webhooks/_manage/event-autosuggest', {
5860
id: 'event',

0 commit comments

Comments
 (0)