From: <al...@us...> - 2004-10-29 16:27:27
|
Update of /cvsroot/egroupware/phpbrain/inc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20456 Modified Files: class.bokb.inc.php class.sokb.inc.php Log Message: Fixes bug 1055175: not deleting articles or transfer ownership when user is deleted Index: class.bokb.inc.php =================================================================== RCS file: /cvsroot/egroupware/phpbrain/inc/class.bokb.inc.php,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** class.bokb.inc.php 29 Oct 2004 13:57:08 -0000 1.37 --- class.bokb.inc.php 29 Oct 2004 16:27:01 -0000 1.38 *************** *** 632,636 **** * @param array Article's files * @param int $art_id Article id. If not given, $this->article_id is used ! * @param int $owner Article's owner id * @return string Success or failure message */ --- 632,636 ---- * @param array Article's files * @param int $art_id Article id. If not given, $this->article_id is used ! * @param int $owner Article's owner id. -1 to avoid checking permissions (when admin is deleting all user's articles) * @return string Success or failure message */ *************** *** 639,643 **** if (!$art_id) $art_id = $this->article_id; // check user has edit rights ! if (!$this->check_permission($this->edit_right, $owner)) return 'no_perm'; // delete files if ($files) --- 639,643 ---- if (!$art_id) $art_id = $this->article_id; // check user has edit rights ! if ($owner != -1 && !$this->check_permission($this->edit_right, $owner)) return 'no_perm'; // delete files if ($files) *************** *** 677,680 **** --- 677,752 ---- /** + * Deletes owners articles (called by hook_deleteaccount) + * + * @author Alejandro Pedraza + * @access public + * @param int $owner Article's owner id + * @return void + */ + function delete_owner_articles($owner) + { + // check if user calling deletion is an admin with user deletion privileges + if ($GLOBALS['phpgw']->acl->check('account_access',32,'admin')) + { + $this->list_users(); + die('invalid rights'); + } + + // fetch articles from user + $GLOBALS['phpgw']->vfs->override_acl = 1; + $owner = (int)$owner; + $articles_ids = $this->so->get_articles_ids($owner); + foreach ($articles_ids as $article_id) + { + $article = $this->so->get_article($article_id); + $this->delete_article($article['files'], $article_id, -1); + } + } + + /** + * changes articles owner (called by hook_deleteaccount) + * + * @author Alejandro Pedraza + * @access public + * @param int $owner Article's owner id + * @param int $owner Article's new owner id + * @return void + */ + function change_articles_owner($owner, $new_owner) + { + // check if user calling deletion is an admin with user deletion privileges + if ($GLOBALS['phpgw']->acl->check('account_access',32,'admin')) + { + $this->list_users(); + die('invalid rights'); + } + + $owner = (int)$owner; + $new_owner = (int)$new_owner; + + // first change file owners in vfs + $articles_ids = $this->so->get_articles_ids($owner); + foreach ($articles_ids as $article_id) + { + $article = $this->so->get_article($article_id); + $GLOBALS['phpgw']->vfs->override_acl = 1; + if (is_array($article['files'])) + { + foreach ($article['files'] as $file) + { + $GLOBALS['phpgw']->vfs->set_attributes(array( + 'string' => '/kb/' . $file['file'], + 'relatives' => array(RELATIVE_NONE), + 'attributes' => array('owner_id' => $new_owner), + )); + } + } + } + + // now change articles owners + $this->so->change_articles_owner($owner, $new_owner); + } + + /** * Deletes question * Index: class.sokb.inc.php =================================================================== RCS file: /cvsroot/egroupware/phpbrain/inc/class.sokb.inc.php,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** class.sokb.inc.php 7 Oct 2004 15:10:30 -0000 1.40 --- class.sokb.inc.php 29 Oct 2004 16:27:02 -0000 1.41 *************** *** 1,7 **** <?php /**************************************************************************\ ! * eGroupWare - KnowledgeBase * * http://www.egroupware.org * ! * Written by Alejandro Pedraza [alejandro.pedraza AT dataenlace DOT com] * * ------------------------------------------------------------------------ * * Started off as a port of phpBrain - http://vrotvrot.com/phpBrain/ * --- 1,7 ---- <?php /**************************************************************************\ ! * eGroupWare - KnowledgeBase * * http://www.egroupware.org * ! * Written by Alejandro Pedraza [alpeb AT users.sourceforge DOT net] * * ------------------------------------------------------------------------ * * Started off as a port of phpBrain - http://vrotvrot.com/phpBrain/ * *************** *** 501,504 **** --- 501,519 ---- /** + * Changes article owner when user is deleted + * + * @author Alejandro Pedraza + * @access public + * @param int $owner actual owner + * @param int $new_owner new owner + * @return void + **/ + function change_articles_owner($owner, $new_owner) + { + $sql = "UPDATE phpgw_kb_articles SET user_id='$new_owner' WHERE user_id='$owner'"; + $this->db->query($sql, __LINE__, __FILE__); + } + + /** * Deletes article * *************** *** 600,603 **** --- 615,638 ---- /** + * Returns all articles ids from a given owner + * + * @author Alejandro Pedraza + * @access public + * @param int $owner owner id + * @return array Articles ids + **/ + function get_articles_ids($owner) + { + $sql = "SELECT art_id FROM phpgw_kb_articles WHERE user_id=$owner"; + $this->db->query($sql, __LINE__, __FILE__); + $articles_ids = array(); + while ($this->db->next_record()) + { + $articles_ids[] = $this->db->f('art_id'); + } + return $articles_ids; + } + + /** * Increments the view count of a published article * |