Last active
December 14, 2015 23:59
-
-
Save jbfavre/5169623 to your computer and use it in GitHub Desktop.
Little script to import into selfoss data from rsslounge. DB structure are quite close, so it's easy. **Warnings**: - Provide your own DB credentials line 2 & 3
- For category -> tag migration, default value was "Sans catégorie" (in french). Beware to adapt it to your rsslounge value (line 34)
- Since I only use RSS feeds in rsslounge, I could n…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$rssloungeDB="rsslounge"; | |
$selfossDB="selfoss"; | |
$rsslounge= new mysqli("localhost", "username", "password", $rssloungeDB); | |
$selfoss= new mysqli("localhost", "username", "password", $selfossDB); | |
/* Export categories into tags */ | |
$categories_query="select name from ".$rssloungeDB.".categories where ".$rssloungeDB.".categories.id>0"; | |
$categories= $rsslounge->prepare($categories_query); | |
$categories->execute(); | |
$categories->bind_result($tag); | |
$tags=''; | |
$tags_query="insert into ".$selfossDB.".tags (tag,color) values (?, '#FFFFFF')"; | |
while ($categories->fetch()) { | |
if (!$tags = $selfoss->prepare($tags_query)) { | |
die ($tags->error); | |
} | |
$tags->bind_param('s', $tag); | |
$tags->execute(); | |
} | |
$categories->free_result(); | |
if ($tags!='') | |
$tags->free_result(); | |
/* Export feeds into sources */ | |
$feeds_query="select ".$rssloungeDB.".feeds.`id`, ".$rssloungeDB.".feeds.`name`, ".$rssloungeDB.".categories.`name`, `url` from ".$rssloungeDB.".feeds, ".$rssloungeDB.".categories where ".$rssloungeDB.".feeds.category=".$rssloungeDB.".categories.id order by id"; | |
$feeds = $rsslounge->prepare($feeds_query); | |
$feeds->execute(); | |
$feeds->bind_result($id, $name, $category, $url); | |
$sources=''; | |
$sources_query = "insert into ".$selfossDB.".sources (id, title, tags, spout, params, error) values (?, ?, ?, ?, ?, NULL)"; | |
while ($feeds->fetch()) { | |
$title = $name; | |
$tags = ($category==="Sans catégorie")?"":$category; | |
$spout = 'spouts\rss\feed'; | |
$params = htmlentities(json_encode(array( "url" => $url ))); | |
$sources = $selfoss->prepare($sources_query); | |
$sources->bind_param('issss', $id, $title, $tags, $spout, $params); | |
$sources->execute(); | |
} | |
$feeds->free_result(); | |
if ($sources!='') | |
$sources->free_result(); | |
/* Export items into items */ | |
$olditems_query="select `id`, `datetime`, `title`, `content`, `unread`, `starred`, `feed`, `uid`, `link` from ".$rssloungeDB.".items"; | |
$olditems = $rsslounge->prepare($olditems_query); | |
$olditems->execute(); | |
$olditems->bind_result($id, $datetime, $title, $content, $unread, $starred, $source, $uid, $link); | |
$items=''; | |
$items_query="insert into ".$selfossDB.".items(`id`, `datetime`, `title`, `content`, `unread`, `starred`, `source`, `uid`, `link`) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"; | |
while ($olditems->fetch()) { | |
$items = $selfoss->prepare($items_query); | |
$items->bind_param('isssiisss', $id, $datetime, $title, $content, $unread, $starred, $source, $uid, $link); | |
$items->execute(); | |
} | |
$olditems->free_result(); | |
if ($items!='') | |
$items->free_result(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment