aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers/importExportController.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-29 11:08:31 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-29 11:08:31 +0100
commitfb3cda8ac9f7c8895ed33d7db432a92b063a7198 (patch)
tree3f310bbe1efef4203cab8ebc66ad77e1ebb8d8da /app/Controllers/importExportController.php
parentcf7350af4768809c8b5117ba586f5165a4e2b1a8 (diff)
Fix limits in import OPML files
See https://github.com/marienfressinaud/FreshRSS/issues/680
Diffstat (limited to 'app/Controllers/importExportController.php')
-rw-r--r--app/Controllers/importExportController.php55
1 files changed, 43 insertions, 12 deletions
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php
index ab277e688..514077bbd 100644
--- a/app/Controllers/importExportController.php
+++ b/app/Controllers/importExportController.php
@@ -176,19 +176,43 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
*/
private function addOpmlElements($opml_elements, $parent_cat = null) {
$error = false;
+
+ $nb_feeds = count($this->feedDAO->listFeeds());
+ $nb_cats = count($this->catDAO->listCategories(false));
+ $limits = Minz_Configuration::limits();
+
foreach ($opml_elements as $elt) {
- $res = false;
+ $is_error = false;
if (isset($elt['xmlUrl'])) {
// If xmlUrl exists, it means it is a feed
- $res = $this->addFeedOpml($elt, $parent_cat);
+ if ($nb_feeds >= $limits['max_feeds']) {
+ Minz_Log::warning(_t('sub.feeds.over_max',
+ $limits['max_feeds']));
+ $is_error = true;
+ continue;
+ }
+
+ $is_error = $this->addFeedOpml($elt, $parent_cat);
+ if (!$is_error) {
+ $nb_feeds += 1;
+ }
} else {
// No xmlUrl? It should be a category!
- $res = $this->addCategoryOpml($elt, $parent_cat);
+ $limit_reached = ($nb_cats >= $limits['max_categories']);
+ if ($limit_reached) {
+ Minz_Log::warning(_t('sub.categories.over_max',
+ $limits['max_categories']));
+ }
+
+ $is_error = $this->addCategoryOpml($elt, $parent_cat, $limit_reached);
+ if (!$is_error) {
+ $nb_cats += 1;
+ }
}
- if (!$error && $res) {
+ if (!$error && $is_error) {
// oops: there is at least one error!
- $error = $res;
+ $error = $is_error;
}
}
@@ -203,16 +227,18 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
* @return boolean true if an error occured, false else.
*/
private function addFeedOpml($feed_elt, $parent_cat) {
+ $default_cat = $this->catDAO->getDefault();
if (is_null($parent_cat)) {
// This feed has no parent category so we get the default one
- $parent_cat = $this->catDAO->getDefault()->name();
+ $parent_cat = $default_cat->name();
}
$cat = $this->catDAO->searchByName($parent_cat);
- if (!$cat) {
+ if (is_null($cat)) {
// If there is not $cat, it means parent category does not exist in
- // database. It should not happened!
- return true;
+ // database.
+ // If it happens, take the default category.
+ $cat = $default_cat;
}
// We get different useful information
@@ -253,14 +279,19 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
*
* @param array $cat_elt an OPML element (must be a category element).
* @param string $parent_cat the name of the parent category.
+ * @param boolean $cat_limit_reached indicates if category limit has been reached.
+ * if yes, category is not added (but we try for feeds!)
* @return boolean true if an error occured, false else.
*/
- private function addCategoryOpml($cat_elt, $parent_cat) {
+ private function addCategoryOpml($cat_elt, $parent_cat, $cat_limit_reached) {
// Create a new Category object
$cat = new FreshRSS_Category(Minz_Helper::htmlspecialchars_utf8($cat_elt['text']));
- $id = $this->catDAO->addCategoryObject($cat);
- $error = ($id === false);
+ $error = true;
+ if (!$cat_limit_reached) {
+ $id = $this->catDAO->addCategoryObject($cat);
+ $error = ($id === false);
+ }
if (isset($cat_elt['@outlines'])) {
// Our cat_elt contains more categories or more feeds, so we