summaryrefslogtreecommitdiffstats
path: root/apps/bookmarks/lib/migrate.php
blob: c655154d41b65f8a437a488762ad03ad3cc9b1d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
class OC_Migrate_Provider_Bookmarks extends OC_Migrate_Provider{
	
	// Create the xml for the user supplied
	function export($uid){
		
		$doc = new DOMDocument();
		$doc->formatOutput = true;
		$bookmarks = $doc->createElement('bookmarks');
		$bookmarks = $doc->appendChild($bookmarks);
		
		$query = OC_DB::prepare("SELECT * FROM  *PREFIX*bookmarks WHERE  *PREFIX*bookmarks.user_id =  ?");
		$bookmarksdata =& $query->execute(array($uid));
		
		
		// Foreach bookmark
		while ($row = $bookmarksdata->fetchRow()) {
			$bookmark = $doc->createElement('bookmark');
			$bookmark = $bookmarks->appendChild($bookmark);
			
			$attr = $doc->createElement('title');
			$attr = $bookmark->appendChild($attr);
			$value = $doc->createTextNode($row['title']);
			$attr->appendChild($value);
			
			$attr = $doc->createElement('url');
			$attr = $bookmark->appendChild($attr);
			$value = $doc->createTextNode($row['url']);
			$attr->appendChild($value);
			
			$attr = $doc->createElement('added');
			$attr = $bookmark->appendChild($attr);
			$value = $doc->createTextNode($row['added']);
			$attr->appendChild($value);
			
			$attr = $doc->createElement('lastmodified');
			$attr = $bookmark->appendChild($attr);
			$value = $doc->createTextNode($row['lastmodified']);
			$attr->appendChild($value);
			
			$attr = $doc->createElement('public');
			$attr = $bookmark->appendChild($attr);
			$value = $doc->createTextNode($row['public']);
			$attr->appendChild($value);
			
			$attr = $doc->createElement('clickcount');
			$attr = $bookmark->appendChild($attr);
			$value = $doc->createTextNode($row['clickcount']);
			$attr->appendChild($value);
			
			$attr = $doc->createElement('tags');
			$tags = $bookmark->appendChild($attr);
			
			$query = OC_DB::prepare("SELECT * FROM  *PREFIX*bookmarks_tags WHERE  *PREFIX*bookmarks_tags.bookmark_id =  ?");
			$tagsdata =& $query->execute(array($row['id']));
		
			// Foreach tag
			while ($row = $tagsdata->fetchRow()) {
				$attr = $doc->createElement('tag');
				$attr = $tags->appendChild($attr);
				$value = $doc->createTextNode($row['tag']);
				$attr->appendChild($value);
			}	
		}
		
		return $doc;
		
	}
	
}

new OC_Migrate_Provider_Bookmarks('bookmarks');