Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
c5a45e57
You need to sign in or sign up before continuing.
Unverified
Commit
c5a45e57
authored
Sep 01, 2021
by
Eric Knibbe
Committed by
GitHub
Sep 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: git storage - handle renamed files & assets (#4307)
parent
9864be88
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
8 deletions
+51
-8
pages.js
server/models/pages.js
+12
-2
storage.js
server/modules/storage/git/storage.js
+39
-6
No files found.
server/models/pages.js
View file @
c5a45e57
...
@@ -650,7 +650,15 @@ module.exports = class Page extends Model {
...
@@ -650,7 +650,15 @@ module.exports = class Page extends Model {
* @returns {Promise} Promise with no value
* @returns {Promise} Promise with no value
*/
*/
static
async
movePage
(
opts
)
{
static
async
movePage
(
opts
)
{
const
page
=
await
WIKI
.
models
.
pages
.
query
().
findById
(
opts
.
id
)
let
page
if
(
_
.
has
(
opts
,
'id'
))
{
page
=
await
WIKI
.
models
.
pages
.
query
().
findById
(
opts
.
id
)
}
else
{
page
=
await
WIKI
.
models
.
pages
.
query
().
findOne
({
path
:
opts
.
path
,
localeCode
:
opts
.
locale
})
}
if
(
!
page
)
{
if
(
!
page
)
{
throw
new
WIKI
.
Error
.
PageNotFound
()
throw
new
WIKI
.
Error
.
PageNotFound
()
}
}
...
@@ -704,9 +712,11 @@ module.exports = class Page extends Model {
...
@@ -704,9 +712,11 @@ module.exports = class Page extends Model {
const
destinationHash
=
pageHelper
.
generateHash
({
path
:
opts
.
destinationPath
,
locale
:
opts
.
destinationLocale
,
privateNS
:
opts
.
isPrivate
?
'TODO'
:
''
})
const
destinationHash
=
pageHelper
.
generateHash
({
path
:
opts
.
destinationPath
,
locale
:
opts
.
destinationLocale
,
privateNS
:
opts
.
isPrivate
?
'TODO'
:
''
})
// -> Move page
// -> Move page
const
destinationTitle
=
(
page
.
title
===
page
.
path
?
opts
.
destinationPath
:
page
.
title
)
await
WIKI
.
models
.
pages
.
query
().
patch
({
await
WIKI
.
models
.
pages
.
query
().
patch
({
path
:
opts
.
destinationPath
,
path
:
opts
.
destinationPath
,
localeCode
:
opts
.
destinationLocale
,
localeCode
:
opts
.
destinationLocale
,
title
:
destinationTitle
,
hash
:
destinationHash
hash
:
destinationHash
}).
findById
(
page
.
id
)
}).
findById
(
page
.
id
)
await
WIKI
.
models
.
pages
.
deletePageFromCache
(
page
.
hash
)
await
WIKI
.
models
.
pages
.
deletePageFromCache
(
page
.
hash
)
...
@@ -775,7 +785,7 @@ module.exports = class Page extends Model {
...
@@ -775,7 +785,7 @@ module.exports = class Page extends Model {
})
})
}
}
if
(
!
page
)
{
if
(
!
page
)
{
throw
new
Error
(
'Invalid Page Id'
)
throw
new
WIKI
.
Error
.
PageNotFound
(
)
}
}
// -> Check for page access
// -> Check for page access
...
...
server/modules/storage/git/storage.js
View file @
c5a45e57
...
@@ -142,7 +142,9 @@ module.exports = {
...
@@ -142,7 +142,9 @@ module.exports = {
if
(
_
.
get
(
diff
,
'files'
,
[]).
length
>
0
)
{
if
(
_
.
get
(
diff
,
'files'
,
[]).
length
>
0
)
{
let
filesToProcess
=
[]
let
filesToProcess
=
[]
for
(
const
f
of
diff
.
files
)
{
for
(
const
f
of
diff
.
files
)
{
const
fPath
=
path
.
join
(
this
.
repoPath
,
f
.
file
)
const
fMoved
=
f
.
file
.
split
(
' => '
)
const
fName
=
fMoved
.
length
===
2
?
fMoved
[
1
]
:
fMoved
[
0
]
const
fPath
=
path
.
join
(
this
.
repoPath
,
fName
)
let
fStats
=
{
size
:
0
}
let
fStats
=
{
size
:
0
}
try
{
try
{
fStats
=
await
fs
.
stat
(
fPath
)
fStats
=
await
fs
.
stat
(
fPath
)
...
@@ -159,7 +161,8 @@ module.exports = {
...
@@ -159,7 +161,8 @@ module.exports = {
path
:
fPath
,
path
:
fPath
,
stats
:
fStats
stats
:
fStats
},
},
relPath
:
f
.
file
oldPath
:
fMoved
[
0
],
relPath
:
fName
})
})
}
}
await
this
.
processFiles
(
filesToProcess
,
rootUser
)
await
this
.
processFiles
(
filesToProcess
,
rootUser
)
...
@@ -174,11 +177,25 @@ module.exports = {
...
@@ -174,11 +177,25 @@ module.exports = {
async
processFiles
(
files
,
user
)
{
async
processFiles
(
files
,
user
)
{
for
(
const
item
of
files
)
{
for
(
const
item
of
files
)
{
const
contentType
=
pageHelper
.
getContentType
(
item
.
relPath
)
const
contentType
=
pageHelper
.
getContentType
(
item
.
relPath
)
const
fileExists
=
await
fs
.
pathExists
(
item
.
file
)
const
fileExists
=
await
fs
.
pathExists
(
item
.
file
.
path
)
if
(
!
item
.
binary
&&
contentType
)
{
if
(
!
item
.
binary
&&
contentType
)
{
// -> Page
// -> Page
if
(
!
fileExists
&&
item
.
deletions
>
0
&&
item
.
insertions
===
0
)
{
if
(
fileExists
&&
item
.
relPath
!==
item
.
oldPath
)
{
// Page was renamed by git, so rename in DB
WIKI
.
logger
.
info
(
`(STORAGE/GIT) Page marked as renamed: from
${
item
.
oldPath
}
to
${
item
.
relPath
}
`
)
const
contentPath
=
pageHelper
.
getPagePath
(
item
.
oldPath
)
const
contentDestinationPath
=
pageHelper
.
getPagePath
(
item
.
relPath
)
await
WIKI
.
models
.
pages
.
movePage
({
user
:
user
,
path
:
contentPath
.
path
,
destinationPath
:
contentDestinationPath
.
path
,
locale
:
contentPath
.
locale
,
destinationLocale
:
contentPath
.
locale
,
skipStorage
:
true
})
}
else
if
(
!
fileExists
&&
item
.
deletions
>
0
&&
item
.
insertions
===
0
)
{
// Page was deleted by git, can safely mark as deleted in DB
// Page was deleted by git, can safely mark as deleted in DB
WIKI
.
logger
.
info
(
`(STORAGE/GIT) Page marked as deleted:
${
item
.
relPath
}
`
)
WIKI
.
logger
.
info
(
`(STORAGE/GIT) Page marked as deleted:
${
item
.
relPath
}
`
)
...
@@ -207,7 +224,23 @@ module.exports = {
...
@@ -207,7 +224,23 @@ module.exports = {
}
else
{
}
else
{
// -> Asset
// -> Asset
if
(
!
fileExists
&&
((
item
.
before
>
0
&&
item
.
after
===
0
)
||
(
item
.
deletions
>
0
&&
item
.
insertions
===
0
)))
{
if
(
fileExists
&&
((
item
.
before
===
item
.
after
)
||
(
item
.
deletions
===
0
&&
item
.
insertions
===
0
)))
{
// Asset was renamed by git, so rename in DB
WIKI
.
logger
.
info
(
`(STORAGE/GIT) Asset marked as renamed: from
${
item
.
oldPath
}
to
${
item
.
relPath
}
`
)
const
fileHash
=
assetHelper
.
generateHash
(
item
.
relPath
)
const
assetToRename
=
await
WIKI
.
models
.
assets
.
query
().
findOne
({
hash
:
fileHash
})
if
(
assetToRename
)
{
await
WIKI
.
models
.
assets
.
query
().
patch
({
filename
:
item
.
relPath
,
hash
:
fileHash
}).
findById
(
assetToRename
.
id
)
await
assetToRename
.
deleteAssetCache
()
}
else
{
WIKI
.
logger
.
info
(
`(STORAGE/GIT) Asset was not found in the DB, nothing to rename:
${
item
.
relPath
}
`
)
}
continue
}
else
if
(
!
fileExists
&&
((
item
.
before
>
0
&&
item
.
after
===
0
)
||
(
item
.
deletions
>
0
&&
item
.
insertions
===
0
)))
{
// Asset was deleted by git, can safely mark as deleted in DB
// Asset was deleted by git, can safely mark as deleted in DB
WIKI
.
logger
.
info
(
`(STORAGE/GIT) Asset marked as deleted:
${
item
.
relPath
}
`
)
WIKI
.
logger
.
info
(
`(STORAGE/GIT) Asset marked as deleted:
${
item
.
relPath
}
`
)
...
@@ -419,7 +452,7 @@ module.exports = {
...
@@ -419,7 +452,7 @@ module.exports = {
transform
:
async
(
page
,
enc
,
cb
)
=>
{
transform
:
async
(
page
,
enc
,
cb
)
=>
{
const
pageObject
=
await
WIKI
.
models
.
pages
.
query
().
findById
(
page
.
id
)
const
pageObject
=
await
WIKI
.
models
.
pages
.
query
().
findById
(
page
.
id
)
page
.
tags
=
await
pageObject
.
$relatedQuery
(
'tags'
)
page
.
tags
=
await
pageObject
.
$relatedQuery
(
'tags'
)
let
fileName
=
`
${
page
.
path
}
.
${
pageHelper
.
getFileExtension
(
page
.
contentType
)}
`
let
fileName
=
`
${
page
.
path
}
.
${
pageHelper
.
getFileExtension
(
page
.
contentType
)}
`
if
(
WIKI
.
config
.
lang
.
namespacing
&&
WIKI
.
config
.
lang
.
code
!==
page
.
localeCode
)
{
if
(
WIKI
.
config
.
lang
.
namespacing
&&
WIKI
.
config
.
lang
.
code
!==
page
.
localeCode
)
{
fileName
=
`
${
page
.
localeCode
}
/
${
fileName
}
`
fileName
=
`
${
page
.
localeCode
}
/
${
fileName
}
`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment