Skip to content

Commit 7d2f19f

Browse files
committed
Review updates and components structure tidying.
1 parent ac0c809 commit 7d2f19f

File tree

10 files changed

+182
-179
lines changed

10 files changed

+182
-179
lines changed

src/Umbraco.Cms.Integrations.Automation.Zapier/App_Plugins/UmbracoCms.Integrations/Automation/Zapier/js/zapier.controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
vm.onDelete = function (id) {
5454

55-
localizationService.localizeMany(["dashboardTabs_promptDeleteTitle", "dashboardTabs_promptDeleteContent", "general_yes", "general_no"])
55+
localizationService.localizeMany(["zapierDashboard_promptDeleteTitle", "zapierDashboard_promptDeleteContent", "general_yes", "general_no"])
5656
.then(function (labels) {
5757
var overlay = {
5858
view: "confirm",

src/Umbraco.Cms.Integrations.Automation.Zapier/App_Plugins/UmbracoCms.Integrations/Automation/Zapier/lang/en-US.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<language>
3-
<area alias="dashboardTabs">
4-
<key alias="zapierDashboard">Zapier Integrations</key>
3+
<area alias="zapierDashboard">
4+
<key alias="title">Zapier Integrations</key>
55
<key alias="promptDeleteTitle">Delete Registered Webhook</key>
66
<key alias="promptDeleteContent">Are you sure?</key>
77
</area>
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,19 @@
1-
using System;
1+
#if NETFRAMEWORK
2+
using System;
23
using System.Collections.Generic;
3-
using System.Net.Http;
44
using System.Threading.Tasks;
55

6-
76
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
87
using Umbraco.Core;
9-
10-
#if NETCOREAPP
11-
using Microsoft.Extensions.Logging;
12-
using Umbraco.Cms.Core.Events;
13-
using Umbraco.Cms.Core.Notifications;
14-
#else
158
using Umbraco.Core.Composing;
169
using Umbraco.Core.Events;
1710
using Umbraco.Core.Logging;
1811
using Umbraco.Core.Services;
1912
using Umbraco.Core.Services.Implement;
20-
#endif
2113

2214
namespace Umbraco.Cms.Integrations.Automation.Zapier.Components
2315
{
24-
#if NETCOREAPP
25-
public class NewContentPublishedNotification : INotificationHandler<ContentPublishedNotification>
26-
{
27-
private readonly ZapConfigService _zapConfigService;
28-
29-
private readonly ZapierService _zapierService;
30-
31-
private readonly ILogger<NewContentPublishedNotification> _logger;
32-
33-
public NewContentPublishedNotification(ZapConfigService zapConfigService, ZapierService zapierService, ILogger<NewContentPublishedNotification> logger)
34-
{
35-
_zapConfigService = zapConfigService;
36-
37-
_zapierService = zapierService;
38-
39-
_logger = logger;
40-
}
41-
42-
public void Handle(ContentPublishedNotification notification)
43-
{
44-
foreach (var node in notification.PublishedEntities)
45-
{
46-
var zapContentConfig = _zapConfigService.GetByName(node.ContentType.Name);
47-
if (zapContentConfig == null) continue;
48-
49-
var content = new Dictionary<string, string>
50-
{
51-
{ Constants.Content.Name, node.Name },
52-
{ Constants.Content.PublishDate, DateTime.UtcNow.ToString() }
53-
};
5416

55-
var t = Task.Run(async () => await _zapierService.TriggerAsync(zapContentConfig.WebHookUrl, content));
56-
57-
var result = t.Result;
58-
59-
if (!string.IsNullOrEmpty(result))
60-
_logger.LogError(result);
61-
}
62-
}
63-
}
64-
#else
6517
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
6618
public class NewContentPublishedComposer : ComponentComposer<NewContentPublishedComponent>
6719
{ }
@@ -115,5 +67,5 @@ private void ContentServiceOnPublished(IContentService sender, ContentPublishedE
11567
}
11668
}
11769
}
118-
#endif
11970
}
71+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#if NETCOREAPP
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
6+
using Microsoft.Extensions.Logging;
7+
8+
using Umbraco.Cms.Core.Events;
9+
using Umbraco.Cms.Core.Notifications;
10+
using Umbraco.Cms.Integrations.Automation.Zapier.Services;
11+
12+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Components
13+
{
14+
public class NewContentPublishedNotification : INotificationHandler<ContentPublishedNotification>
15+
{
16+
private readonly ZapConfigService _zapConfigService;
17+
18+
private readonly ZapierService _zapierService;
19+
20+
private readonly ILogger<NewContentPublishedNotification> _logger;
21+
22+
public NewContentPublishedNotification(ZapConfigService zapConfigService, ZapierService zapierService, ILogger<NewContentPublishedNotification> logger)
23+
{
24+
_zapConfigService = zapConfigService;
25+
26+
_zapierService = zapierService;
27+
28+
_logger = logger;
29+
}
30+
31+
public void Handle(ContentPublishedNotification notification)
32+
{
33+
foreach (var node in notification.PublishedEntities)
34+
{
35+
var zapContentConfig = _zapConfigService.GetByName(node.ContentType.Name);
36+
if (zapContentConfig == null) continue;
37+
38+
var content = new Dictionary<string, string>
39+
{
40+
{ Constants.Content.Name, node.Name },
41+
{ Constants.Content.PublishDate, DateTime.UtcNow.ToString() }
42+
};
43+
44+
var t = Task.Run(async () => await _zapierService.TriggerAsync(zapContentConfig.WebHookUrl, content));
45+
46+
var result = t.Result;
47+
48+
if (!string.IsNullOrEmpty(result))
49+
_logger.LogError(result);
50+
}
51+
}
52+
}
53+
}
54+
#endif

src/Umbraco.Cms.Integrations.Automation.Zapier/Components/ZapContentConfigComponent.cs

-108
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#if NETCOREAPP
2+
using Umbraco.Cms.Core;
3+
using Umbraco.Cms.Core.Events;
4+
using Umbraco.Cms.Core.Migrations;
5+
using Umbraco.Cms.Core.Notifications;
6+
using Umbraco.Cms.Core.Scoping;
7+
using Umbraco.Cms.Core.Services;
8+
using Umbraco.Cms.Infrastructure.Migrations;
9+
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
10+
11+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Migrations
12+
{
13+
public class UmbracoAppStartingHandler : INotificationHandler<UmbracoApplicationStartingNotification>
14+
{
15+
private readonly IMigrationPlanExecutor _migrationPlanExecutor;
16+
17+
private readonly IScopeProvider _scopeProvider;
18+
19+
private readonly IKeyValueService _keyValueService;
20+
21+
private readonly IRuntimeState _runtimeState;
22+
23+
public UmbracoAppStartingHandler(
24+
IScopeProvider scopeProvider,
25+
IMigrationPlanExecutor migrationPlanExecutor,
26+
IKeyValueService keyValueService,
27+
IRuntimeState runtimeState)
28+
{
29+
_migrationPlanExecutor = migrationPlanExecutor;
30+
31+
_scopeProvider = scopeProvider;
32+
33+
_keyValueService = keyValueService;
34+
35+
_runtimeState = runtimeState;
36+
}
37+
38+
public void Handle(UmbracoApplicationStartingNotification notification)
39+
{
40+
if (_runtimeState.Level < RuntimeLevel.Run) return;
41+
42+
var migrationPlan = new MigrationPlan(Constants.MigrationPlanName);
43+
44+
migrationPlan.From(string.Empty)
45+
.To<ZapContentConfigTable>(Constants.TargetStateName);
46+
47+
var upgrader = new Upgrader(migrationPlan);
48+
upgrader.Execute(_migrationPlanExecutor, _scopeProvider, _keyValueService);
49+
}
50+
}
51+
}
52+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#if NETFRAMEWORK
2+
using Umbraco.Core;
3+
using Umbraco.Core.Composing;
4+
using Umbraco.Core.Logging;
5+
using Umbraco.Core.Migrations;
6+
using Umbraco.Core.Migrations.Upgrade;
7+
using Umbraco.Core.Scoping;
8+
using Umbraco.Core.Services;
9+
10+
11+
namespace Umbraco.Cms.Integrations.Automation.Zapier.Migrations
12+
{
13+
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
14+
public class ZapContentConfigComposer : ComponentComposer<ZapContentConfigComponent>
15+
{
16+
17+
}
18+
19+
public class ZapContentConfigComponent : IComponent
20+
{
21+
private IScopeProvider _scopeProvider;
22+
23+
private IMigrationBuilder _migrationBuilder;
24+
25+
private IKeyValueService _keyValueService;
26+
27+
private ILogger _logger;
28+
29+
public ZapContentConfigComponent(IScopeProvider scopeProvider, IMigrationBuilder migrationBuilder, IKeyValueService keyValueService, ILogger logger)
30+
{
31+
_scopeProvider = scopeProvider;
32+
33+
_migrationBuilder = migrationBuilder;
34+
35+
_keyValueService = keyValueService;
36+
37+
_logger = logger;
38+
}
39+
40+
public void Initialize()
41+
{
42+
var migrationPlan = new MigrationPlan(Constants.MigrationPlanName);
43+
44+
migrationPlan.From(string.Empty)
45+
.To<ZapContentConfigTable>(Constants.TargetStateName);
46+
47+
var upgrader = new Upgrader(migrationPlan);
48+
upgrader.Execute(_scopeProvider, _migrationBuilder, _keyValueService, _logger);
49+
}
50+
51+
public void Terminate()
52+
{
53+
}
54+
}
55+
}
56+
#endif

0 commit comments

Comments
 (0)