@kohanajs/mod-cms
Advanced tools
Comparing version 4.2.1 to 5.0.0
@@ -5,2 +5,13 @@ # Changelog | ||
## [5.0.0](https://gitlab.com/kohana-js/proposals/level0/mod-cms/compare/v4.2.1...v5.0.0) (2022-01-27) | ||
### ⚠ BREAKING CHANGES | ||
* API, Page reference, Tags | ||
### Features | ||
* API, Page reference, Tags ([8f14295](https://gitlab.com/kohana-js/proposals/level0/mod-cms/commit/8f142953c15d9db5b82eff29891a89da9e65ebfd)) | ||
### [4.2.1](https://gitlab.com/kohana-js/proposals/level0/mod-cms/compare/v4.2.0...v4.2.1) (2021-11-30) | ||
@@ -7,0 +18,0 @@ |
@@ -10,3 +10,3 @@ const path = require('path'); | ||
const HelperPage = require('../../helper/Page'); | ||
const HelperPage = KohanaJS.require('helper/Page'); | ||
@@ -18,3 +18,2 @@ class ControllerAdminContent extends ControllerAdmin{ | ||
['draft', `${KohanaJS.EXE_PATH}/../database/content.sqlite`], | ||
['pagetype', `${KohanaJS.EXE_PATH}/../database/pagetype.sqlite`], | ||
]), | ||
@@ -26,4 +25,2 @@ orderBy: new Map([['weight', 'ASC'], ['created_at', 'DESC']]), | ||
['index', 'templates/admin/contents/index'], | ||
['edit', 'templates/admin/contents/edit'], | ||
['read', 'templates/admin/contents/read'], | ||
]), | ||
@@ -74,3 +71,3 @@ ...options, | ||
const page = ORM.create(Page, {database, insertID}); | ||
page.name = `Untitled ${pluralize.singular(page_type)}`; | ||
page.name = `Untitled ${pluralize.singular(page_type.replace(/[_-]/gi, ' '))}`; | ||
page.page_type = page_type; | ||
@@ -77,0 +74,0 @@ page.slug = String(insertID); |
const {SQL} = require("@kohanajs/constants"); | ||
const path = require('path'); | ||
const {unlink} = require('fs/promises'); | ||
@@ -8,3 +9,3 @@ const { ControllerAdmin } = require('@kohanajs/mod-admin'); | ||
const { ControllerMixinMultipartForm, HelperForm } = require('@kohanajs/mod-form'); | ||
const HelperPage = require('../../helper/Page'); | ||
const HelperPage = KohanaJS.require('helper/Page'); | ||
@@ -38,3 +39,3 @@ const Page = ORM.require('Page'); | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
const language = await ORM.readBy(Language, 'name', [ this.language ], {database, limit:1 }); | ||
const language = await ORM.readBy(Language, 'code', [ this.language ], {database, limit:1 }); | ||
this.languageId = language.id; | ||
@@ -59,6 +60,7 @@ } | ||
const instance = await ORM.factory(ORM.require(Model), id, {database}); | ||
if(/^\/media\/cms/.test(instance.value)){ | ||
const ins = await ORM.factory(ORM.require(Model), id, {database}); | ||
if(/^\/media\/cms/.test(ins.value)){ | ||
try{ | ||
await unlink(path.normalize(`${KohanaJS.EXE_PATH}/../public${instance.value}`)); | ||
await unlink(path.normalize(`${KohanaJS.EXE_PATH}/../public${ins.value}`)); | ||
}catch(e){ | ||
@@ -68,4 +70,4 @@ console.log(e); | ||
} | ||
instance.value = await HelperForm.moveToUpload($_POST[key], '/media/cms', `${KohanaJS.EXE_PATH}/../public`); | ||
await instance.write(); | ||
ins.value = await HelperForm.moveToUpload($_POST[key], '/media/cms', `${KohanaJS.EXE_PATH}/../public`); | ||
await ins.write(); | ||
} | ||
@@ -104,2 +106,9 @@ }) | ||
async unpublish(id, database){ | ||
const existPages = await ORM.readBy(Page, 'id', [id], {database, asArray:true}); | ||
if(existPages.length > 0){ | ||
await Promise.all(existPages.map(async it => it.delete())); | ||
} | ||
} | ||
async publish(page){ | ||
@@ -112,4 +121,3 @@ //create version. | ||
//check page exist, remove it. | ||
const exist = await ORM.factory(Page, page.id, {database}); | ||
if(exist)await exist.delete(); | ||
await this.unpublish(page.id, database); | ||
@@ -146,30 +154,13 @@ const livePage = ORM.create(Page, {database, insertID: page.id}); | ||
} | ||
page.publish = true; | ||
await page.write(); | ||
} | ||
async unpublish(){ | ||
async action_unpublish(){ | ||
const id = this.request.params['id']; | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('live'); | ||
try{ | ||
const exist = await ORM.factory(Page, id,{database}); | ||
await exist.delete(); | ||
} catch (e){ | ||
} | ||
await this.unpublish(id, this.state.get(ControllerMixinDatabase.DATABASES).get('live')); | ||
await this.redirect(`/admin/pages/${id}?language=${this.language}`); | ||
} | ||
async action_unpublish(){ | ||
await this.unpublish(); | ||
setEditTemplate(page, livePage=null, placeholders = {}){ | ||
const editTemplateFolder = page.page_type ?? 'default'; | ||
const draftDB = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
const page = await ORM.factory(Page, id, {database: draftDB}); | ||
page.publish = false; | ||
await page.write(); | ||
await this.redirect(`/admin/pages/${id}?language=${this.language}`); | ||
} | ||
setEditTemplate(page, placeholders = {}){ | ||
const templateData = this.state.get(ControllerMixinView.TEMPLATE).data; | ||
@@ -185,4 +176,7 @@ | ||
templateData.autosave = this.request.session.autosave; | ||
templateData.published = !!livePage; | ||
templateData.sync = page.updated_at === livePage?.updated_at; | ||
templateData.page_type = page.page_type; | ||
templateData.page_type_name = page.page_type; | ||
const editTemplateFolder = page.page_type ?? 'default'; | ||
this.setTemplate(`templates/admin/page/page_types/${editTemplateFolder.toLowerCase()}/edit`, templateData); | ||
@@ -253,3 +247,3 @@ } | ||
async pageEagerLoad(){ | ||
async action_create(){ | ||
const page = this.state.get('instance'); | ||
@@ -264,7 +258,4 @@ | ||
}); | ||
return page; | ||
} | ||
async action_create(){ | ||
this.setEditTemplate(await this.pageEagerLoad()); | ||
this.setEditTemplate(page, false, {}); | ||
} | ||
@@ -276,3 +267,6 @@ | ||
const database = this.state.get(ControllerMixinDatabase.DATABASES).get('draft'); | ||
const masterLanguage = await ORM.readBy(Language, 'name', [KohanaJS.config.cms.defaultLanguage], {database, limit:1 }); | ||
const liveDatabase = this.state.get(ControllerMixinDatabase.DATABASES).get('live'); | ||
const livePages = await ORM.readBy(Page, 'id', [page.id], {database: liveDatabase, limit:1, asArray:true}); | ||
const masterLanguage = await ORM.readBy(Language, 'code', [KohanaJS.config.cms.defaultLanguage], {database, limit:1 }); | ||
const masterLanguageId = masterLanguage.id; | ||
@@ -290,3 +284,3 @@ | ||
this.setEditTemplate(page, placeholders); | ||
this.setEditTemplate(page, livePages[0], placeholders); | ||
} | ||
@@ -300,5 +294,5 @@ | ||
if(this.state.get(ControllerMixinORMDelete.DELETED)){ | ||
await this.unpublish(); | ||
const page = this.state.get(ControllerMixinORMDelete.INSTANCE); | ||
await this.unpublish(page.id, this.state.get(ControllerMixinDatabase.DATABASES).get('live')); | ||
//redirect to page type index | ||
const page = this.state.get(ControllerMixinORMDelete.INSTANCE); | ||
await this.redirect(`/admin/contents/list/${page.page_type}`); | ||
@@ -305,0 +299,0 @@ } |
@@ -6,3 +6,2 @@ const {ORM} = require('kohanajs'); | ||
slug = null; | ||
publish = false; | ||
weight = 5; | ||
@@ -20,3 +19,2 @@ start = null; | ||
["slug", "String!"], | ||
["publish", "Boolean"], | ||
["weight", "Int"], | ||
@@ -29,2 +27,3 @@ ["start", "Date"], | ||
static hasMany = [ | ||
["page_id", "PageTag"], | ||
["page_id", "PageAttribute"], | ||
@@ -35,7 +34,4 @@ ["page_id", "PageValue"], | ||
]; | ||
static belongsToMany = new Set([ | ||
"Tag" | ||
]); | ||
} | ||
module.exports = Page; |
@@ -16,4 +16,7 @@ const {ORM} = require('kohanajs'); | ||
]); | ||
static hasMany = [ | ||
["tag_id", "TagTranslate"] | ||
]; | ||
} | ||
module.exports = Tag; |
@@ -18,3 +18,2 @@ const {KohanaJS} = require('kohanajs') | ||
RouteList.add('/admin/pages/un-publish/:id', 'controller/admin/Page', 'unpublish'); | ||
RouteCRUD.add('pages', 'controller/admin/Page'); | ||
@@ -24,1 +23,8 @@ RouteList.add('/admin/contents/list/:page_type', 'controller/admin/Content'); | ||
RouteList.add('/admin/api/page-items/:page_type/:item', 'controller/admin/API', 'page_items'); | ||
RouteList.add('/admin/api/pages/:page_type', 'controller/admin/API', 'pages'); | ||
RouteList.add('/admin/api', 'controller/admin/API'); | ||
RouteCRUD.add('pages', 'controller/admin/Page'); | ||
RouteCRUD.add('tag_types', 'controller/admin/TagType'); | ||
RouteCRUD.add('tags', 'controller/admin/Tag'); |
{ | ||
"name": "@kohanajs/mod-cms", | ||
"version": "4.2.1", | ||
"version": "5.0.0", | ||
"description": "The CMS module for KohanaJS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48677
29
1097
2