HandlerPageEdit: Support for renaming and visibility settings
This commit is contained in:
		| @@ -45,9 +45,11 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename, | |||||||
| 	auto revision = this->database->createRevisionDao()->getCurrentForPage(pagename); | 	auto revision = this->database->createRevisionDao()->getCurrentForPage(pagename); | ||||||
| 	std::string body; | 	std::string body; | ||||||
|  |  | ||||||
|  | 	unsigned int current_revision = 0; | ||||||
| 	if(revision) | 	if(revision) | ||||||
| 	{ | 	{ | ||||||
| 		body = revision->content; | 		body = revision->content; | ||||||
|  | 		current_revision = revision->revision; | ||||||
| 	} | 	} | ||||||
| 	if(r.getRequestMethod() == "POST") | 	if(r.getRequestMethod() == "POST") | ||||||
| 	{ | 	{ | ||||||
| @@ -56,12 +58,6 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename, | |||||||
| 			std::string newContent = r.post("content"); | 			std::string newContent = r.post("content"); | ||||||
| 			std::string newComment = r.post("comment"); | 			std::string newComment = r.post("comment"); | ||||||
|  |  | ||||||
| 			Revision newRevision; |  | ||||||
| 			newRevision.author = this->userSession->user.login; |  | ||||||
| 			newRevision.comment = newComment; |  | ||||||
| 			newRevision.page = pagename; |  | ||||||
| 			newRevision.content = newContent; |  | ||||||
|  |  | ||||||
|  |  | ||||||
| 			//TODO: must check, whether categories differ, and perhaps don't allow every user | 			//TODO: must check, whether categories differ, and perhaps don't allow every user | ||||||
| 			//to set categories | 			//to set categories | ||||||
| @@ -70,15 +66,33 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename, | |||||||
| 			try | 			try | ||||||
| 			{ | 			{ | ||||||
| 				this->database->beginTransaction(); | 				this->database->beginTransaction(); | ||||||
| 				if(!pageexists) | 				std::string visiblecmd = parser.extractCommand("visible", newContent); | ||||||
|  | 				std::string rename = parser.extractCommand("rename", newContent); | ||||||
|  | 				Page page; | ||||||
|  | 				std::optional<Page> currentPage = pageDao.find(pagename); | ||||||
|  | 				if(currentPage) | ||||||
| 				{ | 				{ | ||||||
| 					Page newPage; | 					page = *currentPage; | ||||||
| 					newPage.current_revision = 0; |  | ||||||
| 					newPage.listed = true; |  | ||||||
| 					newPage.name = pagename; |  | ||||||
| 					pageDao.save(newPage); |  | ||||||
|  |  | ||||||
| 				} | 				} | ||||||
|  | 				if(rename != "") | ||||||
|  | 				{ | ||||||
|  | 					if(newComment == "") | ||||||
|  | 					{ | ||||||
|  | 						newComment = "(renamed) from " + pagename + " to " + rename; | ||||||
|  | 					} | ||||||
|  | 					pagename = rename; | ||||||
|  | 				} | ||||||
|  | 				page.current_revision = current_revision; | ||||||
|  | 				page.listed = ! (visiblecmd == "0"); | ||||||
|  | 				page.name = pagename; | ||||||
|  | 				pageDao.save(page); | ||||||
|  |  | ||||||
|  | 				Revision newRevision; | ||||||
|  | 				newRevision.author = this->userSession->user.login; | ||||||
|  | 				newRevision.comment = newComment; | ||||||
|  | 				newRevision.page = pagename; | ||||||
|  | 				newRevision.content = newContent; | ||||||
|  |  | ||||||
| 				revisiondao->save(newRevision); | 				revisiondao->save(newRevision); | ||||||
| 				pageDao.setCategories(pagename, cats); | 				pageDao.setCategories(pagename, cats); | ||||||
| 				this->database->commitTransaction(); | 				this->database->commitTransaction(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user