root/taggingreloaded/optionals/de.easy-coding.wbb.taggingreloaded/files/lib/acp/action/UpdateTaggingReloaded.class.php @ 59

Revision 59, 2.7 kB (checked in by d0nut, 6 years ago)

Updated system poster. He now works by cronjob. It is to resource-intensive to build thread data after every post edit.
And there will be too much bad tags if the system poster taggs for every post. See taggingreloadedTechTalks

Line 
1<?php
2require_once(WBB_DIR.'lib/acp/action/UpdateCounterAction.class.php');
3
4// tagging imports
5require_once(WCF_DIR.'lib/util/TaggingReloadedUtil.class.php');
6
7/**
8 * Updates the board tags.
9 *
10 * @author      Torben Brodt
11 * @package     de.easy-coding.wbb.taggingreloaded
12 * @license     GNU General Public License <http://opensource.org/licenses/gpl-license.php>
13 */
14class UpdateTaggingReloadedAction extends UpdateCounterAction {
15        public $action = 'UpdateTaggingReloaded';
16        public $everything = true;
17       
18        protected function buildQuery() {
19                if($this->everything) {
20                        $sql = "SELECT          postID,
21                                                threadID,
22                                                message
23                                FROM            wbb".WBB_N."_post
24                                ORDER BY        threadID ASC,
25                                                postID DESC
26                                LIMIT           ".$this->limit."
27                                OFFSET          ".($this->limit * $this->loop);
28                } else {
29                        $sql = "SELECT          p2.postID,
30                                                p2.threadID,
31                                                p2.message
32                                FROM            wbb".WBB_N."_post p
33                                JOIN            wbb".WBB_N."_thread t
34                                ON              p.threadID = p.threadID
35                                JOIN            wbb".WBB_N."_post p2
36                                ON              t.threadID = p2.threadID
37                                WHERE           p.systemTagged = 0
38                                ORDER BY        p2.threadID ASC,
39                                                p2.postID DESC";
40                }
41               
42                return $sql;
43        }
44       
45        /**
46         * @see Action::execute()
47         */
48        public function execute() {
49                parent::execute();
50                $threadIDs = array();
51                $systemTaggerUserID = -1;
52               
53                // get all posts
54                $sql = $this->buildQuery();
55                $result = WCF::getDB()->sendQuery($sql);
56                while ($row = WCF::getDB()->fetchArray($result)) {
57                        // group by thread to get relevant keywords
58                        if(!isset($threadID) || $threadID == $row['threadID']) {
59                                $threadID = $row['threadID'];
60                                $threadIDs[] = $threadID;
61
62                                $msg = TaggingReloadedUtil::bbcode2text($row['message']);
63                                $text .= $msg;
64                        } else {
65                                // but store them in the first posting
66                                $tags = TaggingReloadedUtil::text2tags($text);
67                                $first_post = $row['postID'];
68                               
69                                // CLEANUP system tags
70                                $sql = "DELETE FROM     wbb".WBB_N."_taggingreloaded,
71                                                        wcf".WCF_N."_taggingreloaded
72                                        USING           wbb".WBB_N."_taggingreloaded wbb
73                                        NATURAL JOIN    wcf".WCF_N."_taggingreloaded wcf
74                                        JOIN            wbb".WBB_N."_post p
75                                        ON              wbb.postID = p.postID
76                                        WHERE           userID = -1
77                                        AND             p.threadID = {$threadID};";
78
79                                WBBCore::getDB()->sendQuery($sql);
80
81                                if(count($tags) > 0) {
82                                        // INSERT tagging<->post
83                                        $sql = "INSERT INTO     wbb".WBB_N."_taggingreloaded
84                                                                (postID)
85                                                VALUES          ({$first_post});";
86
87                                        WBBCore::getDB()->sendQuery($sql);
88                                        $taggingID = WBBCore::getDB()->getInsertID();
89
90                                        // save tags
91                                        TaggingReloadedUtil::tags2db($taggingID, $tags, $systemTaggerUserID);
92                                }
93                                $text = '';
94                        }
95                }
96               
97                $sql = "UPDATE  wbb1_1_post SET systemTagged = 1 WHERE threadID IN (".implode(',', $threadIDs)."); ";
98
99                $this->executed();
100               
101                if($this->everything) {
102                        $this->calcProgress(($this->limit * $this->loop), $count);
103                        $this->nextLoop();
104                }
105        }
106}
107?>
Note: See TracBrowser for help on using the browser.