{"action":"created","comment":{"url":"https://api.github.com/repos/meumobi/sitebuilder/pulls/comments/33821384","id":33821384,"diff_hunk":"@@ -1,126 +1,59 @@\n <?php\n-//TODO order and rename methods\n-//TODO clean code, arrays, indentation etc.\n-//TODO refactor old imported Articles methods\n \n namespace meumobi\\sitebuilder\\workers;\n \n-require_once 'lib/dom/SimpleHtmlDom.php';\n-require_once 'lib/simplepie/SimplePie.php';\n-require_once 'lib/utils/Video.php';\n-\n-use DOMDocument;\n-use Filesystem;\n-use HTMLPurifier;\n-use HTMLPurifier_Config;\n-use Mapper;\n-use SimplePie;\n-use Video;\n-use app\\models\\Items;\n+use Exception;\n use app\\models\\extensions\\Rss;\n-use app\\models\\items\\Articles;\n-use lithium\\data\\Connections;\n use meumobi\\sitebuilder\\Logger;\n-use meumobi\\sitebuilder\\repositories\\RecordNotFoundException;//TODO move exceptions for a more generic namespace\n-use meumobi\\sitebuilder\\services\\ItemCreation;\n+use meumobi\\sitebuilder\\repositories\\RecordNotFoundException;\n+use meumobi\\sitebuilder\\services\\UpdateNewsFeed;\n \n-class UpdateFeedsWorker extends Worker\n+class UpdateFeedsWorker\n {\n-\tconst ARTICLES_TO_KEEP = 50;\n-\n-\tprotected $category;\n-\tprotected $extension;\n \tprotected $priority = Worker::PRIORITY_LOW;\n-\tprotected $blacklist = ['gravatar.com'];\n-\tprotected $stats = [\n-\t\t'total_updated_feeds' => 0,\n-\t\t'total_failed_feeds' => 0,\n-\t\t'failed_feeds'=> [],\n-\t\t'extensions' => []\n-\t];\n \n-\tpublic function perform()\n+\tpublic function perform($params)\n \t{\n+\t\tLogger::info('workers', 'updating feeds', $params);\n \t\t$start = microtime(true);\n-\t\tLogger::info('workers', 'updating feeds', [ 'priority' => $this->priority ]);\n-\t\t$itemCreationService = new ItemCreation();\n-\t\tarray_walk($this->getExtensionsIds(), [$this, 'updateFromFeed'], $itemCreationService);\n-\n-\t\tif($this->stats['extensions']) {\n-\t\t\tLogger::info('workers', 'updated feeds', $this->stats['extensions']);\n-\t\t}\n-\n-\t\tunset($this->stats['extensions']);\n-\t\t$this->stats['priority'] = $this->getPriority();\n-\t\t$this->stats['elapsed_time'] = microtime(true) - $start;\n-\t\tLogger::info('workers', 'finished updating feeds', $this->stats);\n-\t}\n-\n-\tprotected function getPriority()\n-\t{\n-\t\treturn $this->priority;\n-\t}\n-\n-\tprotected function updateFromFeed($extensionId, $key, $itemCreationService)\n-\t{\n-\t\t$this->stats['extensions'][$extensionId] = [\n-\t\t\t'extension_id' => $extensionId,\n-\t\t\t'total_articles' => 0,\n-\t\t\t'updated_articles' => 0,\n-\t\t\t'created_articles' => 0,\n-\t\t\t'removed_articles' => 0,\n-\t\t\t'total_images' => 0,\n-\t\t\t'failed_images' => 0,\n+\t\t$stats = $params + [\n+\t\t\t'total_updated_feeds' => 0,\n+\t\t\t'total_failed_feeds' => 0,\n+\t\t\t'failed_feeds'=> [],\n+\t\t\t'categories' => []\n \t\t];\n-\n-\t\ttry {\n-\t\t\t$this->extension = $this->getExtension($extensionId);\n-\t\t\t$this->category = $this->getCategory($this->extension);\n-\t\t\t$this->stats['extensions'][$extensionId]['category_id'] = $this->category->id();\n-\n-\t\t\t$feed = $this->getFeed();\n-\t\t\t$this->updateArticles($feed, $itemCreationService);\n-\t\t\t$this->removeOldArticles();\n-\n-\t\t\t$this->category->updated = date('Y-m-d H:i:s');\n-\t\t\t$this->category->save();\n-\n-\t\t\t$this->extension->priority = self::PRIORITY_LOW;\n-\t\t\t$this->extension->save(null, ['callbacks' => false]);\n-\t\t\t$this->stats['total_updated_feeds'] += 1;\n-\t\t} catch (\\Exception $e) {\n-\t\t\tunset($this->stats['extensions'][$extensionId]);\n-\t\t\t$this->stats['total_failed_feeds'] += 1;\n-\t\t\t$this->stats['failed_feeds'][] = [\n-\t\t\t\t'extension_id' => $extensionId,\n-\t\t\t\t'error' => $e->getMessage(),\n-\t\t\t];\n+\t\t$extensions = $this->getExtensionsByPriority($params['priority']);\n+\n+\t\tforeach($extensions as $extension) {","path":"sitebuilder/lib/meumobi/sitebuilder/workers/UpdateFeedsWorker.php","position":112,"original_position":111,"commit_id":"a1f97a7106024f38fe994597f3f7d81bbd4ed3fe","original_commit_id":"6a95a3fe494095d00d735c06ae2ed6542ef23472","user":{"login":"juliogreff","id":58992,"avatar_url":"https://avatars.githubusercontent.com/u/58992?v=3","gravatar_id":"","url":"https://api.github.com/users/juliogreff","html_url":"https://github.com/juliogreff","followers_url":"https://api.github.com/users/juliogreff/followers","following_url":"https://api.github.com/users/juliogreff/following{/other_user}","gists_url":"https://api.github.com/users/juliogreff/gists{/gist_id}","starred_url":"https://api.github.com/users/juliogreff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliogreff/subscriptions","organizations_url":"https://api.github.com/users/juliogreff/orgs","repos_url":"https://api.github.com/users/juliogreff/repos","events_url":"https://api.github.com/users/juliogreff/events{/privacy}","received_events_url":"https://api.github.com/users/juliogreff/received_events","type":"User","site_admin":false},"body":"Still not addressed","created_at":"2015-07-02T20:50:09Z","updated_at":"2015-07-02T20:50:09Z","html_url":"https://github.com/meumobi/sitebuilder/pull/124#discussion_r33821384","pull_request_url":"https://api.github.com/repos/meumobi/sitebuilder/pulls/124","_links":{"self":{"href":"https://api.github.com/repos/meumobi/sitebuilder/pulls/comments/33821384"},"html":{"href":"https://github.com/meumobi/sitebuilder/pull/124#discussion_r33821384"},"pull_request":{"href":"https://api.github.com/repos/meumobi/sitebuilder/pulls/124"}}},"pull_request":{"url":"https://api.github.com/repos/meumobi/sitebuilder/pulls/124","id":38283188,"html_url":"https://github.com/meumobi/sitebuilder/pull/124","diff_url":"https://github.com/meumobi/sitebuilder/pull/124.diff","patch_url":"https://github.com/meumobi/sitebuilder/pull/124.patch","issue_url":"https://api.github.com/repos/meumobi/sitebuilder/issues/124","number":124,"state":"open","locked":false,"title":"Extract feed parsing and item creation from UpdateFeedsWorker","user":{"login":"t4deu","id":1649955,"avatar_url":"https://avatars.githubusercontent.com/u/1649955?v=3","gravatar_id":"","url":"https://api.github.com/users/t4deu","html_url":"https://github.com/t4deu","followers_url":"https://api.github.com/users/t4deu/followers","following_url":"https://api.github.com/users/t4deu/following{/other_user}","gists_url":"https://api.github.com/users/t4deu/gists{/gist_id}","starred_url":"https://api.github.com/users/t4deu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/t4deu/subscriptions","organizations_url":"https://api.github.com/users/t4deu/orgs","repos_url":"https://api.github.com/users/t4deu/repos","events_url":"https://api.github.com/users/t4deu/events{/privacy}","received_events_url":"https://api.github.com/users/t4deu/received_events","type":"User","site_admin":false},"body":"Closes #120.","created_at":"2015-06-22T22:21:38Z","updated_at":"2015-07-02T20:50:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"79f7851828bd6b073ef9e0c9f84da31be615c195","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/meumobi/sitebuilder/pulls/124/commits","review_comments_url":"https://api.github.com/repos/meumobi/sitebuilder/pulls/124/comments","review_comment_url":"https://api.github.com/repos/meumobi/sitebuilder/pulls/comments{/number}","comments_url":"https://api.github.com/repos/meumobi/sitebuilder/issues/124/comments","statuses_url":"https://api.github.com/repos/meumobi/sitebuilder/statuses/a1f97a7106024f38fe994597f3f7d81bbd4ed3fe","head":{"label":"meumobi:refact/extract-feed-parsing-from-worker","ref":"refact/extract-feed-parsing-from-worker","sha":"a1f97a7106024f38fe994597f3f7d81bbd4ed3fe","user":{"login":"meumobi","id":4675304,"avatar_url":"https://avatars.githubusercontent.com/u/4675304?v=3","gravatar_id":"","url":"https://api.github.com/users/meumobi","html_url":"https://github.com/meumobi","followers_url":"https://api.github.com/users/meumobi/followers","following_url":"https://api.github.com/users/meumobi/following{/other_user}","gists_url":"https://api.github.com/users/meumobi/gists{/gist_id}","starred_url":"https://api.github.com/users/meumobi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meumobi/subscriptions","organizations_url":"https://api.github.com/users/meumobi/orgs","repos_url":"https://api.github.com/users/meumobi/repos","events_url":"https://api.github.com/users/meumobi/events{/privacy}","received_events_url":"https://api.github.com/users/meumobi/received_events","type":"Organization","site_admin":false},"repo":{"id":26373485,"name":"sitebuilder","full_name":"meumobi/sitebuilder","owner":{"login":"meumobi","id":4675304,"avatar_url":"https://avatars.githubusercontent.com/u/4675304?v=3","gravatar_id":"","url":"https://api.github.com/users/meumobi","html_url":"https://github.com/meumobi","followers_url":"https://api.github.com/users/meumobi/followers","following_url":"https://api.github.com/users/meumobi/following{/other_user}","gists_url":"https://api.github.com/users/meumobi/gists{/gist_id}","starred_url":"https://api.github.com/users/meumobi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meumobi/subscriptions","organizations_url":"https://api.github.com/users/meumobi/orgs","repos_url":"https://api.github.com/users/meumobi/repos","events_url":"https://api.github.com/users/meumobi/events{/privacy}","received_events_url":"https://api.github.com/users/meumobi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/meumobi/sitebuilder","description":"","fork":false,"url":"https://api.github.com/repos/meumobi/sitebuilder","forks_url":"https://api.github.com/repos/meumobi/sitebuilder/forks","keys_url":"https://api.github.com/repos/meumobi/sitebuilder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/meumobi/sitebuilder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/meumobi/sitebuilder/teams","hooks_url":"https://api.github.com/repos/meumobi/sitebuilder/hooks","issue_events_url":"https://api.github.com/repos/meumobi/sitebuilder/issues/events{/number}","events_url":"https://api.github.com/repos/meumobi/sitebuilder/events","assignees_url":"https://api.github.com/repos/meumobi/sitebuilder/assignees{/user}","branches_url":"https://api.github.com/repos/meumobi/sitebuilder/branches{/branch}","tags_url":"https://api.github.com/repos/meumobi/sitebuilder/tags","blobs_url":"https://api.github.com/repos/meumobi/sitebuilder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/meumobi/sitebuilder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/meumobi/sitebuilder/git/refs{/sha}","trees_url":"https://api.github.com/repos/meumobi/sitebuilder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/meumobi/sitebuilder/statuses/{sha}","languages_url":"https://api.github.com/repos/meumobi/sitebuilder/languages","stargazers_url":"https://api.github.com/repos/meumobi/sitebuilder/stargazers","contributors_url":"https://api.github.com/repos/meumobi/sitebuilder/contributors","subscribers_url":"https://api.github.com/repos/meumobi/sitebuilder/subscribers","subscription_url":"https://api.github.com/repos/meumobi/sitebuilder/subscription","commits_url":"https://api.github.com/repos/meumobi/sitebuilder/commits{/sha}","git_commits_url":"https://api.github.com/repos/meumobi/sitebuilder/git/commits{/sha}","comments_url":"https://api.github.com/repos/meumobi/sitebuilder/comments{/number}","issue_comment_url":"https://api.github.com/repos/meumobi/sitebuilder/issues/comments{/number}","contents_url":"https://api.github.com/repos/meumobi/sitebuilder/contents/{+path}","compare_url":"https://api.github.com/repos/meumobi/sitebuilder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/meumobi/sitebuilder/merges","archive_url":"https://api.github.com/repos/meumobi/sitebuilder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/meumobi/sitebuilder/downloads","issues_url":"https://api.github.com/repos/meumobi/sitebuilder/issues{/number}","pulls_url":"https://api.github.com/repos/meumobi/sitebuilder/pulls{/number}","milestones_url":"https://api.github.com/repos/meumobi/sitebuilder/milestones{/number}","notifications_url":"https://api.github.com/repos/meumobi/sitebuilder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/meumobi/sitebuilder/labels{/name}","releases_url":"https://api.github.com/repos/meumobi/sitebuilder/releases{/id}","created_at":"2014-11-08T20:21:22Z","updated_at":"2015-05-08T19:11:50Z","pushed_at":"2015-07-02T20:06:20Z","git_url":"git://github.com/meumobi/sitebuilder.git","ssh_url":"git@github.com:meumobi/sitebuilder.git","clone_url":"https://github.com/meumobi/sitebuilder.git","svn_url":"https://github.com/meumobi/sitebuilder","homepage":null,"size":17736,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":42,"forks":0,"open_issues":42,"watchers":0,"default_branch":"master"}},"base":{"label":"meumobi:master","ref":"master","sha":"0f4a42f5187a480a30aa924c950e9ce13c13a4ea","user":{"login":"meumobi","id":4675304,"avatar_url":"https://avatars.githubusercontent.com/u/4675304?v=3","gravatar_id":"","url":"https://api.github.com/users/meumobi","html_url":"https://github.com/meumobi","followers_url":"https://api.github.com/users/meumobi/followers","following_url":"https://api.github.com/users/meumobi/following{/other_user}","gists_url":"https://api.github.com/users/meumobi/gists{/gist_id}","starred_url":"https://api.github.com/users/meumobi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meumobi/subscriptions","organizations_url":"https://api.github.com/users/meumobi/orgs","repos_url":"https://api.github.com/users/meumobi/repos","events_url":"https://api.github.com/users/meumobi/events{/privacy}","received_events_url":"https://api.github.com/users/meumobi/received_events","type":"Organization","site_admin":false},"repo":{"id":26373485,"name":"sitebuilder","full_name":"meumobi/sitebuilder","owner":{"login":"meumobi","id":4675304,"avatar_url":"https://avatars.githubusercontent.com/u/4675304?v=3","gravatar_id":"","url":"https://api.github.com/users/meumobi","html_url":"https://github.com/meumobi","followers_url":"https://api.github.com/users/meumobi/followers","following_url":"https://api.github.com/users/meumobi/following{/other_user}","gists_url":"https://api.github.com/users/meumobi/gists{/gist_id}","starred_url":"https://api.github.com/users/meumobi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meumobi/subscriptions","organizations_url":"https://api.github.com/users/meumobi/orgs","repos_url":"https://api.github.com/users/meumobi/repos","events_url":"https://api.github.com/users/meumobi/events{/privacy}","received_events_url":"https://api.github.com/users/meumobi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/meumobi/sitebuilder","description":"","fork":false,"url":"https://api.github.com/repos/meumobi/sitebuilder","forks_url":"https://api.github.com/repos/meumobi/sitebuilder/forks","keys_url":"https://api.github.com/repos/meumobi/sitebuilder/keys{/key_id}","collaborators_url":"https://api.github.com/repos/meumobi/sitebuilder/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/meumobi/sitebuilder/teams","hooks_url":"https://api.github.com/repos/meumobi/sitebuilder/hooks","issue_events_url":"https://api.github.com/repos/meumobi/sitebuilder/issues/events{/number}","events_url":"https://api.github.com/repos/meumobi/sitebuilder/events","assignees_url":"https://api.github.com/repos/meumobi/sitebuilder/assignees{/user}","branches_url":"https://api.github.com/repos/meumobi/sitebuilder/branches{/branch}","tags_url":"https://api.github.com/repos/meumobi/sitebuilder/tags","blobs_url":"https://api.github.com/repos/meumobi/sitebuilder/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/meumobi/sitebuilder/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/meumobi/sitebuilder/git/refs{/sha}","trees_url":"https://api.github.com/repos/meumobi/sitebuilder/git/trees{/sha}","statuses_url":"https://api.github.com/repos/meumobi/sitebuilder/statuses/{sha}","languages_url":"https://api.github.com/repos/meumobi/sitebuilder/languages","stargazers_url":"https://api.github.com/repos/meumobi/sitebuilder/stargazers","contributors_url":"https://api.github.com/repos/meumobi/sitebuilder/contributors","subscribers_url":"https://api.github.com/repos/meumobi/sitebuilder/subscribers","subscription_url":"https://api.github.com/repos/meumobi/sitebuilder/subscription","commits_url":"https://api.github.com/repos/meumobi/sitebuilder/commits{/sha}","git_commits_url":"https://api.github.com/repos/meumobi/sitebuilder/git/commits{/sha}","comments_url":"https://api.github.com/repos/meumobi/sitebuilder/comments{/number}","issue_comment_url":"https://api.github.com/repos/meumobi/sitebuilder/issues/comments{/number}","contents_url":"https://api.github.com/repos/meumobi/sitebuilder/contents/{+path}","compare_url":"https://api.github.com/repos/meumobi/sitebuilder/compare/{base}...{head}","merges_url":"https://api.github.com/repos/meumobi/sitebuilder/merges","archive_url":"https://api.github.com/repos/meumobi/sitebuilder/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/meumobi/sitebuilder/downloads","issues_url":"https://api.github.com/repos/meumobi/sitebuilder/issues{/number}","pulls_url":"https://api.github.com/repos/meumobi/sitebuilder/pulls{/number}","milestones_url":"https://api.github.com/repos/meumobi/sitebuilder/milestones{/number}","notifications_url":"https://api.github.com/repos/meumobi/sitebuilder/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/meumobi/sitebuilder/labels{/name}","releases_url":"https://api.github.com/repos/meumobi/sitebuilder/releases{/id}","created_at":"2014-11-08T20:21:22Z","updated_at":"2015-05-08T19:11:50Z","pushed_at":"2015-07-02T20:06:20Z","git_url":"git://github.com/meumobi/sitebuilder.git","ssh_url":"git@github.com:meumobi/sitebuilder.git","clone_url":"https://github.com/meumobi/sitebuilder.git","svn_url":"https://github.com/meumobi/sitebuilder","homepage":null,"size":17736,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":42,"forks":0,"open_issues":42,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/meumobi/sitebuilder/pulls/124"},"html":{"href":"https://github.com/meumobi/sitebuilder/pull/124"},"issue":{"href":"https://api.github.com/repos/meumobi/sitebuilder/issues/124"},"comments":{"href":"https://api.github.com/repos/meumobi/sitebuilder/issues/124/comments"},"review_comments":{"href":"https://api.github.com/repos/meumobi/sitebuilder/pulls/124/comments"},"review_comment":{"href":"https://api.github.com/repos/meumobi/sitebuilder/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/meumobi/sitebuilder/pulls/124/commits"},"statuses":{"href":"https://api.github.com/repos/meumobi/sitebuilder/statuses/a1f97a7106024f38fe994597f3f7d81bbd4ed3fe"}}}}