chg: refactored site deletion with sql
This commit is contained in:
parent
70d8c67f07
commit
5683b35d12
3 changed files with 54 additions and 32 deletions
|
@ -108,7 +108,8 @@ HopObject.prototype.onRequest = function() {
|
||||||
User.autoLogin();
|
User.autoLogin();
|
||||||
res.handlers.membership = User.getMembership();
|
res.handlers.membership = User.getMembership();
|
||||||
|
|
||||||
if (session.user && !session.user.deleted && session.user.status === User.DELETED) {
|
// Logout persisting session if account has been deleted
|
||||||
|
if (User.getCurrentStatus() === User.DELETED && !session.user.deleted) {
|
||||||
User.logout();
|
User.logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,20 +122,22 @@ HopObject.prototype.onRequest = function() {
|
||||||
res.stop();
|
res.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulate 404 for sites which are due for deletion by cronjob
|
if (!User.require(User.PRIVILEGED)) {
|
||||||
if (res.handlers.site.mode === Site.DELETED && !User.require(User.PRIVILEGED) && !Membership.require(Membership.OWNER)) {
|
// Simulate 404 for sites which are due for deletion by cronjob
|
||||||
res.handlers.site = root;
|
if (res.handlers.site.mode === Site.DELETED) {
|
||||||
root.notfound_action();
|
res.handlers.site = root;
|
||||||
res.stop();
|
root.notfound_action();
|
||||||
}
|
res.stop();
|
||||||
|
}
|
||||||
|
|
||||||
if (res.handlers.site.status === Site.BLOCKED && !User.require(User.PRIVILEGED)) {
|
if (res.handlers.site.status === Site.BLOCKED) {
|
||||||
res.status = 403;
|
res.status = 403;
|
||||||
res.handlers.site = root;
|
res.handlers.site = root;
|
||||||
res.data.error = gettext('The site you requested has been blocked.') +
|
res.data.error = gettext('The site you requested has been blocked.') +
|
||||||
String.SPACE + gettext('Please contact an administrator for further information.');
|
String.SPACE + gettext('Please contact an administrator for further information.');
|
||||||
root.error_action();
|
root.error_action();
|
||||||
res.stop();
|
res.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HopObject.confirmConstructor(Layout);
|
HopObject.confirmConstructor(Layout);
|
||||||
|
@ -178,8 +181,9 @@ HopObject.prototype.delete_action = function() {
|
||||||
if (req.postParams.proceed) {
|
if (req.postParams.proceed) {
|
||||||
try {
|
try {
|
||||||
var parent = this._parent;
|
var parent = this._parent;
|
||||||
|
var type = this._prototype;
|
||||||
var url = this.constructor.remove.call(this, req.postParams) || parent.href();
|
var url = this.constructor.remove.call(this, req.postParams) || parent.href();
|
||||||
res.message = gettext('{0} was successfully deleted.', gettext(this._prototype));
|
res.message = gettext('{0} was successfully deleted.', gettext(type));
|
||||||
res.redirect(User.getLocation() || url);
|
res.redirect(User.getLocation() || url);
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
res.message = ex;
|
res.message = ex;
|
||||||
|
|
|
@ -45,12 +45,12 @@ HopObject.prototype.handleMetadata = function(name) {
|
||||||
*/
|
*/
|
||||||
HopObject.prototype.getMetadata = function(name) {
|
HopObject.prototype.getMetadata = function(name) {
|
||||||
if (!this.metadata) {
|
if (!this.metadata) {
|
||||||
throw Error('No metadata collection defined for prototype ' + this.constructor.name);
|
app.log('No metadata collection defined for prototype ' + this.constructor.name);
|
||||||
} else {
|
return name ? null : {};
|
||||||
this.metadata.prefetchChildren();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
this.metadata.prefetchChildren();
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
var result = {};
|
var result = {};
|
||||||
|
|
|
@ -163,20 +163,38 @@ Site.add = function(data, user) {
|
||||||
* @param {Site} site
|
* @param {Site} site
|
||||||
*/
|
*/
|
||||||
Site.remove = function() {
|
Site.remove = function() {
|
||||||
if (this.constructor === Site || this === root) {
|
if (this.constructor !== Site || this === root) return;
|
||||||
HopObject.remove.call(this.stories);
|
|
||||||
HopObject.remove.call(this.images);
|
const sql = new Sql();
|
||||||
HopObject.remove.call(this.files);
|
const id = this._id;
|
||||||
HopObject.remove.call(this.polls);
|
const dir = this.getStaticFile();
|
||||||
HopObject.remove.call(this.entries);
|
|
||||||
HopObject.remove.call(this.members, {force: true});
|
this.remove();
|
||||||
Layout.remove.call(this.layout, {force: true});
|
root.cache.sites = null;
|
||||||
this.getStaticFile().removeDirectory();
|
|
||||||
this.deleteMetadata();
|
sql.execute('delete from site where id = $0', id);
|
||||||
this.remove();
|
|
||||||
}
|
sql.execute('delete from membership where site_id = $0', id);
|
||||||
return;
|
sql.execute('delete from content where site_id = $0', id);
|
||||||
}
|
sql.execute('delete from file where site_id = $0', id);
|
||||||
|
|
||||||
|
sql.execute("delete from image where parent_type = 'Site' and parent_id = $0", id);
|
||||||
|
sql.execute("delete from log where context_type = 'Site' and context_id = $0", id);
|
||||||
|
sql.execute("delete from metadata where parent_type = 'Site' and parent_id = $0", id);
|
||||||
|
|
||||||
|
sql.execute('delete from skin where layout_id in (select id from layout where site_id = $0)', id);
|
||||||
|
sql.execute('delete from layout where site_id = $0', id);
|
||||||
|
|
||||||
|
sql.execute('delete from tag_hub where tag_id in (select id from tag where site_id = $0)', id);
|
||||||
|
sql.execute('delete from tag where site_id = $0', id);
|
||||||
|
|
||||||
|
let subQuery = 'select id from poll where site_id';
|
||||||
|
sql.execute('delete from vote where choice_id in (select id from choice where poll_id in ($0 = $1))', subQuery, id);
|
||||||
|
sql.execute('delete from choice where poll_id in ($0 = $1)', subQuery, id);
|
||||||
|
sql.execute('delete from poll where site_id = $0', id);
|
||||||
|
|
||||||
|
dir.removeDirectory();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue