完美解决phpcms批量移动内容后,新闻心情、评论排行等不更新的问题

清泛原创
问题描述:
phpcms批量移动内容/文章,”批量更新URL“ -> "批量更新内容页"后,发现原内容的评论、新闻心情全部丢失,这还不算差,后台评论排行列表数据仍然还是原内容的数据,url却是空链接了(原url已删除了)。

原因:内容移动后,catid发生了变化,而comment、mood相关的表中catid没有更新。

解决方法:只需修改一个文件搞定 phpcms/modules/content/content.php
/**
         * 批量移动文章
         */
        public function remove() {...
改为:
/**
         * 批量移动文章
         */
        public function remove() {
                if(isset($_POST['dosubmit'])) {
                        $this->content_check_db = pc_base::load_model('content_check_model');
                        $this->hits_db = pc_base::load_model('hits_model');
                        $this->mood_db = pc_base::load_model('mood_model');
                        $this->comment_db = pc_base::load_model('comment_model');
                        $this->comment_data_db = pc_base::load_model('comment_data_model');
                        $this->url = pc_base::load_app_class('url', 'content');
                        if($_POST['fromtype']==0) {
                                if($_POST['ids']=='') showmessage(L('please_input_move_source'));
                                if(!$_POST['tocatid']) showmessage(L('please_select_target_category'));
                                $tocatid = intval($_POST['tocatid']);
                                $modelid = $this->categorys[$tocatid]['modelid'];
                                if(!$modelid) showmessage(L('illegal_operation'));
                                $ids = array_filter(explode(',', $_POST['ids']),"intval");
                                foreach ($ids as $id) {
                                        $checkid = 'c-'.$id.'-'.$this->siteid;
                                        $this->content_check_db->update(array('catid'=>$tocatid), array('checkid'=>$checkid));
                                        $hitsid = 'c-'.$modelid.'-'.$id;
                                        $this->hits_db->update(array('catid'=>$tocatid),array('hitsid'=>$hitsid));
                                        
                                        // 找出原catid
                                        $this->db->set_model($modelid);
                                        $r = $this->db->get_one(array('id'=>$id), 'catid,prefix');
                                        $catid = $r['catid'];
                                        // mood
                                        $this->mood_db->update(array('catid'=>$tocatid), array('catid'=>$catid,'siteid'=>$this->siteid,'contentid'=>$id));
                                        // comment
                                        $commentid = 'content_'.$catid.'-'.$id.'-'.$this->siteid;
                                        $newcommentid = 'content_'.$tocatid.'-'.$id.'-'.$this->siteid;
                                        $urls = $this->url->show($id, '', $tocatid, $r['inputtime'], $r['prefix']);
                                        $this->comment_db->update(array('commentid'=>$newcommentid, 'url'=>$urls[0]), array('commentid'=>$commentid));
                                        // comment_data
                                        $comment = $this->comment_db->get_one(array('commentid'=>$commentid, 'siteid'=>$this->siteid));
                                        if ($comment) {
                                                $this->comment_data_db->table_name($comment['tableid']);
                                                $this->comment_data_db->update(array('commentid'=>$newcommentid), array('commentid'=>$commentid));
                                        }
                                }
                                $ids = implode(',', $ids);
                                $this->db->set_model($modelid);
                                $this->db->update(array('catid'=>$tocatid),"id IN($ids)");
                        } else {
                                if(!$_POST['fromid']) showmessage(L('please_input_move_source'));
                                if(!$_POST['tocatid']) showmessage(L('please_select_target_category'));
                                $tocatid = intval($_POST['tocatid']);
                                $modelid = $this->categorys[$tocatid]['modelid'];
                                if(!$modelid) showmessage(L('illegal_operation'));
                                $fromid = array_filter($_POST['fromid'],"intval");
                                $fromid = implode(',', $fromid);
                                $this->db->set_model($modelid);
                                $this->db->update(array('catid'=>$tocatid),"catid IN($fromid)");
                                $this->hits_db->update(array('catid'=>$tocatid),"catid IN($fromid)");
                        }
                        showmessage(L('operation_success'),HTTP_REFERER);
                        //ids
                } else {
                        $show_header = '';
                        $catid = intval($_GET['catid']);
                        $modelid = $this->categorys[$catid]['modelid'];
                        $tree = pc_base::load_sys_class('tree');
                        $tree->icon = array('  │ ','  ├─ ','  └─ ');
                        $tree->nbsp = '  ';
                        $categorys = array();
                        foreach($this->categorys as $cid=>$r) {
                                if($this->siteid != $r['siteid'] || $r['type']) continue;
                                if($modelid && $modelid != $r['modelid']) continue;
                                $r['disabled'] = $r['child'] ? 'disabled' : '';
                                $r['selected'] = $cid == $catid ? 'selected' : '';
                                $categorys[$cid] = $r;
                        }
                        $str  = "<option value='\$catid' \$selected \$disabled>\$spacer \$catname</option>";

                        $tree->init($categorys);
                        $string .= $tree->get_tree(0, $str);
                         $str  = "<option value='\$catid'>\$spacer \$catname</option>";
                        $source_string = '';
                        $tree->init($categorys);
                        $source_string .= $tree->get_tree(0, $str);
                        $ids = empty($_POST['ids']) ? '' : implode(',',$_POST['ids']);
                        include $this->admin_tpl('content_remove');
                }
        }

phpcms 批量移动 新闻心情 评论排行 不更新

分享到:
评论加载中,请稍后...
创APP如搭积木 - 创意无限,梦想即时!
回到顶部