[Patch] Fix af_readability/init.php bad use of empty array

Development-related discussion, including bundled plugins
troyengel
Bear Rating Trainee
Bear Rating Trainee
Posts: 18
Joined: 23 Mar 2013, 19:39

[Patch] Fix af_readability/init.php bad use of empty array

Postby troyengel » 29 Nov 2015, 20:25

I created a gitlab account but can't fork or create an issue, sorry - posting a proposed patch here. I did a fresh git pull and enabled af_readability for the first time (checking it out to try and resolve some crappy feed content) and saw this in the logs:

Code: Select all

E_WARNING (2)   plugins/af_readability/init.php:186   Invalid argument supplied for foreach()


Proposed patch:

Code: Select all

$ diff -uN init.php.orig init.php
--- init.php.orig   2015-11-29 17:14:23.000000000 +0000
+++ init.php   2015-11-29 17:20:05.000000000 +0000
@@ -33,9 +33,11 @@
       print_notice("Enable the plugin for specific feeds in the feed editor.");
 
       $enabled_feeds = $this->host->get($this, "enabled_feeds");
-      if (!array($enabled_feeds)) $enabled_feeds = array();
-
-      $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds);
+      if (!array($enabled_feeds)) {
+         $enabled_feeds = array();
+      } else {
+         $enabled_feeds = $this->filter_unknown_feeds($enabled_feeds);
+      }
       $this->host->set($this, "enabled_feeds", $enabled_feeds);
 
       if (count($enabled_feeds) > 0) {
@@ -183,12 +185,14 @@
    private function filter_unknown_feeds($enabled_feeds) {
       $tmp = array();
 
-      foreach ($enabled_feeds as $feed) {
+       if (!empty($enabled_feeds)) {
+         foreach ($enabled_feeds as $feed) {
 
-         $result = db_query("SELECT id FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
+            $result = db_query("SELECT id FROM ttrss_feeds WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
 
-         if (db_num_rows($result) != 0) {
-            array_push($tmp, $feed);
+            if (db_num_rows($result) != 0) {
+               array_push($tmp, $feed);
+            }
          }
       }


Several ways to tackle it though, dealer's choice.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: [Patch] Fix af_readability/init.php bad use of empty array

Postby fox » 29 Nov 2015, 21:24

how about you post your gitlab account name, i'll add you to the "can make branches and do stuff" group

troyengel
Bear Rating Trainee
Bear Rating Trainee
Posts: 18
Joined: 23 Mar 2013, 19:39

Re: [Patch] Fix af_readability/init.php bad use of empty array

Postby troyengel » 29 Nov 2015, 21:34

troyengel (same as here) thx, I'll do the needful and submit a pull request

troyengel
Bear Rating Trainee
Bear Rating Trainee
Posts: 18
Joined: 23 Mar 2013, 19:39

Re: [Patch] Fix af_readability/init.php bad use of empty array

Postby troyengel » 02 Dec 2015, 03:53

Andrew, can you check my "maximum projects" setting? Attempting to fork results in:

Fork Error!
You tried to fork Andrew Dolgov / tt-rss but it failed for the following reason:
– Limit reached Your project limit is 0 projects! Please contact your administrator to increase it


I thought maybe it was a random delay after you activated my access so waited a day and tried again tonight, same above error. :-/

JustAMacUser
Bear Rating Overlord
Bear Rating Overlord
Posts: 373
Joined: 20 Aug 2013, 23:13

Re: [Patch] Fix af_readability/init.php bad use of empty array

Postby JustAMacUser » 02 Dec 2015, 05:52

fox lets you create branches and GitLab will allow you to request a merge after you've pushed your branch to it. No forking needed.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: [Patch] Fix af_readability/init.php bad use of empty array

Postby fox » 02 Dec 2015, 08:22

it's on the wiki even :p

troyengel
Bear Rating Trainee
Bear Rating Trainee
Posts: 18
Joined: 23 Mar 2013, 19:39

Re: [Patch] Fix af_readability/init.php bad use of empty array

Postby troyengel » 04 Dec 2015, 23:06

I gave it a shot, think I got it right - I've not worked in this manner before so it's a slightly off-kilter method but nothing hard. :) Perhaps we could update the wiki with a sample session showing how it's done for others who are not used to this method of usage and/or Gitlab, something like...

Code: Select all

$ git clone [email protected]:fox/tt-rss.git && cd tt-rss
$ git config user.email "[email protected]"
$ git config user.name "My Name"
$ git checkout -b <new-branch-name-with-sensible-name>
$ vim path/to/code.php
$ git commit -m "My fixes" path/to/code.php
$ git push origin <new-branch-name-with-sensible-name>

Now visit https://tt-rss.org/gitlab/fox/tt-rss/commits/master, switch to the branch just pushed upstream in the upper left dropdown box. On the new branch a green "Create Merge Request" in the upper right will be available to generate the pull request from your new branch into master.

Be sure to double-check the pull request diff to ensure the results are as desired.


It's 99% close to what most public docs say, just without the forking business. I'm one of the huge majority who is used to doing things the github.com way, needed a little help to adjust to no forking and the Gitlab way is all.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: [Patch] Fix af_readability/init.php bad use of empty array

Postby fox » 05 Dec 2015, 02:51

this makes sense, I'll link this post in the how to contribute wiki page.

troyengel
Bear Rating Trainee
Bear Rating Trainee
Posts: 18
Joined: 23 Mar 2013, 19:39

Re: [Patch] Fix af_readability/init.php bad use of empty array

Postby troyengel » 06 Dec 2015, 00:44

Updating here after we worked together on Gitlab - in addition to the above, 3 more tasks:

1. If further changes need to be pushed up to that branch, first set the remote origin as upstream:

Code: Select all

$ git branch -u origin/<new-branch-name-with-sensible-name>


Now dev and push updates as you normally would to the remote branch. Note you can also set the upstream while you're pushing the newest change, in case you forgot: git push --set-upstream origin <new-branch-name-with-sensible-name>

2. After the Merge Request has been accepted and merged into master, the person making the branch is responsible for cleaning it up. On the Merge Request screen will be a button at the top middle-left allowing you to remove that branch with one button click. Note that this is cleaning up the master Gitlab source tree, not your local checkout.

3. Clean up your local code tree to get rid of the branch and reset:

Code: Select all

$ git checkout master
$ git pull
$ git branch -d <new-branch-name-with-sensible-name>
$ git remote prune origin


Your local code tree should now be ready for the next branch/dev cycle - the "remote prune origin" synchronizes your local cached copy with the remote branches, you should see a message like so:

Code: Select all

$ git remote prune origin
Pruning origin
URL: [email protected]:fox/tt-rss.git
 * [pruned] origin/<new-branch-name-with-sensible-name>


Run a "git branch -r" to confirm your temporary dev branch is gone.


Return to “Development”

Who is online

Users browsing this forum: No registered users and 2 guests