root/de.mdman.importer/de.wbb-security.database.importer.jgsdb.30x/files/lib/data/database/importer/JGSDatenbank30xExporter.class.php @ 834

Revision 834, 8.2 kB (checked in by MDMAN, 4 years ago)

JGS - Exporter.class bugfix

Line 
1<?php
2
3require_once(WCF_DIR.'lib/data/database/importer/AbstractDatabaseExporter.class.php');
4
5
6/**
7 *
8 * @author              Markus Gerdelmann
9 * @copyright   2005-2009
10 * @package             de.wbb-security.database.importer
11 */
12class JGSDatenbank30xExporter extends AbstractDatabaseExporter {
13       
14        /**
15         * @see AbstractDatabaseExporter::$useDatabase
16         */
17        public $useDatabase = true;
18       
19        /**
20         * @see AbstractDatabaseExporter::$supportedDatabaseClasses
21         */
22        public $supportedDatabaseClasses = array('MySQLDatabase');
23       
24        /**
25         * @see AbstractDatabaseExporter::$supportedData;
26         */
27        public $supportedData = array(
28                'categories' => 1, 
29                'items' => 1, 
30                'files' => 1, 
31                'links' => 1, 
32                'optionals' => 0, 
33                'thumbnails' => 1,
34                'activation' => 1
35        );
36       
37        /**
38         * @see AbstractDatabaseExporter::$settings
39         */
40        public $settings = array(
41                'encoding' => 'ISO-8859-1',
42                'boardID' => 0,
43                'dbClass' => '',
44                'dbHost' => 'localhost',
45                'dbUser' => '',
46                'dbPassword' => '',
47                'dbName' => '',
48                'dbNumber' => 1,
49                'sourcePath' => WCF_DIR,
50        );
51       
52        /**
53         * @see AbstractDatabaseExporter::validate()
54         */
55        public function validate() {
56                parent::validate();
57               
58                // db number
59                $this->settings['dbNumber'] = intval($this->settings['dbNumber']);
60               
61               
62                // search a wbb2 table
63                try {
64                        $this->getDB()->sendQuery("SELECT COUNT(*) FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_users");
65                }
66                catch (Exception $e) {
67                        throw new UserInputException('dbNumber', 'invalid');
68                }
69               
70               
71                // search JGS - Database table
72                try {
73                        $this->getDB()->sendQuery("SELECT COUNT(*) FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_kategorie2");
74                }
75                catch (Exception $e) {
76                        throw new UserInputException('dbNumber', 'noDownloadDatabase');
77                }
78
79                // source path
80                $tmpPath = FileUtil::addTrailingSlash($this->settings['sourcePath']);
81                if ($this->data['files'] || $this->data['thumbnails']) {
82                        if (!@file_exists($tmpPath.'acp/lib/functions.php')) {
83                                $tmpPath = FileUtil::addTrailingSlash(dirname($tmpPath));
84                                if (!@file_exists($tmpPath.'acp/lib/functions.php')) {
85                                        throw new UserInputException('sourcePath', 'invalid');
86                                }
87                        }
88                }
89               
90                $this->settings['sourcePath'] = $tmpPath;
91        }
92       
93        /**
94         * @see AbstractDatabaseExporter::countCategories();
95         */
96        public function countCategories() {
97                $row = $this->getDB()->getFirstRow("SELECT COUNT(id) AS `count` FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_kategorie2");
98                return $row['count'];
99        }
100       
101        /**
102         * @see AbstractDatabaseExporter::countItems();
103         */
104        public function countItems() {
105                $row = $this->getDB()->getFirstRow("SELECT COUNT(id) AS `count` FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_eintrag");
106                return $row['count'];
107        }
108       
109        /**
110         * @see AbstractDatabaseExporter::countThumbnails();
111         */
112        public function countThumbnails() {
113                $row = $this->getDB()->getFirstRow("SELECT COUNT(id) AS `count` FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_bilder");
114                return $row['count'];
115        }
116       
117        /**
118         * @see AbstractDatabaseExporter::countFiles();
119         */
120        public function countFiles() {
121                $row = $this->getDB()->getFirstRow("SELECT COUNT(id) AS `count` FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_dateien");
122                return $row['count'];
123        }
124       
125        /**
126         * @see AbstractDatabaseExporter::countLinks();
127         */
128        public function countLinks() {
129                $row = $this->getDB()->getFirstRow("SELECT COUNT(id) AS `count` FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_eintrag WHERE dl_url != ''");
130                return $row['count'];
131        }
132
133        /**
134         * @see AbstractDatabaseExporter::countOptionals();
135         */
136        public function countOptionals() {
137                return 0;
138        }
139       
140        /**
141         * @see AbstractDatabaseExporter::Activation();
142         */
143        public function countActivation() {
144                return $this->countItems();
145        }
146       
147
148        /**
149         * @see AbstractDatabaseExporter::exportCategories();
150         */
151        public function exportCategories($offset,$limit) {
152                $result = $this->getDB()->sendQuery("SELECT * FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_kategorie2",$limit,$offset);
153                while($row = $this->getDB()->fetchArray($result)) {
154                        $this->getImporter()->importCategory("c".$row['id'],$row['kat2_name'],$row['kat2_beschreibung'],"c".$row['id_2'],$row['kat2_order'],1,"",0);
155                }
156        }
157       
158        /**
159         * @see AbstractDatabaseExporter::exportItems();
160         */
161        public function exportItems($offset,$limit) {
162               
163                $users = array();
164                $result = $this->getDB()->sendQuery("SELECT userid, username FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_users");
165                while($row = WCF::getDB()->fetchArray($result)) {
166                        $users[$row['userid']] = $row['username'];
167                }
168               
169                $result = $this->getDB()->sendQuery("SELECT d.*,u.username FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_eintrag AS `d` LEFT JOIN ".$this->dbPrefix."bb".$this->settings['dbNumber']."_users AS `u` ON (u.userid = d.userid)",$limit,$offset);
170                while($row = $this->getDB()->fetchArray($result)) {
171                       
172                        if(!isset($users[$row['userid']]) OR $users[$row['userid']] != $row['username']) {
173                                $row['userid'] = 0;
174                        }
175                       
176                        $row['enableSmilies'] = '1';
177                        $row['enableHtml'] = '0';
178                        $row['enableBBCodes'] = '1';
179                       
180                        $this->getImporter()->importItem("i".$row['id'],$row['eintrag_name'],"c".$row['kat_id'],"",$row['kurz_info'],$row['beschreibung'],$row['enableSmilies'],$row['enableHtml'],$row['enableBBCodes'],$row['username'],$row['userid']);
181                }
182        }
183       
184        /**
185         * @see AbstractDatabaseExporter::exportThumbnails();
186         */
187        public function exportThumbnails($offset,$limit) {
188                $result = $this->getDB()->sendQuery("SELECT f.*, u.userid FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_bilder AS `f` LEFT JOIN ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_eintrag AS `u` ON (u.id = f.eintrags_id)",$limit,$offset);
189                while($row = $this->getDB()->fetchArray($result)) {
190                        $row2 = $this->getDB()->getFirstRow("SELECT * FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_bilder WHERE eintrags_id = ".$row['eintrags_id']." ORDER BY id ASC");
191                        if(file_exists($this->settings['sourcePath']."jgs_db_bilder/bild-".$row2['zeit']."-".$row2['id'].".jpg")) {
192                                $this->getImporter()->importThumbnail("t".$row2['id'],"i".$row2['eintrags_id'],$this->settings['sourcePath']."jgs_db_bilder/bild-".$row2['zeit']."-".$row2['id'].".jpg","",$row['userid']);
193                        }
194                }
195        }
196       
197        /**
198         * @see AbstractDatabaseExporter::exportFiles();
199         */
200        public function exportFiles($offset,$limit) {
201                $result = $this->getDB()->sendQuery("SELECT f.*, u.userid, u.dl_url FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_dateien AS `f` LEFT JOIN ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_eintrag AS `u` ON (u.id = f.eintrags_id) WHERE u.dl_url = ''",$limit,$offset);
202                while($row = $this->getDB()->fetchArray($result)) {
203                        if(file_exists($this->settings['sourcePath']."jgs_db_download/download-".$row['zeit']."-".$row['id'].".".$row['datei_endung']."")) {
204                                $this->getImporter()->importFile("f".$row['id'],"i".$row['eintrags_id'],$this->settings['sourcePath']."jgs_db_download/download-".$row['zeit']."-".$row['id'].".".$row['datei_endung']."",$row['datei_name'].".".$row['datei_endung'],"",$row['userid']);
205                        }
206                }
207               
208        }
209       
210        /**
211         * @see AbstractDatabaseExporter::exportLinks();
212         */
213        public function exportLinks($offset,$limit) {
214                $result = $this->getDB()->sendQuery("SELECT * FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_eintrag WHERE dl_url != ''",$limit,$offset);
215                while($row = $this->getDB()->fetchArray($result)) {
216                        $this->getImporter()->importLinks("l".$row['id'],"i".$row['id'],$row['dl_url'],$row['userid']);
217                }
218        }
219       
220        /**
221         * @see AbstractDatabaseExporter::exportOptionals();
222         */
223        public function exportOptionals($offset,$limit) {
224                //nothing
225        }
226       
227        /**
228         * @see AbstractDatabaseExporter::exportActivation();
229         */
230        public function exportActivation($offset,$limit) {
231                $result = $this->getDB()->sendQuery("SELECT id FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_eintrag",$limit,$offset);
232                while($row = $this->getDB()->fetchArray($result)) {
233                        $this->getImporter()->activateItem("i".$row['id']);
234                }
235        }
236       
237}
238?>
Note: See TracBrowser for help on using the browser.