/** * Moves all posts within the current thread to a new forum * * @param integer $old_obj_id object id of the current forum * @param integer $old_pk primary key of old forum * @param integer $new_obj_id object id of the new forum * @param integer $new_pk primary key of new forum * @return integer number of afffected rows by updating posts * @access public */ public function movePosts($old_obj_id, $old_pk, $new_obj_id, $new_pk) { global $ilDB; if ($this->id) { $nodes = $this->getAllPosts(); if (is_array($nodes)) { // Move attachments foreach ($nodes as $node) { $file_obj = new ilFileDataForum((int) $old_obj_id, (int) $node->pos_pk); $file_obj->moveFilesOfPost((int) $new_obj_id); unset($file_obj); } } $this->db->lockTables(array(0 => array('name' => 'frm_user_read', 'type' => ilDB::LOCK_WRITE), 1 => array('name' => 'frm_thread_access', 'type' => ilDB::LOCK_WRITE))); $this->db->manipulateF(' DELETE FROM frm_user_read WHERE obj_id = %s AND thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id)); $this->db->manipulateF(' UPDATE frm_user_read SET obj_id = %s WHERE thread_id = %s', array('integer', 'integer'), array($new_obj_id, $this->id)); $this->db->manipulateF(' DELETE FROM frm_thread_access WHERE obj_id = %s AND thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id)); $this->db->manipulateF(' UPDATE frm_thread_access SET obj_id = %s WHERE thread_id =%s', array('integer', 'integer'), array($new_obj_id, $this->id)); $this->db->unlockTables(); $this->db->manipulateF(' UPDATE frm_posts SET pos_top_fk = %s WHERE pos_thr_fk = %s', array('integer', 'integer'), array($new_pk, $this->id)); // update all related news $posts = $ilDB->queryf(' SELECT * FROM frm_posts WHERE pos_thr_fk = %s', array('integer'), array($this->id)); $old_obj_id = ilForum::_lookupObjIdForForumId($old_pk); $new_obj_id = ilForum::_lookupObjIdForForumId($new_pk); while ($post = $posts->fetchRow(DB_FETCHMODE_ASSOC)) { include_once "./Services/News/classes/class.ilNewsItem.php"; $news_id = ilNewsItem::getFirstNewsIdForContext($old_obj_id, "frm", $post["pos_pk"], "pos"); $news_item = new ilNewsItem($news_id); $news_item->setContextObjId($new_obj_id); $news_item->update(); //echo "<br>-".$post["pos_pk"]."-".$old_obj_id."-".$new_obj_id."-"; } return count($nodes); } return 0; }