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

Revision 68, 3.1 kB (checked in by d0nut, 6 years ago)

optimized the tagging wbb package (especially the system tagger)

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 = {$systemTaggerUserID}
77                                        AND             p.threadID = {$threadID};";
78
79                                WBBCore::getDB()->sendQuery($sql);
80
81                                if(count($tags) > 0) {
82                                        $sql = "SELECT          taggingID
83                                                FROM            wbb".WBB_N."_taggingreloaded
84                                                WHERE           postID = {$first_post};";
85                                        $row = WCF::getDB()->getFirstRow($sql);
86                                       
87                                        // is there an tagging entry?
88                                        if(isset($row['taggingID'])) {
89                                                $taggingID = $row['taggingID'];
90                                        } else {
91                                                // INSERT tagging<->post
92                                                $sql = "INSERT INTO     wbb".WBB_N."_taggingreloaded
93                                                                        (postID)
94                                                        VALUES          ({$first_post});";
95
96                                                WBBCore::getDB()->sendQuery($sql);
97                                                $taggingID = WBBCore::getDB()->getInsertID();
98                                        }
99
100                                        // save tags
101                                        TaggingReloadedUtil::tags2db($taggingID, $tags, $systemTaggerUserID);
102                                }
103                                $text = '';
104                        }
105                }
106
107                $sql = "UPDATE          wbb1_1_post
108                        SET     
109                                        systemTagged = 1
110                        WHERE           threadID IN (".implode(',', $threadIDs)."); ";
111                WBBCore::getDB()->sendQuery($sql);
112
113                $this->executed();
114               
115                if($this->everything) {
116                        $this->calcProgress(($this->limit * $this->loop), $count);
117                        $this->nextLoop();
118                }
119        }
120}
121?>
Note: See TracBrowser for help on using the browser.