@ -99,14 +99,6 @@ export class Page extends Model {
from : 'pages.creatorId' ,
from : 'pages.creatorId' ,
to : 'users.id'
to : 'users.id'
}
}
} ,
locale : {
relation : Model . BelongsToOneRelation ,
modelClass : Locale ,
join : {
from : 'pages.localeCode' ,
to : 'locales.code'
}
}
}
}
}
}
}
@ -267,7 +259,7 @@ export class Page extends Model {
// -> Check for duplicate
// -> Check for duplicate
const dupCheck = await WIKI . db . pages . query ( ) . findOne ( {
const dupCheck = await WIKI . db . pages . query ( ) . findOne ( {
siteId : opts . siteId ,
siteId : opts . siteId ,
locale Code : opts . locale ,
locale : opts . locale ,
path : opts . path
path : opts . path
} ) . select ( 'id' )
} ) . select ( 'id' )
if ( dupCheck ) {
if ( dupCheck ) {
@ -345,7 +337,7 @@ export class Page extends Model {
icon : opts . icon ,
icon : opts . icon ,
isBrowsable : opts . isBrowsable ? ? true ,
isBrowsable : opts . isBrowsable ? ? true ,
isSearchable : opts . isSearchable ? ? true ,
isSearchable : opts . isSearchable ? ? true ,
locale Code : opts . locale ,
locale : opts . locale ,
ownerId : opts . user . id ,
ownerId : opts . user . id ,
path : opts . path ,
path : opts . path ,
publishState : opts . publishState ,
publishState : opts . publishState ,
@ -372,7 +364,7 @@ export class Page extends Model {
id : page . id ,
id : page . id ,
parentPath : initial ( pathParts ) . join ( '/' ) ,
parentPath : initial ( pathParts ) . join ( '/' ) ,
fileName : last ( pathParts ) ,
fileName : last ( pathParts ) ,
locale : page . locale Code ,
locale : page . locale ,
title : page . title ,
title : page . title ,
meta : {
meta : {
authorId : page . authorId ,
authorId : page . authorId ,
@ -401,7 +393,7 @@ export class Page extends Model {
// // -> Reconnect Links
// // -> Reconnect Links
// await WIKI.db.pages.reconnectLinks({
// await WIKI.db.pages.reconnectLinks({
// locale: page.locale Code ,
// locale: page.locale ,
// path: page.path,
// path: page.path,
// mode: 'create'
// mode: 'create'
// })
// })
@ -427,7 +419,7 @@ export class Page extends Model {
// -> Check for page access
// -> Check for page access
if ( ! WIKI . auth . checkAccess ( opts . user , [ 'write:pages' ] , {
if ( ! WIKI . auth . checkAccess ( opts . user , [ 'write:pages' ] , {
locale : ogPage . locale Code ,
locale : ogPage . locale ,
path : ogPage . path
path : ogPage . path
} ) ) {
} ) ) {
throw new Error ( 'ERR_PAGE_UPDATE_FORBIDDEN' )
throw new Error ( 'ERR_PAGE_UPDATE_FORBIDDEN' )
@ -596,7 +588,7 @@ export class Page extends Model {
// -> Format CSS Scripts
// -> Format CSS Scripts
if ( opts . patch . scriptCss ) {
if ( opts . patch . scriptCss ) {
if ( WIKI . auth . checkAccess ( opts . user , [ 'write:styles' ] , {
if ( WIKI . auth . checkAccess ( opts . user , [ 'write:styles' ] , {
locale : ogPage . locale Code ,
locale : ogPage . locale ,
path : ogPage . path
path : ogPage . path
} ) ) {
} ) ) {
patch . scripts = {
patch . scripts = {
@ -610,7 +602,7 @@ export class Page extends Model {
// -> Format JS Scripts
// -> Format JS Scripts
if ( opts . patch . scriptJsLoad ) {
if ( opts . patch . scriptJsLoad ) {
if ( WIKI . auth . checkAccess ( opts . user , [ 'write:scripts' ] , {
if ( WIKI . auth . checkAccess ( opts . user , [ 'write:scripts' ] , {
locale : ogPage . locale Code ,
locale : ogPage . locale ,
path : ogPage . path
path : ogPage . path
} ) ) {
} ) ) {
patch . scripts = {
patch . scripts = {
@ -622,7 +614,7 @@ export class Page extends Model {
}
}
if ( opts . patch . scriptJsUnload ) {
if ( opts . patch . scriptJsUnload ) {
if ( WIKI . auth . checkAccess ( opts . user , [ 'write:scripts' ] , {
if ( WIKI . auth . checkAccess ( opts . user , [ 'write:scripts' ] , {
locale : ogPage . locale Code ,
locale : ogPage . locale ,
path : ogPage . path
path : ogPage . path
} ) ) {
} ) ) {
patch . scripts = {
patch . scripts = {
@ -701,11 +693,11 @@ export class Page extends Model {
if ( ! id ) {
if ( ! id ) {
throw new Error ( 'Must provide either the page ID or the page object.' )
throw new Error ( 'Must provide either the page ID or the page object.' )
}
}
page = await WIKI . db . pages . query ( ) . findById ( id ) . select ( 'id' , 'locale Code ', 'render' , 'password' )
page = await WIKI . db . pages . query ( ) . findById ( id ) . select ( 'id' , 'locale ', 'render' , 'password' )
}
}
// -> Exclude password-protected content from being indexed
// -> Exclude password-protected content from being indexed
const safeContent = page . password ? '' : WIKI . db . pages . cleanHTML ( page . render )
const safeContent = page . password ? '' : WIKI . db . pages . cleanHTML ( page . render )
const dictName = getDictNameFromLocale ( page . locale Code )
const dictName = getDictNameFromLocale ( page . locale )
return WIKI . db . knex ( 'pages' ) . where ( 'id' , page . id ) . update ( {
return WIKI . db . knex ( 'pages' ) . where ( 'id' , page . id ) . update ( {
searchContent : safeContent ,
searchContent : safeContent ,
ts : WIKI . db . knex . raw ( `
ts : WIKI . db . knex . raw ( `
@ -747,7 +739,7 @@ export class Page extends Model {
// -> Check for page access
// -> Check for page access
if ( ! WIKI . auth . checkAccess ( opts . user , [ 'write:pages' ] , {
if ( ! WIKI . auth . checkAccess ( opts . user , [ 'write:pages' ] , {
locale : ogPage . locale Code ,
locale : ogPage . locale ,
path : ogPage . path
path : ogPage . path
} ) ) {
} ) ) {
throw new WIKI . Error . PageUpdateForbidden ( )
throw new WIKI . Error . PageUpdateForbidden ( )
@ -908,7 +900,7 @@ export class Page extends Model {
} else {
} else {
page = await WIKI . db . pages . query ( ) . findOne ( {
page = await WIKI . db . pages . query ( ) . findOne ( {
path : opts . path ,
path : opts . path ,
locale Code : opts . locale
locale : opts . locale
} )
} )
}
}
if ( ! page ) {
if ( ! page ) {
@ -932,7 +924,7 @@ export class Page extends Model {
// -> Check for source page access
// -> Check for source page access
if ( ! WIKI . auth . checkAccess ( opts . user , [ 'manage:pages' ] , {
if ( ! WIKI . auth . checkAccess ( opts . user , [ 'manage:pages' ] , {
locale : page . locale Code ,
locale : page . locale ,
path : page . path
path : page . path
} ) ) {
} ) ) {
throw new WIKI . Error . PageMoveForbidden ( )
throw new WIKI . Error . PageMoveForbidden ( )
@ -948,7 +940,7 @@ export class Page extends Model {
// -> Check for existing page at destination path
// -> Check for existing page at destination path
const destPage = await WIKI . db . pages . query ( ) . findOne ( {
const destPage = await WIKI . db . pages . query ( ) . findOne ( {
path : opts . destinationPath ,
path : opts . destinationPath ,
locale Code : opts . destinationLocale
locale : opts . destinationLocale
} )
} )
if ( destPage ) {
if ( destPage ) {
throw new WIKI . Error . PagePathCollision ( )
throw new WIKI . Error . PagePathCollision ( )
@ -967,7 +959,7 @@ export class Page extends Model {
const destinationTitle = ( page . title === page . path ? opts . destinationPath : page . title )
const destinationTitle = ( page . title === page . path ? opts . destinationPath : page . title )
await WIKI . db . pages . query ( ) . patch ( {
await WIKI . db . pages . query ( ) . patch ( {
path : opts . destinationPath ,
path : opts . destinationPath ,
locale Code : opts . destinationLocale ,
locale : opts . destinationLocale ,
title : destinationTitle ,
title : destinationTitle ,
hash : destinationHash
hash : destinationHash
} ) . findById ( page . id )
} ) . findById ( page . id )
@ -983,7 +975,7 @@ export class Page extends Model {
await WIKI . data . searchEngine . renamed ( {
await WIKI . data . searchEngine . renamed ( {
... page ,
... page ,
destinationPath : opts . destinationPath ,
destinationPath : opts . destinationPath ,
destinationLocale Code : opts . destinationLocale ,
destinationLocale : opts . destinationLocale ,
destinationHash
destinationHash
} )
} )
@ -994,7 +986,7 @@ export class Page extends Model {
page : {
page : {
... page ,
... page ,
destinationPath : opts . destinationPath ,
destinationPath : opts . destinationPath ,
destinationLocale Code : opts . destinationLocale ,
destinationLocale : opts . destinationLocale ,
destinationHash ,
destinationHash ,
moveAuthorId : opts . user . id ,
moveAuthorId : opts . user . id ,
moveAuthorName : opts . user . name ,
moveAuthorName : opts . user . name ,
@ -1005,7 +997,7 @@ export class Page extends Model {
// -> Reconnect Links : Changing old links to the new path
// -> Reconnect Links : Changing old links to the new path
await WIKI . db . pages . reconnectLinks ( {
await WIKI . db . pages . reconnectLinks ( {
sourceLocale : page . locale Code ,
sourceLocale : page . locale ,
sourcePath : page . path ,
sourcePath : page . path ,
locale : opts . destinationLocale ,
locale : opts . destinationLocale ,
path : opts . destinationPath ,
path : opts . destinationPath ,
@ -1066,7 +1058,7 @@ export class Page extends Model {
// -> Reconnect Links
// -> Reconnect Links
await WIKI . db . pages . reconnectLinks ( {
await WIKI . db . pages . reconnectLinks ( {
locale : page . locale Code ,
locale : page . locale ,
path : page . path ,
path : page . path ,
mode : 'delete'
mode : 'delete'
} )
} )
@ -1118,7 +1110,7 @@ export class Page extends Model {
. whereIn ( 'pages.id' , function ( ) {
. whereIn ( 'pages.id' , function ( ) {
this . select ( 'pageLinks.pageId' ) . from ( 'pageLinks' ) . where ( {
this . select ( 'pageLinks.pageId' ) . from ( 'pageLinks' ) . where ( {
'pageLinks.path' : opts . path ,
'pageLinks.path' : opts . path ,
'pageLinks.locale Code ': opts . locale
'pageLinks.locale ': opts . locale
} )
} )
} )
} )
affectedHashes = qryHashes . map ( h => h . hash )
affectedHashes = qryHashes . map ( h => h . hash )
@ -1131,7 +1123,7 @@ export class Page extends Model {
. whereIn ( 'pages.id' , function ( ) {
. whereIn ( 'pages.id' , function ( ) {
this . select ( 'pageLinks.pageId' ) . from ( 'pageLinks' ) . where ( {
this . select ( 'pageLinks.pageId' ) . from ( 'pageLinks' ) . where ( {
'pageLinks.path' : opts . path ,
'pageLinks.path' : opts . path ,
'pageLinks.locale Code ': opts . locale
'pageLinks.locale ': opts . locale
} )
} )
} )
} )
const qryHashes = await WIKI . db . pages . query ( )
const qryHashes = await WIKI . db . pages . query ( )
@ -1139,7 +1131,7 @@ export class Page extends Model {
. whereIn ( 'pages.id' , function ( ) {
. whereIn ( 'pages.id' , function ( ) {
this . select ( 'pageLinks.pageId' ) . from ( 'pageLinks' ) . where ( {
this . select ( 'pageLinks.pageId' ) . from ( 'pageLinks' ) . where ( {
'pageLinks.path' : opts . path ,
'pageLinks.path' : opts . path ,
'pageLinks.locale Code ': opts . locale
'pageLinks.locale ': opts . locale
} )
} )
} )
} )
affectedHashes = qryHashes . map ( h => h . hash )
affectedHashes = qryHashes . map ( h => h . hash )
@ -1227,20 +1219,18 @@ export class Page extends Model {
authorEmail : 'author.email' ,
authorEmail : 'author.email' ,
creatorName : 'creator.name' ,
creatorName : 'creator.name' ,
creatorEmail : 'creator.email'
creatorEmail : 'creator.email'
}
} ,
'tree.navigationId'
] )
] )
. joinRelated ( 'author' )
. joinRelated ( 'author' )
. joinRelated ( 'creator' )
. joinRelated ( 'creator' )
// .withGraphJoined('tags')
. leftJoin ( 'tree' , 'pages.id' , 'tree.id' )
// .modifyGraph('tags', builder => {
// builder.select('tag')
// })
. where ( queryModeID ? {
. where ( queryModeID ? {
'pages.id' : opts
'pages.id' : opts
} : {
} : {
'pages.siteId' : opts . siteId ,
'pages.siteId' : opts . siteId ,
'pages.path' : opts . path ,
'pages.path' : opts . path ,
'pages.locale Code ': opts . locale
'pages.locale ': opts . locale
} )
} )
// .andWhere(builder => {
// .andWhere(builder => {
// if (queryModeID) return
// if (queryModeID) return
@ -1307,7 +1297,7 @@ export class Page extends Model {
return {
return {
... page ,
... page ,
path : opts . path ,
path : opts . path ,
locale Code : opts . locale
locale : opts . locale
}
}
} catch ( err ) {
} catch ( err ) {
if ( err . code === 'ENOENT' ) {
if ( err . code === 'ENOENT' ) {
@ -1346,13 +1336,13 @@ export class Page extends Model {
static async migrateToLocale ( { sourceLocale , targetLocale } ) {
static async migrateToLocale ( { sourceLocale , targetLocale } ) {
return WIKI . db . pages . query ( )
return WIKI . db . pages . query ( )
. patch ( {
. patch ( {
locale Code : targetLocale
locale : targetLocale
} )
} )
. where ( {
. where ( {
locale Code : sourceLocale
locale : sourceLocale
} )
} )
. whereNotExists ( function ( ) {
. whereNotExists ( function ( ) {
this . select ( 'id' ) . from ( 'pages AS pagesm' ) . where ( 'pagesm.locale Code ', targetLocale ) . andWhereRaw ( 'pagesm.path = pages.path' )
this . select ( 'id' ) . from ( 'pages AS pagesm' ) . where ( 'pagesm.locale ', targetLocale ) . andWhereRaw ( 'pagesm.path = pages.path' )
} )
} )
}
}