Skip to content

Commit f194d4a

Browse files
committed
chore(data): add json data from database
1 parent df685ce commit f194d4a

File tree

12 files changed

+958442
-0
lines changed

12 files changed

+958442
-0
lines changed

dump/database/options.csv

Lines changed: 1449 additions & 0 deletions
Large diffs are not rendered by default.

dump/database/postmeta.csv

Lines changed: 68371 additions & 0 deletions
Large diffs are not rendered by default.

dump/database/posts.csv

Lines changed: 21471 additions & 0 deletions
Large diffs are not rendered by default.

dump/json/options.json

Lines changed: 1028 additions & 0 deletions
Large diffs are not rendered by default.

dump/json/postmeta.json

Lines changed: 410228 additions & 0 deletions
Large diffs are not rendered by default.

dump/json/posts.json

Lines changed: 455602 additions & 0 deletions
Large diffs are not rendered by default.

dump/modify/convertToJSON.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
const files = [
5+
{
6+
filename: 'options',
7+
columns: {
8+
option_id: 'number',
9+
option_name: 'string',
10+
option_value: 'string',
11+
autoload: 'string'
12+
}
13+
},
14+
{
15+
filename: 'postmeta',
16+
columns: {
17+
meta_id: 'number',
18+
post_id: 'number',
19+
meta_key: 'string',
20+
meta_value: 'string'
21+
}
22+
},
23+
{
24+
filename: 'posts',
25+
columns: {
26+
ID: 'number',
27+
post_author: 'number',
28+
post_date: 'string',
29+
post_date_gmt: 'string',
30+
post_content: 'string',
31+
post_title: 'string',
32+
post_excerpt: 'string',
33+
post_status: 'string',
34+
comment_status: 'string',
35+
ping_status: 'string',
36+
post_password: 'string',
37+
post_name: 'string',
38+
to_ping: 'string',
39+
pinged: 'string',
40+
post_modified: 'number',
41+
post_modified_gmt: 'number',
42+
post_content_filtered: 'string',
43+
post_parent: 'number',
44+
guid: 'string',
45+
menu_order: 'number',
46+
post_type: 'string',
47+
post_mime_type: 'string',
48+
comment_count: 'number'
49+
}
50+
}
51+
]
52+
53+
files.forEach(async ({ filename, columns }) => {
54+
const data = await fs.promises.readFile(
55+
path.join(__dirname, '../database/', `${filename}.csv`),
56+
'utf8'
57+
)
58+
59+
// Remove last empty line
60+
const lines = data.trim().split(/(?<![\\\n])\r?\n/)
61+
62+
const json = lines.map((line, lineNum) => {
63+
const values = line.split(',,,,,')
64+
const obj = {}
65+
let i = 0
66+
for (const [key, type] of Object.entries(columns)) {
67+
const value = values[i++]
68+
if (value === '\\N') {
69+
obj[key] = null
70+
} else if (type === 'number') {
71+
obj[key] = !Number.isNaN(value) ? Number(value) : null
72+
} else if (type === 'string') {
73+
if (!value) {
74+
console.log(`undefined in ${filename} for ${key} in line ${lineNum}`)
75+
}
76+
obj[key] = value ? value.replace(/^"([^]*)"$/, '$1') : ''
77+
}
78+
}
79+
return obj
80+
})
81+
82+
return fs.promises.writeFile(
83+
path.join(__dirname, '../json', `${filename}.json`),
84+
JSON.stringify(json, null, 2)
85+
)
86+
})

dump/modify/modifyAttachments.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const attachments = require('../json/attachment.json')
4+
const newAttachments = []
5+
6+
attachments
7+
.filter((attachment) => {
8+
return fs.existsSync(
9+
path.join(
10+
__dirname,
11+
'../..',
12+
'raw-attachment/ticket',
13+
attachment.id,
14+
attachment.filename
15+
)
16+
)
17+
})
18+
.forEach((attachment) => {
19+
for (const key in attachment) {
20+
if (attachment[key] === '""' || attachment[key] == null) {
21+
attachment[key] = ''
22+
}
23+
// Replace escaped quotes with real quotes
24+
if (typeof attachment[key] === 'string') {
25+
attachment[key] = attachment[key].replace(/\\"/g, '"')
26+
}
27+
// Make IDs numbers
28+
if (key === 'id') {
29+
if (isNaN(attachment[key])) {
30+
throw new Error(`Attachment ID ${attachment[key]} is not a number`)
31+
}
32+
attachment[key] = parseInt(attachment[key])
33+
}
34+
}
35+
newAttachments.push(attachment)
36+
})
37+
38+
console.log('Original length: ', attachments.length)
39+
console.log('New length: ', newAttachments.length)
40+
41+
fs.promises
42+
.writeFile(
43+
path.join(__dirname, 'attachments.json'),
44+
JSON.stringify(newAttachments, null, 2)
45+
)
46+
.catch((err) => console.error(err))

dump/modify/modifyChanges.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const changes = require('../json/ticket_change.json')
4+
5+
const ticketChanges = []
6+
changes.forEach((change) => {
7+
for (const key in change) {
8+
if (change[key] === '""' || change[key] == null) {
9+
change[key] = ''
10+
}
11+
// Replace escaped quotes with real quotes
12+
if (typeof change[key] === 'string') {
13+
change[key] = change[key].replace(/\\"/g, '"')
14+
}
15+
}
16+
if (change.oldvalue !== change.newvalue) {
17+
const prevChange = ticketChanges[ticketChanges.length - 1]
18+
if (prevChange && prevChange.time === change.time) {
19+
prevChange.fields.push({
20+
field: change.field,
21+
oldvalue: change.oldvalue,
22+
newvalue: change.newvalue
23+
})
24+
} else {
25+
ticketChanges.push({
26+
ticket: change.ticket,
27+
time: change.time,
28+
author: change.author,
29+
fields: [
30+
{
31+
field: change.field,
32+
oldvalue: change.oldvalue,
33+
newvalue: change.newvalue
34+
}
35+
]
36+
})
37+
}
38+
}
39+
})
40+
41+
fs.promises
42+
.writeFile(
43+
path.join(__dirname, 'changes.json'),
44+
JSON.stringify(ticketChanges, null, 2)
45+
)
46+
.catch((err) => console.error(err))

dump/modify/modifyMilestones.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const milestones = require('../json/milestone.json')
4+
const tickets = require('../json/ticket.json')
5+
6+
milestones.forEach((milestone) => {
7+
for (const key in milestone) {
8+
if (milestone[key] === '""' || milestone[key] == null) {
9+
milestone[key] = ''
10+
}
11+
// Replace escaped quotes with real quotes
12+
if (typeof milestone[key] === 'string') {
13+
milestone[key] = milestone[key].replace(/\\"/g, '"')
14+
}
15+
}
16+
const milestoneTickets = tickets.filter(
17+
(ticket) => ticket.milestone === milestone.name
18+
)
19+
milestone.total = milestoneTickets.length
20+
milestone.closed = milestoneTickets.filter(
21+
(ticket) => ticket.status === 'closed'
22+
).length
23+
// 0 and 0 should be 100% not 0%
24+
milestone.percent = milestone.closed === milestone.total ? 100 : Math.round((milestone.closed / milestone.total) * 100) || 0
25+
})
26+
27+
milestones.sort((a, b) => {
28+
if (!a.completed && b.completed) {
29+
return 1
30+
}
31+
if (a.completed && !b.completed) {
32+
return -1
33+
}
34+
return a.completed - b.completed
35+
})
36+
37+
fs.promises
38+
.writeFile(
39+
path.join(__dirname, 'milestones.json'),
40+
JSON.stringify(milestones, null, 2)
41+
)
42+
.catch((err) => console.error(err))

0 commit comments

Comments
 (0)