|
|
@@ -1,77 +1,77 @@
|
|
1
|
|
-const { default: initModels } = require('./models/init-models')
|
|
|
1
|
+const { default: initModels } = require("./models/init-models");
|
|
2
|
2
|
|
|
3
|
3
|
module.exports = {
|
|
4
|
|
- /**
|
|
5
|
|
- * Grabs the actual row information as JSON
|
|
6
|
|
- * and packs it up into an array
|
|
7
|
|
- *
|
|
8
|
|
- * @param {array} postList
|
|
9
|
|
- * @param {string} typeToFind
|
|
10
|
|
- * @returns array
|
|
11
|
|
- */
|
|
12
|
|
- getPostData: (postList, typeToFind) => {
|
|
13
|
|
- return postList.reduce((data, post) => {
|
|
14
|
|
- /**
|
|
15
|
|
- * Double-check our post matches the type
|
|
16
|
|
- */
|
|
17
|
|
- if(typeToFind && post.dataValues.post_type != typeToFind) {
|
|
18
|
|
- return data
|
|
19
|
|
- }
|
|
|
4
|
+ /**
|
|
|
5
|
+ * Grabs the actual row information as JSON
|
|
|
6
|
+ * and packs it up into an array
|
|
|
7
|
+ *
|
|
|
8
|
+ * @param {array} postList
|
|
|
9
|
+ * @param {string} typeToFind
|
|
|
10
|
+ * @returns array
|
|
|
11
|
+ */
|
|
|
12
|
+ getPostData: (postList, typeToFind) => {
|
|
|
13
|
+ return postList.reduce((data, post) => {
|
|
|
14
|
+ /**
|
|
|
15
|
+ * Double-check our post matches the type
|
|
|
16
|
+ */
|
|
|
17
|
+ if (typeToFind && post.dataValues.post_type != typeToFind) {
|
|
|
18
|
+ return data;
|
|
|
19
|
+ }
|
|
20
|
20
|
|
|
21
|
|
- /**
|
|
22
|
|
- * ONLY add matching postData to our data array
|
|
23
|
|
- * and omit all the extra sequelize meta data
|
|
24
|
|
- * by pushing the dataValues key
|
|
25
|
|
- */
|
|
26
|
|
- data.push(post.dataValues)
|
|
27
|
|
- return data
|
|
28
|
|
- }, [])
|
|
29
|
|
- },
|
|
|
21
|
+ /**
|
|
|
22
|
+ * ONLY add matching postData to our data array
|
|
|
23
|
+ * and omit all the extra sequelize meta data
|
|
|
24
|
+ * by pushing the dataValues key
|
|
|
25
|
+ */
|
|
|
26
|
+ data.push(post.dataValues);
|
|
|
27
|
+ return data;
|
|
|
28
|
+ }, []);
|
|
|
29
|
+ },
|
|
30
|
30
|
|
|
31
|
|
- /**
|
|
32
|
|
- * Helper to find post descendants
|
|
33
|
|
- *
|
|
34
|
|
- * @param {array} parentList
|
|
35
|
|
- * @param {object} db - sequelize instance
|
|
36
|
|
- * @param {function} getParams - lambda returning param object { rule: 'example' }
|
|
37
|
|
- * @returns array
|
|
38
|
|
- */
|
|
39
|
|
- findDescendants: async (parentList, db, getParams) => {
|
|
40
|
|
- const matchList = []
|
|
41
|
|
- for(let post of parentList) {
|
|
42
|
|
- const match = await db.findAll({ where: getParams(post) })
|
|
43
|
|
- match.forEach(entity => matchList.push(entity))
|
|
44
|
|
- }
|
|
45
|
|
- return matchList
|
|
46
|
|
- },
|
|
|
31
|
+ /**
|
|
|
32
|
+ * Helper to find post descendants
|
|
|
33
|
+ *
|
|
|
34
|
+ * @param {array} parentList
|
|
|
35
|
+ * @param {object} db - sequelize instance
|
|
|
36
|
+ * @param {function} getParams - lambda returning param object { rule: 'example' }
|
|
|
37
|
+ * @returns array
|
|
|
38
|
+ */
|
|
|
39
|
+ findDescendants: async (parentList, db, getParams) => {
|
|
|
40
|
+ const matchList = [];
|
|
|
41
|
+ for (let post of parentList) {
|
|
|
42
|
+ const match = await db.findAll({ where: getParams(post) });
|
|
|
43
|
+ match.forEach((entity) => matchList.push(entity));
|
|
|
44
|
+ }
|
|
|
45
|
+ return matchList;
|
|
|
46
|
+ },
|
|
47
|
47
|
|
|
48
|
|
- /**
|
|
49
|
|
- * The keys we want from the postmeta table
|
|
50
|
|
- */
|
|
51
|
|
- metakeys: [
|
|
52
|
|
- '_wp_attached_file',
|
|
53
|
|
- '_wp_attachment_metadata',
|
|
54
|
|
- '_thumbnail_id',
|
|
55
|
|
- ...process.env.METAKEYS
|
|
56
|
|
- ],
|
|
|
48
|
+ /**
|
|
|
49
|
+ * The keys we want from the postmeta table
|
|
|
50
|
+ */
|
|
|
51
|
+ metakeys: [
|
|
|
52
|
+ "_wp_attached_file",
|
|
|
53
|
+ "_wp_attachment_metadata",
|
|
|
54
|
+ "_thumbnail_id",
|
|
|
55
|
+ ...JSON.parse(process.env.METAKEYS),
|
|
|
56
|
+ ],
|
|
57
|
57
|
|
|
58
|
|
- /**
|
|
59
|
|
- * The post type names we're interested in
|
|
60
|
|
- *
|
|
61
|
|
- * 1. Status types we migrate
|
|
62
|
|
- */
|
|
63
|
|
- types: {
|
|
64
|
|
- ...process.env.POST_TYPES,
|
|
65
|
|
- /* 1 */
|
|
66
|
|
- status: ['publish']
|
|
67
|
|
- },
|
|
|
58
|
+ /**
|
|
|
59
|
+ * The post type names we're interested in
|
|
|
60
|
+ *
|
|
|
61
|
+ * 1. Status types we migrate
|
|
|
62
|
+ */
|
|
|
63
|
+ types: {
|
|
|
64
|
+ ...JSON.parse(process.env.POST_TYPES),
|
|
|
65
|
+ /* 1 */
|
|
|
66
|
+ status: ["publish"],
|
|
|
67
|
+ },
|
|
68
|
68
|
|
|
69
|
|
- /**
|
|
70
|
|
- * dB creation helper
|
|
71
|
|
- * !: Don't touch
|
|
72
|
|
- *
|
|
73
|
|
- * @param {object} models - sequelize instance
|
|
74
|
|
- * @returns object - all models associated with instance
|
|
75
|
|
- */
|
|
76
|
|
- db: models => initModels(models),
|
|
77
|
|
-}
|
|
|
69
|
+ /**
|
|
|
70
|
+ * dB creation helper
|
|
|
71
|
+ * !: Don't touch
|
|
|
72
|
+ *
|
|
|
73
|
+ * @param {object} models - sequelize instance
|
|
|
74
|
+ * @returns object - all models associated with instance
|
|
|
75
|
+ */
|
|
|
76
|
+ db: (models) => initModels(models),
|
|
|
77
|
+};
|