diff options
author | Egil Moeller <egil.moller@freecode.no> | 2010-03-12 21:03:59 +0100 |
---|---|---|
committer | Egil Moeller <egil.moller@freecode.no> | 2010-03-12 21:03:59 +0100 |
commit | e4ddcd93e291047717843a61d5511719fbec3901 (patch) | |
tree | b010fd99be4391a108cf5f8bcfb86aef5037205e /trunk | |
parent | c1894c8e0a52f4e3d2f89fa92f0066bbf0fcf1b1 (diff) | |
download | etherpad-e4ddcd93e291047717843a61d5511719fbec3901.tar.gz etherpad-e4ddcd93e291047717843a61d5511719fbec3901.tar.xz etherpad-e4ddcd93e291047717843a61d5511719fbec3901.zip |
First attempt to saving tags to db
Diffstat (limited to '')
-rw-r--r-- | trunk/etherpad/src/etherpad/pad/model.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/trunk/etherpad/src/etherpad/pad/model.js b/trunk/etherpad/src/etherpad/pad/model.js index 9424f10..ea0d68d 100644 --- a/trunk/etherpad/src/etherpad/pad/model.js +++ b/trunk/etherpad/src/etherpad/pad/model.js @@ -258,6 +258,42 @@ function accessPadGlobal(padId, padFunc, rwMode) { delete meta2.status; sqlbase.putJSON("PAD_META", padId, meta2); + /* Update tags for the pad. Should maybe be in a separate function? */ + var new_tags = pad.text().match(new RegExp("#[^,# \t\n\r][^,# \t\n\r]*", "g")) + if (new_tags == null) new_tags = new Array(); + for (i = 0; i < new_tags.length; i++) + new_tags[i] = new_tags[i].substring(1); + var new_tags_str = new_tags.join('#') + + var old_tags_row = sqlobj.selectSingle("PAD_TAG_CACHE", { id: padId }); + var old_tags_str; + if (old_tags_row !== null) + old_tags_str = old_tags_row['TAGS']; + else + old_tags_str = ''; + + var old_tags = old_tags_str != '' ? old_tags_str.split('#') : new Array(); + + if (new_tags_str != old_tags_str) { + log.info({message: 'Updating tags', new_tags:new_tags, old_tags:old_tags}); + + if (old_tags_row) + sqlobj.update("PAD_TAG_CACHE", { id: padId }, {tags: new_tags.join('#')}); + else + sqlobj.insert("PAD_TAG_CACHE", {id: padId, tags: new_tags.join('#')}); + + sqlobj.deleteRows("PAD_TAG", {pad_id: padId}); + + for (i = 0; i < new_tags.length; i++) { + var tag_row = sqlobj.selectSingle("TAG", { name: new_tags[i] }); + if (tag_row === null) { + sqlobj.insert("TAG", {name: new_tags[i]}); + tag_row = sqlobj.selectSingle("TAG", { name: new_tags[i] }); + } + sqlobj.insert("PAD_TAG", {pad_id: padId, tag_id: tag_row['ID']}); + } + } + _getPadStringArray(padId, "revs").writeToDB(); _getPadStringArray(padId, "revs10").writeToDB(); _getPadStringArray(padId, "revs100").writeToDB(); |