2
2
3
3
namespace Bonnier \WP \ContentHub \Editor \Commands ;
4
4
5
- use Bonnier \WP \Cache \Models \Post ;
5
+ use Bonnier \WP \Cache \Models \Post as BonnierCachePost ;
6
6
use Bonnier \WP \ContentHub \Editor \Commands \Taxonomy \Helpers \WpTerm ;
7
7
use Bonnier \WP \ContentHub \Editor \Helpers \SlugHelper ;
8
8
use Bonnier \WP \ContentHub \Editor \Models \WpAttachment ;
9
9
use Bonnier \WP \ContentHub \Editor \Models \WpComposite ;
10
10
use Bonnier \WP \ContentHub \Editor \Models \WpTaxonomy ;
11
11
use Bonnier \WP \ContentHub \Editor \Repositories \Scaphold \CompositeRepository ;
12
+ use Bonnier \WP \Cxense \Models \Post as CxensePost ;
12
13
use Illuminate \Support \Collection ;
13
14
use WP_CLI ;
14
15
use WP_Post ;
@@ -36,6 +37,9 @@ public static function register()
36
37
* [--id=<id>]
37
38
* : The id of a single composite to import.
38
39
*
40
+ * [--source=<source_code>]
41
+ * : The the source code to fetch content from
42
+ *
39
43
* ## EXAMPLES
40
44
* wp contenthub editor composites import
41
45
*
@@ -49,19 +53,24 @@ public function import($args, $assocArgs)
49
53
return [];
50
54
});
51
55
52
- // Disable on save hook to prevent call to content hub on import
56
+ // Disable on save hook to prevent call to content hub, Cxense and Bonnier Cache Manager
53
57
remove_action ( 'save_post ' , [WpComposite::class, 'on_save ' ], 10 , 2 );
54
- // Disable on save hook in wp bonnier cache, to avoid triggering cxense crawl on import
55
- remove_action ( 'save_post ' , [Post ::class, 'update_post ' ], 10 , 1 );
56
-
58
+ remove_action ( ' save_post ' , [BonnierCachePost::class, ' update_post ' ], 10 , 1 );
59
+ remove_action ( 'save_post ' , [CxensePost ::class, 'update_post ' ], 10 , 1 );
60
+
57
61
if ($ id = $ assocArgs ['id ' ] ?? null ) {
58
62
$ this ->import_composite (CompositeRepository::find_by_id ($ id ));
59
63
return ;
60
64
}
61
- $ this ->map_sites (function ($ site ) {
62
- $ this ->map_composites_by_brand_id ($ site ->brand ->content_hub_id , function ($ composite ) {
65
+ $ brandId = $ this ->get_site ()->brand ->content_hub_id ;
66
+ if ($ source = $ assocArgs ['source ' ] ?? null ) {
67
+ $ this ->map_composites_by_brand_id_and_source ($ brandId , $ source , function ($ composite ) {
63
68
$ this ->import_composite ($ composite );
64
69
});
70
+ return ;
71
+ }
72
+ $ this ->map_composites_by_brand_id ($ brandId , function ($ composite ) {
73
+ $ this ->import_composite ($ composite );
65
74
});
66
75
}
67
76
@@ -120,6 +129,22 @@ private function map_composites_by_brand_id($id, callable $callable)
120
129
}
121
130
}
122
131
132
+ private function map_composites_by_brand_id_and_source ($ id , $ source , callable $ callable )
133
+ {
134
+ $ compositeQuery = CompositeRepository::find_by_brand_id_and_source ($ id , $ source );
135
+
136
+ while ($ compositeQuery ) {
137
+ $ categories = collect ($ compositeQuery ->edges );
138
+ $ categories ->pluck ('node ' )->each (function ($ compositeInfo ) use ($ callable ) {
139
+ $ callable (CompositeRepository::find_by_id ($ compositeInfo ->id ));
140
+ });
141
+ if (isset ($ compositeQuery ->pageInfo ->hasNextPage ) && $ compositeQuery ->pageInfo ->hasNextPage )
142
+ $ compositeQuery = CompositeRepository::map_composites_by_brand_id_and_source ($ id , $ categories ->last ()->cursor );
143
+ else
144
+ $ compositeQuery = null ;
145
+ }
146
+ }
147
+
123
148
private function import_composite ($ composite )
124
149
{
125
150
WP_CLI ::line ('Beginning import of: ' . $ composite ->title . ' id: ' . $ composite ->id );
0 commit comments