Email on EDIT
From Another Web Company
Viewed 434 times, With a total of 7 Posts
| Have a suggestion, improvement, change or non-beta Forum Entension bug ? Please add them to the todo list
|
|
|
|
Clicked A Few Times
Wiki Edits: 4
Threads 28
Posts 158
|
|
| 11:50:46 AM - Thursday 21st, January 2010 |
|
OK, is there a way to get an email trigger/hook installed when a user EDITS a post? I know I'm pushing here, but I'd like to know the following ocnditions:
EDIT - MAIN POST
EDIT - REPLY POST
I'm thinking I want edits to the main topic only to send out EDIT emails.
Basically, I want to setup a thread that is locked, like an annoncement, and when I change it... I want my members to get a fresh email.
I'll try to dig through your code and find the code and use a modified hook, but just in case I get stuck!
Thanks a bunch!
|
|
|
|
|
|
Clicked A Few Times
Wiki Edits: 4
Threads 28
Posts 158
|
|
| 12:54:44 PM - Thursday 21st, January 2010 |
|
Well, I just added this to post.php --> edit_post. I created a new hook as well. It works for the most part, but if you could modify (as i just basically copy/pased from new_post) and add to the next version it would be most awesome!!! (=
require_once(awc_dir . 'includes/subscribe.php');
$t_subscribe = new awcs_forum_subscribe();
$t_subscribe->fID = $this->fID;
$t_subscribe->tID = $this->tID;
$t_subscribe->cur_memID = $this->cur_memID;
$t_subscribe->subscribe = $this->subscribe;
$t_subscribe->title = $current_title; //;$this->ThreadTitle;
$t_subscribe->post = $this->post;
$t_subscribe->m_thread_subsrib = $this->m_thread_subsrib;
$t_subscribe->m_forum_subsrib = $this->m_forum_subsrib;
wfRunHooks( 'awcsforum_add_editpost_thread_subscribe', array(&$t_subscribe, &$this ) ); // 2.5.5
$t_subscribe->check_user_thread_subscribe();
|
|
|
|
|
|
Clicked A Few Times
Wiki Edits: 4
Threads 28
Posts 158
|
|
| 1:25:12 PM - Thursday 21st, January 2010 |
|
Also needed to add:
$thread_title = $r['t_name'];
...
..
$t_subscribe->title = $thread_title; //;$this->ThreadTitle;
...and add the to the SQL query
|
|
|
|
|
|
Clicked A Few Times
Wiki Edits: 4
Threads 28
Posts 158
|
|
| 2:12:53 PM - Thursday 21st, January 2010 |
|
So, every time I edit a post (and my get_email_addresses hook is triggered), my name/email is duplicated for each test edit i had done... I can easily filter out duplicates before posting the email, but was wondering if you had a better idea? I'm assuming the SQL is grabbing my subscription per edit? (you can see where the dup is in my WHILE loop below)
Thanks!
if($this->awc_new_thread){
$sql = "SELECT wu.user_email, f.wtchf_mem_id as mem_ID, m.m_thread_subsrib
FROM $awc_f_watchforums f
JOIN $wiki_user wu
ON f.wtchf_mem_id=wu.user_id
JOIN $awc_f_mems m
ON f.wtchf_mem_id=m.m_ID
WHERE f.wtchf_forum_id=$class_info->fID";
} else {
$sql = "SELECT wu.user_email, t.wtcht_mem_id as mem_ID, m.m_thread_subsrib
FROM $awc_f_watchthreads t
JOIN $wiki_user wu
ON t.wtcht_mem_id=wu.user_id
JOIN $awc_f_mems m
ON t.wtcht_mem_id=m.m_ID
WHERE t.wtcht_thread_id=$class_info->tID";
}
$res = $rDB->query($sql);
while ($r = $rDB->fetchObject( $res )) {
$user = User::newFromID($r->mem_ID);
if( $r->user_email != '' ) {
$address[] = $r->user_email;
$name = $user->getRealName();
if( $name == "") $name = $user->getName();
$this->members .= $name . ", ";
}
$threads = unserialize($r->m_thread_subsrib);
// we dont need to do a db call for the current user as the AWC code does this
if($class_info->cur_memID != $r->mem_ID){
if($this->awc_new_thread == true) {
self::subscribe_to_thread( $r->mem_ID, $this->awc_ext_thread->tID, $threads ); //auto subscribe other members
}
}
}
|
|
|
|
|
|
Clicked A Few Times
Wiki Edits: 4
Threads 28
Posts 158
|
|
| 2:37:25 PM - Thursday 21st, January 2010 |
|
Anyhow, I'm all set with my hacks. I used the following to filter out dups:
// remove any types of duplicates
$address = array_unique($address);
$this->members = implode(", ", array_unique($arrName));
I guess in summary, I'm just hoping you can add the edit post hooks into the main code so I dont have to remember to go back and add them again. If you do add them, please let me know what ya did so I can re-hack my hooks to match yours!
Thanks so much!
|
|
Edited On 2:38:30 PM - Thursday 21st, January 2010 by Kenyu73
|
|
|
|
|
|
|
| 2:44:33 AM - Saturday 23rd, January 2010 |
|
Just added a hook for you.
Edit file: extensions/awc/forums/post.php
|
| Find:
|
In the edit_post() function $rDB = wfGetDB( DB_SLAVE );
|
| Above that add:
|
wfRunHooks( 'awcsforum_edit_thread', &$this ); // 2.5.8
|
That will give you access to a bunch of info (and you could also change that info (if you wanted to) and the changes would be saved since the hook is being called just before the SQL save), and you can use that to do what you need to do.
Heres the object info which you will have access to.
awcsforum_post_cls Object
(
[ann] => 0
[sticky] => 0
[lock] => 0
[id] =>
[tID] => 9
[fID] => 1
[pID] => 35
[title] => Test "double" 'single'
[p_title] => Test "double" 'single'
[post] => Test "double" 'single'
[ThreadTitle] =>
[isThread] => yes
[m_thread_subsrib] => Array
(
[9] => email
)
[m_forum_subsrib] =>
[cur_memID] => 1
[cur_memName] => Me
[cur_m_posts] => 30
[cur_m_topics] => 8
[mId] => 1
[mName] => Me
[forum_Antispam] =>
[ispoll] =>
[polls_enabled] => 1
[action] => post/todo_edit_post/
[subscrib_what] =>
[subscribe] =>
[cf_add_post_text_to_wiki] =>
[t_wiki_pageID] =>
[f_name] =>
[num_topics] =>
)
So in your extension code, use what you already have, but with out the hook call you added.
The below is a copy/paste and untested, but should work.
$wgHooks['awcsforum_edit_thread'][] = 'yourHookFunctionName';
function yourHookFunctionName($editInfo){
require_once(awc_dir . 'includes/subscribe.php');
$t_subscribe = new awcs_forum_subscribe();
$t_subscribe->fID = $editInfo->fID;
$t_subscribe->tID = $editInfo->tID;
$t_subscribe->cur_memID = $editInfo->cur_memID;
$t_subscribe->subscribe = $editInfo->subscribe;
$t_subscribe->title = $editInfo->title; //;$this->ThreadTitle;
$t_subscribe->post = $editInfo->post;
$t_subscribe->m_thread_subsrib = $editInfo->m_thread_subsrib;
$t_subscribe->m_forum_subsrib = $editInfo->m_forum_subsrib;
$t_subscribe->check_user_thread_subscribe();
return true;
}
Post back how you made out...
_
|
|
~ What was once an opinion, became a fact, to be later proven wrong ~
|
|
|
|
Clicked A Few Times
Wiki Edits: 4
Threads 28
Posts 158
|
|
| 11:43:04 AM - Monday 25th, January 2010 |
|
I'm not sure what the deal is yet, but using the hook before the db update is causing this error:
INSERT INTO `mw_awc_f_watchthreads` (wtcht_thread_id,wtcht_mem_id,wtcht_todo) VALUES (NULL,NULL,NULL)
The error is probably in the awcsforum_subscribe_get_email_address hook. I'm not sure right now why adding my hacked code into your edit_post function works post db update as opposed to the same $t_subscribe object used pre-db update.
Just out of curisity (maybe a minor suggestion) but why change this hook to pre-db update when all the other hooks are post-db update (new thread, new post, etc)? Either is fine... pre-update, like you said, gives more options to modify the post before saving to the db like maybe forum mods being able to auto-proof posts for bad words and such.
I just recommend either making all hooks are pre or all hooks are post db...
//using my hacked hook ($t_subscribe created in AWC edit_post function)
function add_edit_post(&$t_subscribe, &$thread){
$t_subscribe->email_lookup = false;
if( $t_subscribe->tID > 0 ) {
$this->awc_ext_thread = $t_subscribe;
$this->awc_ext_thread->cur_m_posts = $thread->cur_m_posts;
$this->awc_ext_thread->title = $this->awc_ext_thread->title . " {edit}";
$this->awc_new_thread = false;
$this->edit_post = true;
}
return true;
}
//using AWCs recommendation (pre-db update)
function add_edit_post2(&$editInfo){
require_once(awc_dir . 'includes/subscribe.php');
$t_subscribe = new awcs_forum_subscribe();
$t_subscribe->fID = $editInfo->fID;
$t_subscribe->tID = $editInfo->tID;
$t_subscribe->cur_memID = $editInfo->cur_memID;
$t_subscribe->subscribe = $editInfo->subscribe;
$t_subscribe->title = $editInfo->title; //;$this->ThreadTitle;
$t_subscribe->post = $editInfo->post;
$t_subscribe->m_thread_subsrib = $editInfo->m_thread_subsrib;
$t_subscribe->m_forum_subsrib = $editInfo->m_forum_subsrib;
$t_subscribe->email_lookup = false;
if( $t_subscribe->tID > 0 ) {
$this->awc_ext_thread = $t_subscribe;
$this->awc_ext_thread->cur_m_posts = $editInfo->cur_m_posts;
$this->awc_ext_thread->title = $this->awc_ext_thread->title . " {edit}";
$this->awc_new_thread = false;
$this->edit_post = true;
}
$t_subscribe->check_user_thread_subscribe();
return true;
}
|
|
|
|
|
|
|
| 1:50:44 AM - Tuesday 26th, January 2010 |
|
Quote:Kenyu73 Jan 25th 10:35 amI just recommend either making all hooks are pre or all hooks are post db...
They are (called before).
http://wiki.anotherwebcom.com/Hooks_AWC's_MediaWiki_Forum_Extension
As of forum version 2.5.5 there are three hooks called before info is saved to the database, New Thread, New Post and New Poll along with other Hooks as-well.
Not sure what a happened to your code, but i did check to see if the info was being passed with the new hook I posted in this thread (thats where the object info came from). When i get time i will double check what i posted - before it is made a permanent change.
Theres definitely no reason to add all that code to the post.php file, especially since it will only do one thing, send off a subscription notice. Other people might want to use the hook in other ways (reason it is being called before the dbase save), thats why its gonna be a Hook and not a Function.
_
|
|
|
AWC's:
2.5.8 MediaWiki - Stand Alone Forum Extension Forum theme style by: AWC
|