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

Revision 836, 9.9 kB (checked in by MDMAN, 4 years ago)

JGS - Exporter.class updated to Version 1.0.0

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' => 1, 
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                $row = $this->getDB()->getFirstRow("SELECT COUNT(*) AS `count` 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)");
138                return $row['count'];
139        }
140       
141        /**
142         * @see AbstractDatabaseExporter::Activation();
143         */
144        public function countActivation() {
145                return $this->countItems();
146        }
147       
148
149        /**
150         * @see AbstractDatabaseExporter::exportCategories();
151         */
152        public function exportCategories($offset,$limit) {
153                $result = $this->getDB()->sendQuery("SELECT * FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_kategorie2",$limit,$offset);
154                while($row = $this->getDB()->fetchArray($result)) {
155                        $this->getImporter()->importCategory("c".$row['id'],$row['kat2_name'],$row['kat2_beschreibung'],"c".$row['id_2'],$row['kat2_order'],1,"",0);
156                }
157        }
158       
159        /**
160         * @see AbstractDatabaseExporter::exportItems();
161         */
162        public function exportItems($offset,$limit) {
163               
164                $users = array();
165                $result = $this->getDB()->sendQuery("SELECT userid, username FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_users");
166                while($row = WCF::getDB()->fetchArray($result)) {
167                        $users[$row['userid']] = $row['username'];
168                }
169               
170                $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);
171                while($row = $this->getDB()->fetchArray($result)) {
172                       
173                        if(!isset($users[$row['userid']]) OR $users[$row['userid']] != $row['username']) {
174                                $row['userid'] = 0;
175                        }
176                       
177                        $row['enableSmilies'] = '1';
178                        $row['enableHtml'] = '0';
179                        $row['enableBBCodes'] = '1';
180                       
181                        $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']);
182                }
183        }
184       
185        /**
186         * @see AbstractDatabaseExporter::exportThumbnails();
187         */
188        public function exportThumbnails($offset,$limit) {
189                $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);
190                while($row = $this->getDB()->fetchArray($result)) {
191                        $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");
192                        if(file_exists($this->settings['sourcePath']."jgs_db_bilder/bild-".$row2['zeit']."-".$row2['id'].".jpg")) {
193                                $this->getImporter()->importThumbnail("t".$row2['id'],"i".$row2['eintrags_id'],$this->settings['sourcePath']."jgs_db_bilder/bild-".$row2['zeit']."-".$row2['id'].".jpg","",$row['userid']);
194                        }
195                }
196        }
197       
198        /**
199         * @see AbstractDatabaseExporter::exportFiles();
200         */
201        public function exportFiles($offset,$limit) {
202                $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);
203                while($row = $this->getDB()->fetchArray($result)) {
204                        if(file_exists($this->settings['sourcePath']."jgs_db_download/download-".$row['zeit']."-".$row['id'].".".$row['datei_endung']."")) {
205                                $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']);
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
225                require_once(WCF_DIR.'lib/data/message/attachment/AttachmentsEditor.class.php');
226                       
227                $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);
228                while($row = $this->getDB()->fetchArray($result)) {
229               
230                        $source = $this->settings['sourcePath']."jgs_db_bilder/bild-".$row['zeit']."-".$row['id'].".jpg";
231                        if(file_exists($source)) {
232                       
233                                $attachmentName = $row['bild_name'].".jpg";
234                       
235                                $item = $this->getImporter()->getImportKey("i".$row['eintrags_id']); 
236
237                                $attachment = array(
238                                        "attachmentSize" => filesize($source),
239                                        "sha1Hash" => sha1_file($source),
240                                        "fileType" => "image/jpeg",
241                                        "isBinary" => 1,
242                                        "isImage" => 1,
243                                        "messageID" => $item['value'],
244                                        "messageType" => "database",
245                                        "packageID" => PACKAGE_ID,
246                                        "idHash" => StringUtil::getRandomID(),
247                                        "userID" => $row['userid'],
248                                        "uploadTime" => $row['zeit']
249                                );
250
251                                $attachment['attachmentID'] = AttachmentsEditor::insert($attachmentName, $attachment);
252                                $attachment['attachmentName'] = $attachmentName;
253                                $attachment['attachment'] = WCF_DIR.'attachments/attachment-'.$attachment['attachmentID'];
254                                $attachment['attachmentExtension'] = 'jgp';
255                               
256                                @copy($source,$attachment['attachment']);
257                               
258                                AttachmentsEditor::saveThumbnail($attachment);
259                        } 
260                }
261        }
262       
263        /**
264         * @see AbstractDatabaseExporter::exportActivation();
265         */
266        public function exportActivation($offset,$limit) {
267                $result = $this->getDB()->sendQuery("SELECT id FROM ".$this->dbPrefix."bb".$this->settings['dbNumber']."_jgs_db_eintrag",$limit,$offset);
268                while($row = $this->getDB()->fetchArray($result)) {
269                        $this->getImporter()->activateItem("i".$row['id']);
270                }
271        }
272       
273}
274?>
Note: See TracBrowser for help on using the browser.