* Moved all direct SQL statements as constants into Sql object

* Removed redundant call for HopObject.log() in Admin.update() method
This commit is contained in:
Tobi Schäfer 2010-01-19 22:01:39 +00:00
parent 499e8d97b9
commit 33ef009f20
5 changed files with 30 additions and 22 deletions

View file

@ -175,8 +175,7 @@ Admin.purgeSites = function() {
*/
Admin.purgeReferrers = function() {
var sql = new Sql;
var result = sql.execute("delete from log where action = 'main' and " +
"created < date_add(now(), interval -2 day)");
var result = sql.execute(Sql.PURGEREFERRERS);
return result;
}
@ -419,7 +418,6 @@ Admin.prototype.update = function(data) {
probationPeriod: data.probationPeriod,
quota: data.quota
});
this.log(root, "Updated setup");
return;
}

View file

@ -41,8 +41,7 @@ Comment.remove = function(options) {
}
if (options && options.mode === "user" && options.confirm === "1") {
var sql = new Sql;
sql.retrieve("select id from content where site_id = $0 and creator_id = $1 \
and prototype = 'Comment'", this.site._id, this.creator._id);
sql.retrieve(Sql.COMMENTS, this.site._id, this.creator._id);
sql.traverse(function() {
Comment.remove.call(Comment.getById(this.id));
});

View file

@ -64,7 +64,6 @@ String.URLPATTERN = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF90
// FIXME: Be careful with property names of app.data;
// they inherit all properties from HopObject!
/**
* @name app.data
* @namespace
@ -82,7 +81,6 @@ app.data.exports || (app.data.exports = []);
/** @name app.data.imports */
app.data.imports || (app.data.imports = []);
/**
* @name helma.File
* @namespace
@ -146,15 +144,37 @@ jala.i18n.setLocaleGetter(function() {
return (res.handlers.site || root).getLocale();
});
/** @constant */
Sql.COMMENTS = "select id from content where site_id = $0 and creator_id = $1 \
and prototype = 'Comment'";
/** @constant */
Sql.PURGEREFERRERS = "delete from log where action = 'main' and " +
"created < date_add(now(), interval -2 day)";
/** @constant */
Sql.REFERRERS = "select referrer, count(*) as requests from " +
"log where context_type = '$0' and context_id = $1 and action = " +
"'main' and created > date_add(now(), interval -1 day) group " +
"by referrer order by requests desc, referrer asc";
/** @constant */
Sql.SEARCH = "select id from content where site_id = $0 and " +
"prototype = $1 and status <> $2 and (metadata like $3 or " +
"metadata like $4) order by created desc limit $5";
/** @constant */
var SHORTDATEFORMAT = "yyyy-MM-dd HH:mm";
/** @constant */
var LONGDATEFORMAT = "EEEE, d. MMMM yyyy, HH:mm";
/** @constant */
var SQLDATEFORMAT = "yyyy-MM-dd HH:mm:ss";
/** @function */
var idle = new Function;
/** */
var html = new helma.Html();

View file

@ -567,11 +567,8 @@ Site.prototype.search_action = function() {
search = String(search).toSource().slice(13, -3).replace(/(\\)/g, "$1$1");
var title = '%title:"%' + search + '%"%';
var text = '%text:"%' + search + '%"%';
var sql = new Sql();
sql.retrieve("select id from content where site_id = $0 and " +
"prototype = $1 and status <> $2 and (metadata like $3 or " +
"metadata like $4) order by created desc limit $5",
this._id, "Story", Story.CLOSED, text, title, 25);
var sql = new Sql;
sql.retrieve(Sql.SEARCH, this._id, "Story", Story.CLOSED, text, title, 25);
res.push();
var counter = 0;
sql.traverse(function() {
@ -734,11 +731,8 @@ Site.prototype.deleted_macro = function() {
*/
Site.prototype.referrers_macro = function() {
var self = this;
var sql = new Sql();
sql.retrieve("select referrer, count(*) as requests from " +
"log where context_type = 'Site' and context_id = $0 and action = " +
"'main' and created > date_add(now(), interval -1 day) group " +
"by referrer order by requests desc, referrer asc", this._id);
var sql = new Sql;
sql.retrieve(Sql.REFERRERS, "Site", this._id);
sql.traverse(function() {
if (this.requests && this.referrer) {
this.text = encode(this.referrer.head(50));

View file

@ -524,11 +524,8 @@ Story.prototype.referrers_macro = function(param, limit) {
}
var self = this;
var sql = new Sql();
sql.retrieve("select referrer, count(*) as requests from " +
"log where context_type = 'Story' and context_id = $0 and action = " +
"'main' and created > date_add(now(), interval -1 day) group " +
"by referrer order by requests desc, referrer asc", this._id);
var sql = new Sql;
sql.retrieve(Sql.REFERRERS, "Story", this._id);
res.push();
var n = 0;