1
- using System ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
using System . Linq ;
4
3
5
4
using Umbraco . Cms . Integrations . Automation . Zapier . Extensions ;
6
- using Umbraco . Cms . Integrations . Automation . Zapier . Models . Dtos ;
7
5
using Umbraco . Cms . Integrations . Automation . Zapier . Services ;
8
6
9
7
#if NETCOREAPP
10
8
using Microsoft . Extensions . Options ;
11
-
9
+ using Umbraco . Cms . Core . Models . PublishedContent ;
12
10
using Umbraco . Cms . Core . Services ;
11
+ using Umbraco . Cms . Web . Common ;
13
12
using Umbraco . Cms . Integrations . Automation . Zapier . Configuration ;
14
13
#else
15
14
using Umbraco . Core . Services ;
@@ -24,38 +23,25 @@ namespace Umbraco.Cms.Integrations.Automation.Zapier.Controllers
24
23
/// </summary>
25
24
public class PollingController : ZapierAuthorizedApiController
26
25
{
27
- private IContentService _contentService ;
28
-
29
- private IContentTypeService _contentTypeService ;
26
+ private readonly IContentTypeService _contentTypeService ;
30
27
31
28
#if NETCOREAPP
32
- public PollingController ( IOptions < ZapierSettings > options , IContentService contentService , IContentTypeService contentTypeService , IUserValidationService userValidationService )
29
+ private readonly UmbracoHelper _umbracoHelper ;
30
+
31
+ public PollingController ( IOptions < ZapierSettings > options , IContentService contentService , IContentTypeService contentTypeService , UmbracoHelper umbracoHelper ,
32
+ IUserValidationService userValidationService )
33
33
: base ( options , userValidationService )
34
34
#else
35
- public PollingController ( IContentService contentService , IContentTypeService contentTypeService , IUserValidationService userValidationService )
35
+ public PollingController ( IContentTypeService contentTypeService , IUserValidationService userValidationService )
36
36
: base ( userValidationService )
37
37
#endif
38
38
{
39
- _contentService = contentService ;
40
-
41
39
_contentTypeService = contentTypeService ;
42
- }
43
-
44
- [ Obsolete ( "Used only for Umbraco Zapier app v1.0.0. For updated versions use GetContentByType" ) ]
45
- public IEnumerable < PublishedContentDto > GetSampleContent ( )
46
- {
47
- if ( ! IsAccessValid ( ) ) return null ;
48
40
49
- var rootNodes = _contentService . GetRootContent ( )
50
- . Where ( p => p . Published )
51
- . OrderByDescending ( p => p . PublishDate ) ;
52
-
53
- return rootNodes . Select ( p => new PublishedContentDto
54
- {
55
- Id = p . Id . ToString ( ) ,
56
- Name = p . Name ,
57
- PublishDate = p . PublishDate . Value . ToString ( )
58
- } ) ;
41
+ #if NETCOREAPP
42
+ _umbracoHelper = umbracoHelper ;
43
+ #else
44
+ #endif
59
45
}
60
46
61
47
public List < Dictionary < string , string > > GetContentByType ( string alias )
@@ -65,7 +51,15 @@ public List<Dictionary<string, string>> GetContentByType(string alias)
65
51
var contentType = _contentTypeService . Get ( alias ) ;
66
52
if ( contentType == null ) return new List < Dictionary < string , string > > ( ) ;
67
53
68
- return new List < Dictionary < string , string > > { contentType . ToContentTypeDictionary ( ) } ;
54
+ #if NETCOREAPP
55
+ var contentItems = _umbracoHelper . ContentAtXPath ( "//" + alias )
56
+ . OrderByDescending ( p => p . UpdateDate ) ;
57
+ #else
58
+ var contentItems = Umbraco . ContentAtXPath ( "//" + alias )
59
+ . OrderByDescending ( p => p . UpdateDate ) ;
60
+ #endif
61
+
62
+ return new List < Dictionary < string , string > > { contentType . ToContentTypeDictionary ( contentItems . FirstOrDefault ( ) ) } ;
69
63
}
70
64
71
65
0 commit comments