mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-05-14 02:03:55 -04:00
Import of articles is implemented!
- Remove massiveImportAction and addCategories from FeedController - Fix typo for some methods (camelCase) - addCategoryObject and addFeedObject return id if corresponding object already exists in DB - introduce addEntryObject. Return -1 if Entry already exist (in order to keep quite good performances) - Complete importArticles method Need some more tests + better performance
This commit is contained in:
@@ -327,82 +327,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
|
||||
}
|
||||
}
|
||||
|
||||
public function massiveImportAction () {
|
||||
# TODO: this function has moved to importExportController.php
|
||||
# I keep it for the moment but should be deleted in a near future.
|
||||
@set_time_limit(300);
|
||||
|
||||
$this->catDAO = new FreshRSS_CategoryDAO ();
|
||||
$this->catDAO->checkDefault ();
|
||||
|
||||
$entryDAO = new FreshRSS_EntryDAO ();
|
||||
$feedDAO = new FreshRSS_FeedDAO ();
|
||||
|
||||
$categories = Minz_Request::param ('categories', array (), true);
|
||||
$feeds = Minz_Request::param ('feeds', array (), true);
|
||||
|
||||
// on ajoute les catégories en masse dans une fonction à part
|
||||
$this->addCategories ($categories);
|
||||
|
||||
// on calcule la date des articles les plus anciens qu'on accepte
|
||||
$nb_month_old = $this->view->conf->old_entries;
|
||||
$date_min = time () - (3600 * 24 * 30 * $nb_month_old);
|
||||
|
||||
// la variable $error permet de savoir si une erreur est survenue
|
||||
// Le but est de ne pas arrêter l'import même en cas d'erreur
|
||||
// L'utilisateur sera mis au courant s'il y a eu des erreurs, mais
|
||||
// ne connaîtra pas les détails. Ceux-ci seront toutefois logguées
|
||||
$error = false;
|
||||
$i = 0;
|
||||
foreach ($feeds as $feed) {
|
||||
try {
|
||||
$values = array (
|
||||
'id' => $feed->id (),
|
||||
'url' => $feed->url (),
|
||||
'category' => $feed->category (),
|
||||
'name' => $feed->name (),
|
||||
'website' => $feed->website (),
|
||||
'description' => $feed->description (),
|
||||
'lastUpdate' => 0,
|
||||
'httpAuth' => $feed->httpAuth ()
|
||||
);
|
||||
|
||||
// ajout du flux que s'il n'est pas déjà en BDD
|
||||
if (!$feedDAO->searchByUrl ($values['url'])) {
|
||||
$id = $feedDAO->addFeed ($values);
|
||||
if ($id) {
|
||||
$feed->_id ($id);
|
||||
$feed->faviconPrepare();
|
||||
} else {
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
} catch (FreshRSS_Feed_Exception $e) {
|
||||
$error = true;
|
||||
Minz_Log::record ($e->getMessage (), Minz_Log::WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
$res = Minz_Translate::t ('feeds_imported_with_errors');
|
||||
} else {
|
||||
$res = Minz_Translate::t ('feeds_imported');
|
||||
}
|
||||
|
||||
$notif = array (
|
||||
'type' => 'good',
|
||||
'content' => $res
|
||||
);
|
||||
Minz_Session::_param ('notification', $notif);
|
||||
Minz_Session::_param ('actualize_feeds', true);
|
||||
|
||||
// et on redirige vers la page d'accueil
|
||||
Minz_Request::forward (array (
|
||||
'c' => 'index',
|
||||
'a' => 'index'
|
||||
), true);
|
||||
}
|
||||
|
||||
public function deleteAction () {
|
||||
if (Minz_Request::isPost ()) {
|
||||
$type = Minz_Request::param ('type', 'feed');
|
||||
@@ -446,16 +370,4 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function addCategories ($categories) {
|
||||
foreach ($categories as $cat) {
|
||||
if (!$this->catDAO->searchByName ($cat->name ())) {
|
||||
$values = array (
|
||||
'id' => $cat->id (),
|
||||
'name' => $cat->name (),
|
||||
);
|
||||
$catDAO->addCategory ($values);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user