-
Notifications
You must be signed in to change notification settings - Fork 322
/
Copy pathdrupal8.rb
65 lines (55 loc) · 1.86 KB
/
drupal8.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
require "jekyll-import/importers/drupal_common"
module JekyllImport
module Importers
class Drupal8 < Importer
include DrupalCommon
extend DrupalCommon::ClassMethods
def self.build_query(prefix, types, engine)
types = types.join("' OR n.type = '")
types = "n.type = '#{types}'"
tag_group = if engine == "postgresql"
<<POSTGRESQL
(SELECT STRING_AGG(td.name, '|')
FROM #{prefix}taxonomy_term_field_data td, #{prefix}taxonomy_index ti
WHERE ti.tid = td.tid AND ti.nid = n.nid) AS tags
POSTGRESQL
else
<<SQL
(SELECT GROUP_CONCAT(td.name SEPARATOR '|')
FROM #{prefix}taxonomy_term_field_data td, #{prefix}taxonomy_index ti
WHERE ti.tid = td.tid AND ti.nid = n.nid) AS 'tags'
SQL
end
query = <<QUERY
SELECT n.nid,
n.title,
nb.body_value,
nb.body_summary,
n.created,
n.status,
n.type,
#{tag_group}
FROM #{prefix}node_field_data AS n
LEFT JOIN #{prefix}node__body AS nb
ON nb.entity_id = n.nid
WHERE (#{types})
QUERY
query
end
def self.aliases_query(prefix)
"SELECT source, alias FROM #{prefix}url_alias WHERE source = ?"
end
def self.post_data(sql_post_data)
content = sql_post_data[:body_value].to_s
summary = sql_post_data[:body_summary].to_s
tags = (sql_post_data[:tags] || "").downcase.strip
data = {
"excerpt" => summary,
"categories" => tags.split("|"),
}
[data, content]
end
end
end
end