{"action":"created","comment":{"url":"https://api.github.com/repos/bedita/bedita/pulls/comments/83227653","pull_request_review_id":4083907,"id":83227653,"diff_hunk":"@@ -182,19 +235,135 @@ protected function checkDir($dirPath, $label)\n     }\n \n     /**\n+     * Check if database connection is working\n+     *\n+     * @return bool True on success, false on error\n+     */\n+    protected function checkDbConnection()\n+    {\n+        $res = Database::connectionTest();\n+        if (!$res['success']) {\n+            $this->warn('Unable to connect');\n+            $this->err('Error message: ' . $res['error']);\n+            if ($this->configModified) {\n+                $this->warn('==> Please check your database configuration in config/app.php file');\n+                $this->warn(\"==> See 'DataSources' => 'default' array\");\n+            }\n+\n+            return false;\n+        }\n+\n+        return true;\n+    }\n+\n+    /**\n+     * Check database connection parameters\n+     * On a fresh install placeholders should be found, if placeholders are not found\n+     * a manual edit is required\n+     *\n+     * @return bool True on success, false otherwise\n+     */\n+    protected function databaseConnection()\n+    {\n+        $this->configModified = false;\n+        $dbParams = Database::basicInfo();\n+        $fields = ['host', 'database', 'username', 'password'];\n+        foreach ($fields as $name) {\n+            $expected = '__BE4_DB_' . strtoupper($name) . '__';\n+            if (empty($dbParams[$name]) || $dbParams[$name] !== $expected) {\n+                $this->configModified = true;\n+            }\n+        }\n+\n+        if ($this->configModified) {\n+            $this->warn('Configuration file has been modified!');\n+\n+            return $this->checkDbConnection();\n+        }\n+\n+        $this->info('A working database connection is needed in order to continue');\n+        $this->info('Parameter needed are: host, database, username, password');\n+        $res = $this->in('Proceed with setup?', ['y', 'n'], 'n');\n+        if ($res != 'y') {\n+            $this->info('Database setup stopped');\n+\n+            return false;\n+        }\n+\n+        $this->dbConnectionUserInput();\n+        $dbParams = array_merge($dbParams, $this->userInputData);\n+        $dbParams['className'] = 'Cake\\Database\\Connection';\n+        ConnectionManager::config(self::TEMP_SETUP_CFG, $dbParams);\n+        ConnectionManager::alias(self::TEMP_SETUP_CFG, 'default');\n+\n+        return $this->checkDbConnection();\n+    }\n+\n+    /**\n+     * Save database connection data in config/app.php file\n+     *\n+     * @return bool True on success, false otherwise\n+     */\n+    protected function saveConnectionData()\n+    {\n+        if (empty($this->configPath)) {\n+            $this->configPath = CONFIG . 'app.php';\n+        }\n+        if (!is_writable($this->configPath)) {\n+            $this->warn('Unable to update configuration file');\n+            $this->warn('==> Please check write permission on config/app.php file');\n+\n+            return false;\n+        }\n+\n+        $content = file_get_contents($this->configPath);\n+        $fields = ['host', 'database', 'username', 'password'];\n+        foreach ($fields as $name) {\n+            $placeHolder = '__BE4_DB_' . strtoupper($name) . '__';\n+            $content = str_replace($placeHolder, $this->userInputData[$name], $content);\n+        }\n+\n+        // TODO: better php check for $content?\n+        $eval = eval(str_replace('<?php', '', $content));","path":"plugins/BEdita/Core/src/Shell/BeditaShell.php","position":233,"original_position":233,"commit_id":"058fdc0f704927a019f848a0077d9248d4f84ef1","original_commit_id":"058fdc0f704927a019f848a0077d9248d4f84ef1","user":{"login":"batopa","id":1306319,"avatar_url":"https://avatars.githubusercontent.com/u/1306319?v=3","gravatar_id":"","url":"https://api.github.com/users/batopa","html_url":"https://github.com/batopa","followers_url":"https://api.github.com/users/batopa/followers","following_url":"https://api.github.com/users/batopa/following{/other_user}","gists_url":"https://api.github.com/users/batopa/gists{/gist_id}","starred_url":"https://api.github.com/users/batopa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/batopa/subscriptions","organizations_url":"https://api.github.com/users/batopa/orgs","repos_url":"https://api.github.com/users/batopa/repos","events_url":"https://api.github.com/users/batopa/events{/privacy}","received_events_url":"https://api.github.com/users/batopa/received_events","type":"User","site_admin":false},"body":"Maybe we could mitigate the risks doing some validation on data input and using `File\\Filesystem\\File` operating on files, for example using `http://api.cakephp.org/3.3/class-Cake.Filesystem.File.html#_replaceText.","created_at":"2016-10-13T14:23:40Z","updated_at":"2016-10-13T14:23:40Z","html_url":"https://github.com/bedita/bedita/pull/1005#discussion_r83227653","pull_request_url":"https://api.github.com/repos/bedita/bedita/pulls/1005","_links":{"self":{"href":"https://api.github.com/repos/bedita/bedita/pulls/comments/83227653"},"html":{"href":"https://github.com/bedita/bedita/pull/1005#discussion_r83227653"},"pull_request":{"href":"https://api.github.com/repos/bedita/bedita/pulls/1005"}}},"pull_request":{"url":"https://api.github.com/repos/bedita/bedita/pulls/1005","id":87865350,"html_url":"https://github.com/bedita/bedita/pull/1005","diff_url":"https://github.com/bedita/bedita/pull/1005.diff","patch_url":"https://github.com/bedita/bedita/pull/1005.patch","issue_url":"https://api.github.com/repos/bedita/bedita/issues/1005","number":1005,"state":"open","locked":false,"title":"Issue/v4/998 setup db connection","user":{"login":"stefanorosanelli","id":2122280,"avatar_url":"https://avatars.githubusercontent.com/u/2122280?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanorosanelli","html_url":"https://github.com/stefanorosanelli","followers_url":"https://api.github.com/users/stefanorosanelli/followers","following_url":"https://api.github.com/users/stefanorosanelli/following{/other_user}","gists_url":"https://api.github.com/users/stefanorosanelli/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanorosanelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanorosanelli/subscriptions","organizations_url":"https://api.github.com/users/stefanorosanelli/orgs","repos_url":"https://api.github.com/users/stefanorosanelli/repos","events_url":"https://api.github.com/users/stefanorosanelli/events{/privacy}","received_events_url":"https://api.github.com/users/stefanorosanelli/received_events","type":"User","site_admin":false},"body":"Port handling is missing\r\nAlso password should (probably) not be visible - i'll do it in a separate issue","created_at":"2016-10-04T10:05:13Z","updated_at":"2016-10-13T14:23:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c426e24f79879c3c3469507bf14adaf5ebc13093","assignee":{"login":"batopa","id":1306319,"avatar_url":"https://avatars.githubusercontent.com/u/1306319?v=3","gravatar_id":"","url":"https://api.github.com/users/batopa","html_url":"https://github.com/batopa","followers_url":"https://api.github.com/users/batopa/followers","following_url":"https://api.github.com/users/batopa/following{/other_user}","gists_url":"https://api.github.com/users/batopa/gists{/gist_id}","starred_url":"https://api.github.com/users/batopa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/batopa/subscriptions","organizations_url":"https://api.github.com/users/batopa/orgs","repos_url":"https://api.github.com/users/batopa/repos","events_url":"https://api.github.com/users/batopa/events{/privacy}","received_events_url":"https://api.github.com/users/batopa/received_events","type":"User","site_admin":false},"assignees":[{"login":"batopa","id":1306319,"avatar_url":"https://avatars.githubusercontent.com/u/1306319?v=3","gravatar_id":"","url":"https://api.github.com/users/batopa","html_url":"https://github.com/batopa","followers_url":"https://api.github.com/users/batopa/followers","following_url":"https://api.github.com/users/batopa/following{/other_user}","gists_url":"https://api.github.com/users/batopa/gists{/gist_id}","starred_url":"https://api.github.com/users/batopa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/batopa/subscriptions","organizations_url":"https://api.github.com/users/batopa/orgs","repos_url":"https://api.github.com/users/batopa/repos","events_url":"https://api.github.com/users/batopa/events{/privacy}","received_events_url":"https://api.github.com/users/batopa/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/bedita/bedita/milestones/9","html_url":"https://github.com/bedita/bedita/milestones/4.0.0-alpha","labels_url":"https://api.github.com/repos/bedita/bedita/milestones/9/labels","id":461460,"number":9,"title":"4.0.0-alpha","description":"\r\n","creator":{"login":"stefanorosanelli","id":2122280,"avatar_url":"https://avatars.githubusercontent.com/u/2122280?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanorosanelli","html_url":"https://github.com/stefanorosanelli","followers_url":"https://api.github.com/users/stefanorosanelli/followers","following_url":"https://api.github.com/users/stefanorosanelli/following{/other_user}","gists_url":"https://api.github.com/users/stefanorosanelli/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanorosanelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanorosanelli/subscriptions","organizations_url":"https://api.github.com/users/stefanorosanelli/orgs","repos_url":"https://api.github.com/users/stefanorosanelli/repos","events_url":"https://api.github.com/users/stefanorosanelli/events{/privacy}","received_events_url":"https://api.github.com/users/stefanorosanelli/received_events","type":"User","site_admin":false},"open_issues":25,"closed_issues":131,"state":"open","created_at":"2013-10-22T14:17:42Z","updated_at":"2016-10-11T10:47:42Z","due_on":"2016-10-31T00:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/bedita/bedita/pulls/1005/commits","review_comments_url":"https://api.github.com/repos/bedita/bedita/pulls/1005/comments","review_comment_url":"https://api.github.com/repos/bedita/bedita/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bedita/bedita/issues/1005/comments","statuses_url":"https://api.github.com/repos/bedita/bedita/statuses/058fdc0f704927a019f848a0077d9248d4f84ef1","head":{"label":"bedita:issue/v4/998-setup-db-connection","ref":"issue/v4/998-setup-db-connection","sha":"058fdc0f704927a019f848a0077d9248d4f84ef1","user":{"login":"bedita","id":2121737,"avatar_url":"https://avatars.githubusercontent.com/u/2121737?v=3","gravatar_id":"","url":"https://api.github.com/users/bedita","html_url":"https://github.com/bedita","followers_url":"https://api.github.com/users/bedita/followers","following_url":"https://api.github.com/users/bedita/following{/other_user}","gists_url":"https://api.github.com/users/bedita/gists{/gist_id}","starred_url":"https://api.github.com/users/bedita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bedita/subscriptions","organizations_url":"https://api.github.com/users/bedita/orgs","repos_url":"https://api.github.com/users/bedita/repos","events_url":"https://api.github.com/users/bedita/events{/privacy}","received_events_url":"https://api.github.com/users/bedita/received_events","type":"Organization","site_admin":false},"repo":{"id":5352389,"name":"bedita","full_name":"bedita/bedita","owner":{"login":"bedita","id":2121737,"avatar_url":"https://avatars.githubusercontent.com/u/2121737?v=3","gravatar_id":"","url":"https://api.github.com/users/bedita","html_url":"https://github.com/bedita","followers_url":"https://api.github.com/users/bedita/followers","following_url":"https://api.github.com/users/bedita/following{/other_user}","gists_url":"https://api.github.com/users/bedita/gists{/gist_id}","starred_url":"https://api.github.com/users/bedita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bedita/subscriptions","organizations_url":"https://api.github.com/users/bedita/orgs","repos_url":"https://api.github.com/users/bedita/repos","events_url":"https://api.github.com/users/bedita/events{/privacy}","received_events_url":"https://api.github.com/users/bedita/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bedita/bedita","description":"BEdita the Semantic Content Management Framework","fork":false,"url":"https://api.github.com/repos/bedita/bedita","forks_url":"https://api.github.com/repos/bedita/bedita/forks","keys_url":"https://api.github.com/repos/bedita/bedita/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bedita/bedita/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bedita/bedita/teams","hooks_url":"https://api.github.com/repos/bedita/bedita/hooks","issue_events_url":"https://api.github.com/repos/bedita/bedita/issues/events{/number}","events_url":"https://api.github.com/repos/bedita/bedita/events","assignees_url":"https://api.github.com/repos/bedita/bedita/assignees{/user}","branches_url":"https://api.github.com/repos/bedita/bedita/branches{/branch}","tags_url":"https://api.github.com/repos/bedita/bedita/tags","blobs_url":"https://api.github.com/repos/bedita/bedita/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bedita/bedita/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bedita/bedita/git/refs{/sha}","trees_url":"https://api.github.com/repos/bedita/bedita/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bedita/bedita/statuses/{sha}","languages_url":"https://api.github.com/repos/bedita/bedita/languages","stargazers_url":"https://api.github.com/repos/bedita/bedita/stargazers","contributors_url":"https://api.github.com/repos/bedita/bedita/contributors","subscribers_url":"https://api.github.com/repos/bedita/bedita/subscribers","subscription_url":"https://api.github.com/repos/bedita/bedita/subscription","commits_url":"https://api.github.com/repos/bedita/bedita/commits{/sha}","git_commits_url":"https://api.github.com/repos/bedita/bedita/git/commits{/sha}","comments_url":"https://api.github.com/repos/bedita/bedita/comments{/number}","issue_comment_url":"https://api.github.com/repos/bedita/bedita/issues/comments{/number}","contents_url":"https://api.github.com/repos/bedita/bedita/contents/{+path}","compare_url":"https://api.github.com/repos/bedita/bedita/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bedita/bedita/merges","archive_url":"https://api.github.com/repos/bedita/bedita/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bedita/bedita/downloads","issues_url":"https://api.github.com/repos/bedita/bedita/issues{/number}","pulls_url":"https://api.github.com/repos/bedita/bedita/pulls{/number}","milestones_url":"https://api.github.com/repos/bedita/bedita/milestones{/number}","notifications_url":"https://api.github.com/repos/bedita/bedita/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bedita/bedita/labels{/name}","releases_url":"https://api.github.com/repos/bedita/bedita/releases{/id}","deployments_url":"https://api.github.com/repos/bedita/bedita/deployments","created_at":"2012-08-09T07:13:29Z","updated_at":"2016-09-28T15:11:33Z","pushed_at":"2016-10-13T13:29:49Z","git_url":"git://github.com/bedita/bedita.git","ssh_url":"git@github.com:bedita/bedita.git","clone_url":"https://github.com/bedita/bedita.git","svn_url":"https://github.com/bedita/bedita","homepage":"http://www.bedita.com","size":58611,"stargazers_count":33,"watchers_count":33,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":89,"forks":9,"open_issues":89,"watchers":33,"default_branch":"3-corylus"}},"base":{"label":"bedita:4-develop","ref":"4-develop","sha":"2c34f5d1536b2f3a11fdddcfa910dcb8b63de3f4","user":{"login":"bedita","id":2121737,"avatar_url":"https://avatars.githubusercontent.com/u/2121737?v=3","gravatar_id":"","url":"https://api.github.com/users/bedita","html_url":"https://github.com/bedita","followers_url":"https://api.github.com/users/bedita/followers","following_url":"https://api.github.com/users/bedita/following{/other_user}","gists_url":"https://api.github.com/users/bedita/gists{/gist_id}","starred_url":"https://api.github.com/users/bedita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bedita/subscriptions","organizations_url":"https://api.github.com/users/bedita/orgs","repos_url":"https://api.github.com/users/bedita/repos","events_url":"https://api.github.com/users/bedita/events{/privacy}","received_events_url":"https://api.github.com/users/bedita/received_events","type":"Organization","site_admin":false},"repo":{"id":5352389,"name":"bedita","full_name":"bedita/bedita","owner":{"login":"bedita","id":2121737,"avatar_url":"https://avatars.githubusercontent.com/u/2121737?v=3","gravatar_id":"","url":"https://api.github.com/users/bedita","html_url":"https://github.com/bedita","followers_url":"https://api.github.com/users/bedita/followers","following_url":"https://api.github.com/users/bedita/following{/other_user}","gists_url":"https://api.github.com/users/bedita/gists{/gist_id}","starred_url":"https://api.github.com/users/bedita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bedita/subscriptions","organizations_url":"https://api.github.com/users/bedita/orgs","repos_url":"https://api.github.com/users/bedita/repos","events_url":"https://api.github.com/users/bedita/events{/privacy}","received_events_url":"https://api.github.com/users/bedita/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bedita/bedita","description":"BEdita the Semantic Content Management Framework","fork":false,"url":"https://api.github.com/repos/bedita/bedita","forks_url":"https://api.github.com/repos/bedita/bedita/forks","keys_url":"https://api.github.com/repos/bedita/bedita/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bedita/bedita/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bedita/bedita/teams","hooks_url":"https://api.github.com/repos/bedita/bedita/hooks","issue_events_url":"https://api.github.com/repos/bedita/bedita/issues/events{/number}","events_url":"https://api.github.com/repos/bedita/bedita/events","assignees_url":"https://api.github.com/repos/bedita/bedita/assignees{/user}","branches_url":"https://api.github.com/repos/bedita/bedita/branches{/branch}","tags_url":"https://api.github.com/repos/bedita/bedita/tags","blobs_url":"https://api.github.com/repos/bedita/bedita/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bedita/bedita/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bedita/bedita/git/refs{/sha}","trees_url":"https://api.github.com/repos/bedita/bedita/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bedita/bedita/statuses/{sha}","languages_url":"https://api.github.com/repos/bedita/bedita/languages","stargazers_url":"https://api.github.com/repos/bedita/bedita/stargazers","contributors_url":"https://api.github.com/repos/bedita/bedita/contributors","subscribers_url":"https://api.github.com/repos/bedita/bedita/subscribers","subscription_url":"https://api.github.com/repos/bedita/bedita/subscription","commits_url":"https://api.github.com/repos/bedita/bedita/commits{/sha}","git_commits_url":"https://api.github.com/repos/bedita/bedita/git/commits{/sha}","comments_url":"https://api.github.com/repos/bedita/bedita/comments{/number}","issue_comment_url":"https://api.github.com/repos/bedita/bedita/issues/comments{/number}","contents_url":"https://api.github.com/repos/bedita/bedita/contents/{+path}","compare_url":"https://api.github.com/repos/bedita/bedita/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bedita/bedita/merges","archive_url":"https://api.github.com/repos/bedita/bedita/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bedita/bedita/downloads","issues_url":"https://api.github.com/repos/bedita/bedita/issues{/number}","pulls_url":"https://api.github.com/repos/bedita/bedita/pulls{/number}","milestones_url":"https://api.github.com/repos/bedita/bedita/milestones{/number}","notifications_url":"https://api.github.com/repos/bedita/bedita/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bedita/bedita/labels{/name}","releases_url":"https://api.github.com/repos/bedita/bedita/releases{/id}","deployments_url":"https://api.github.com/repos/bedita/bedita/deployments","created_at":"2012-08-09T07:13:29Z","updated_at":"2016-09-28T15:11:33Z","pushed_at":"2016-10-13T13:29:49Z","git_url":"git://github.com/bedita/bedita.git","ssh_url":"git@github.com:bedita/bedita.git","clone_url":"https://github.com/bedita/bedita.git","svn_url":"https://github.com/bedita/bedita","homepage":"http://www.bedita.com","size":58611,"stargazers_count":33,"watchers_count":33,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":89,"forks":9,"open_issues":89,"watchers":33,"default_branch":"3-corylus"}},"_links":{"self":{"href":"https://api.github.com/repos/bedita/bedita/pulls/1005"},"html":{"href":"https://github.com/bedita/bedita/pull/1005"},"issue":{"href":"https://api.github.com/repos/bedita/bedita/issues/1005"},"comments":{"href":"https://api.github.com/repos/bedita/bedita/issues/1005/comments"},"review_comments":{"href":"https://api.github.com/repos/bedita/bedita/pulls/1005/comments"},"review_comment":{"href":"https://api.github.com/repos/bedita/bedita/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bedita/bedita/pulls/1005/commits"},"statuses":{"href":"https://api.github.com/repos/bedita/bedita/statuses/058fdc0f704927a019f848a0077d9248d4f84ef1"}}}}
{"actor":{"display_login":"batopa"}}