GitHub PullRequestReviewCommentEvent at 2014-11-13 10:21:18
Repository: thelia
Actor: lunika
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/thelia/thelia/pulls/comments/20282106","id":20282106,"diff_hunk":"@@ -51,50 +115,221 @@ protected function isLatestVersion($version)\n \n     public function process()\n     {\n-        $logger = Tlog::getInstance();\n-        $logger->setLevel(Tlog::DEBUG);\n+        $this->updatedVersions = array();\n \n-        $updatedVersions = array();\n+        $currentVersion = $this->getCurrentVersion();\n+        $this->log('debug', \"start update process\");\n \n-        $currentVersion = ConfigQuery::read('thelia_version');\n-        $logger->debug(\"start update process\");\n         if (true === $this->isLatestVersion($currentVersion)) {\n-            $logger->debug(\"You already have the latest version. No update available\");\n+            $this->log('debug', \"You already have the latest version. No update available\");\n             throw new UpToDateException('You already have the latest version. No update available');\n         }\n \n         $index = array_search($currentVersion, self::$version);\n-        $con = Propel::getServiceContainer()->getWriteConnection(ProductTableMap::DATABASE_NAME);\n-        $con->beginTransaction();\n-        $logger->debug(\"begin transaction\");\n-        $database = new Database($con->getWrappedConnection());\n+\n+        $this->connection->exec(\"SET autocommit = 0\");\n+        $this->connection->beginTransaction();\n+\n+        $database = new Database($this->connection);\n+        $version = null;\n+\n         try {\n             $size = count(self::$version);\n+\n             for ($i = ++$index; $i < $size; $i++) {\n-                $this->updateToVersion(self::$version[$i], $database, $logger);\n-                $updatedVersions[] = self::$version[$i];\n+                $version = self::$version[$i];\n+                $this->updateToVersion($version, $database);\n+                $this->updatedVersions[] = $version;\n+            }\n+\n+            $this->connection->commit();\n+            $this->log('debug', 'update successfully');\n+        } catch (\\Exception $e) {\n+            $this->connection->rollBack();\n+\n+            $this->log('error', sprintf('error during update process with message : %s', $e->getMessage()));\n+\n+            $ex = new UpdateException($e->getMessage(), $e->getCode(), $e->getPrevious());\n+            $ex->setVersion($version);\n+            throw $ex;\n+        }\n+        $this->log('debug', 'end of update processing');\n+\n+        return $this->updatedVersions;\n+    }\n+\n+    public function backupDb()\n+    {\n+        $database = new Database($this->connection);\n+\n+        $this->backupFile = THELIA_ROOT . $this->backupDir . 'update.sql';\n+\n+        $fs = new Filesystem();\n+\n+        try {\n+            $this->log('debug', sprintf('Backup database to file : %s', $this->backupFile));\n+\n+            // test if backup dir exists\n+            if (!$fs->exists(THELIA_ROOT . $this->backupDir)) {\n+                $fs->mkdir(THELIA_ROOT . $this->backupDir);\n+            }\n+\n+            // test if backup file already exists\n+            if ($fs->exists($this->backupFile)) {\n+                // remove file\n+                $fs->remove($this->backupFile);\n+            }\n+\n+            $database->backupDb($this->backupFile);\n+        } catch (\\Exception $ex) {\n+            $this->log('error', sprintf('error during backup process with message : %s', $ex->getMessage()));\n+            return false;\n+        }\n+\n+        return true;\n+    }\n+\n+    public function restoreDb()\n+    {\n+        $database = new Database($this->connection);\n+\n+        try {\n+            $this->log('debug', sprintf('Restore database with file : %s', $this->backupFile));\n+\n+            if (!file_exists($this->backupFile)) {\n+                return false;\n             }\n-            $con->commit();\n-            $logger->debug('update successfully');\n-        } catch (PropelException $e) {\n-            $con->rollBack();\n-            $logger->error(sprintf('error during update process with message : %s', $e->getMessage()));\n-            throw $e;\n+\n+            $database->restoreDb($this->backupFile);\n+        } catch (\\Exception $ex) {\n+            $this->log('error', sprintf('error during restore process with message : %s', $ex->getMessage()));\n+            print $ex->getMessage();\n+            return false;\n         }\n \n-        $logger->debug('end of update processing');\n+        return true;\n+    }\n+\n+    /**\n+     * @return null|string\n+     */\n+    public function getBackupFile()\n+    {\n+        return $this->backupFile;\n+    }\n+\n+    public function getLogs()\n+    {\n+        return $this->logs;\n+    }\n \n-        return $updatedVersions;\n+    protected function log($level, $message)\n+    {\n+        if ($this->usePropel) {\n+            switch ($level) {\n+                case 'debug':\n+                    $this->logger->debug($message);\n+                    break;\n+                case 'info':\n+                    $this->logger->info($message);\n+                    break;\n+                case 'notice':\n+                    $this->logger->notice($message);\n+                    break;\n+                case 'warning':\n+                    $this->logger->warning($message);\n+                    break;\n+                case 'error':\n+                    $this->logger->error($message);\n+                    break;\n+                case 'critical':\n+                    $this->logger->critical($message);\n+                    break;\n+            }\n+        } else {\n+            $this->logs[] = [$level, $message];\n+        }\n     }\n \n-    protected function updateToVersion($version, Database $database, Tlog $logger)\n+    protected function updateToVersion($version, Database $database)\n     {\n-        if (file_exists(THELIA_ROOT . '/setup/update/'.$version.'.sql')) {\n-            $logger->debug(sprintf('inserting file %s', $version.'$sql'));\n-            $database->insertSql(null, array(THELIA_ROOT . '/setup/update/'.$version.'.sql'));\n-            $logger->debug(sprintf('end inserting file %s', $version.'$sql'));\n+        // sql update\n+        if (file_exists(THELIA_ROOT . 'setup/update/' . $version . '.sql')) {\n+            $this->log('debug', sprintf('inserting file %s', $version . '.sql'));\n+            $database->insertSql(null, array(THELIA_ROOT . 'setup/update/' . $version . '.sql'));\n+            $this->log('debug', sprintf('end inserting file %s', $version . '.sql'));\n         }\n \n-        ConfigQuery::write('thelia_version', $version);\n+        // php update\n+        if (file_exists(THELIA_ROOT . 'setup/update/' . $version . '.php')) {\n+            $this->log('debug', sprintf('executing file %s', $version . '.php'));\n+            include_once THELIA_ROOT . 'setup/update/'.$version . '.php';\n+            $this->log('debug', sprintf('end executing file %s', $version . '.php'));\n+        }\n+\n+        $this->setCurrentVersion($version);\n+    }\n+\n+    public function getCurrentVersion()\n+    {\n+        $currentVersion = null;\n+\n+        if (null !== $this->connection) {\n+            try {\n+                $stmt = $this->connection->prepare('SELECT * from config where name = ? LIMIT 1');","path":"core/lib/Thelia/Install/Update.php","position":282,"original_position":282,"commit_id":"e5d9e2b69e3318dfccf3819bd918495b7f5d243a","original_commit_id":"e5d9e2b69e3318dfccf3819bd918495b7f5d243a","user":{"login":"lunika","id":767834,"avatar_url":"https://avatars.githubusercontent.com/u/767834?v=3","gravatar_id":"","url":"https://api.github.com/users/lunika","html_url":"https://github.com/lunika","followers_url":"https://api.github.com/users/lunika/followers","following_url":"https://api.github.com/users/lunika/following{/other_user}","gists_url":"https://api.github.com/users/lunika/gists{/gist_id}","starred_url":"https://api.github.com/users/lunika/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lunika/subscriptions","organizations_url":"https://api.github.com/users/lunika/orgs","repos_url":"https://api.github.com/users/lunika/repos","events_url":"https://api.github.com/users/lunika/events{/privacy}","received_events_url":"https://api.github.com/users/lunika/received_events","type":"User","site_admin":false},"body":"select only the ```value``` column","created_at":"2014-11-13T10:21:18Z","updated_at":"2014-11-13T10:21:18Z","html_url":"https://github.com/thelia/thelia/pull/847#discussion_r20282106","pull_request_url":"https://api.github.com/repos/thelia/thelia/pulls/847","_links":{"self":{"href":"https://api.github.com/repos/thelia/thelia/pulls/comments/20282106"},"html":{"href":"https://github.com/thelia/thelia/pull/847#discussion_r20282106"},"pull_request":{"href":"https://api.github.com/repos/thelia/thelia/pulls/847"}}},"pull_request":{"url":"https://api.github.com/repos/thelia/thelia/pulls/847","id":23826891,"html_url":"https://github.com/thelia/thelia/pull/847","diff_url":"https://github.com/thelia/thelia/pull/847.diff","patch_url":"https://github.com/thelia/thelia/pull/847.patch","issue_url":"https://api.github.com/repos/thelia/thelia/issues/847","number":847,"state":"open","locked":false,"title":"Added a php script to update Thelia and replace the Thelia update command","user":{"login":"bibich","id":1215555,"avatar_url":"https://avatars.githubusercontent.com/u/1215555?v=3","gravatar_id":"","url":"https://api.github.com/users/bibich","html_url":"https://github.com/bibich","followers_url":"https://api.github.com/users/bibich/followers","following_url":"https://api.github.com/users/bibich/following{/other_user}","gists_url":"https://api.github.com/users/bibich/gists{/gist_id}","starred_url":"https://api.github.com/users/bibich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bibich/subscriptions","organizations_url":"https://api.github.com/users/bibich/orgs","repos_url":"https://api.github.com/users/bibich/repos","events_url":"https://api.github.com/users/bibich/events{/privacy}","received_events_url":"https://api.github.com/users/bibich/received_events","type":"User","site_admin":false},"body":"The goal of this script is to avoid issues encountered with the Thelia update command due to incompatibilities between php files and database version.\r\n\r\nGo to the root directory of your Thelia installation and run :\r\n\r\n```bash\r\nphp setup/update.sh\r\n```\r\n","created_at":"2014-11-04T11:54:03Z","updated_at":"2014-11-13T10:21:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"789eed0588af7bd81e81621cd4a1e4aedb6cf864","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/thelia/thelia/pulls/847/commits","review_comments_url":"https://api.github.com/repos/thelia/thelia/pulls/847/comments","review_comment_url":"https://api.github.com/repos/thelia/thelia/pulls/comments/{number}","comments_url":"https://api.github.com/repos/thelia/thelia/issues/847/comments","statuses_url":"https://api.github.com/repos/thelia/thelia/statuses/e5d9e2b69e3318dfccf3819bd918495b7f5d243a","head":{"label":"bibich:update","ref":"update","sha":"e5d9e2b69e3318dfccf3819bd918495b7f5d243a","user":{"login":"bibich","id":1215555,"avatar_url":"https://avatars.githubusercontent.com/u/1215555?v=3","gravatar_id":"","url":"https://api.github.com/users/bibich","html_url":"https://github.com/bibich","followers_url":"https://api.github.com/users/bibich/followers","following_url":"https://api.github.com/users/bibich/following{/other_user}","gists_url":"https://api.github.com/users/bibich/gists{/gist_id}","starred_url":"https://api.github.com/users/bibich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bibich/subscriptions","organizations_url":"https://api.github.com/users/bibich/orgs","repos_url":"https://api.github.com/users/bibich/repos","events_url":"https://api.github.com/users/bibich/events{/privacy}","received_events_url":"https://api.github.com/users/bibich/received_events","type":"User","site_admin":false},"repo":{"id":19065406,"name":"thelia","full_name":"bibich/thelia","owner":{"login":"bibich","id":1215555,"avatar_url":"https://avatars.githubusercontent.com/u/1215555?v=3","gravatar_id":"","url":"https://api.github.com/users/bibich","html_url":"https://github.com/bibich","followers_url":"https://api.github.com/users/bibich/followers","following_url":"https://api.github.com/users/bibich/following{/other_user}","gists_url":"https://api.github.com/users/bibich/gists{/gist_id}","starred_url":"https://api.github.com/users/bibich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bibich/subscriptions","organizations_url":"https://api.github.com/users/bibich/orgs","repos_url":"https://api.github.com/users/bibich/repos","events_url":"https://api.github.com/users/bibich/events{/privacy}","received_events_url":"https://api.github.com/users/bibich/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bibich/thelia","description":"Thelia is an open source tool for creating e-business websites and managing online content. Repo containing the next major version (v2)","fork":true,"url":"https://api.github.com/repos/bibich/thelia","forks_url":"https://api.github.com/repos/bibich/thelia/forks","keys_url":"https://api.github.com/repos/bibich/thelia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bibich/thelia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bibich/thelia/teams","hooks_url":"https://api.github.com/repos/bibich/thelia/hooks","issue_events_url":"https://api.github.com/repos/bibich/thelia/issues/events{/number}","events_url":"https://api.github.com/repos/bibich/thelia/events","assignees_url":"https://api.github.com/repos/bibich/thelia/assignees{/user}","branches_url":"https://api.github.com/repos/bibich/thelia/branches{/branch}","tags_url":"https://api.github.com/repos/bibich/thelia/tags","blobs_url":"https://api.github.com/repos/bibich/thelia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bibich/thelia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bibich/thelia/git/refs{/sha}","trees_url":"https://api.github.com/repos/bibich/thelia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bibich/thelia/statuses/{sha}","languages_url":"https://api.github.com/repos/bibich/thelia/languages","stargazers_url":"https://api.github.com/repos/bibich/thelia/stargazers","contributors_url":"https://api.github.com/repos/bibich/thelia/contributors","subscribers_url":"https://api.github.com/repos/bibich/thelia/subscribers","subscription_url":"https://api.github.com/repos/bibich/thelia/subscription","commits_url":"https://api.github.com/repos/bibich/thelia/commits{/sha}","git_commits_url":"https://api.github.com/repos/bibich/thelia/git/commits{/sha}","comments_url":"https://api.github.com/repos/bibich/thelia/comments{/number}","issue_comment_url":"https://api.github.com/repos/bibich/thelia/issues/comments/{number}","contents_url":"https://api.github.com/repos/bibich/thelia/contents/{+path}","compare_url":"https://api.github.com/repos/bibich/thelia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bibich/thelia/merges","archive_url":"https://api.github.com/repos/bibich/thelia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bibich/thelia/downloads","issues_url":"https://api.github.com/repos/bibich/thelia/issues{/number}","pulls_url":"https://api.github.com/repos/bibich/thelia/pulls{/number}","milestones_url":"https://api.github.com/repos/bibich/thelia/milestones{/number}","notifications_url":"https://api.github.com/repos/bibich/thelia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bibich/thelia/labels{/name}","releases_url":"https://api.github.com/repos/bibich/thelia/releases{/id}","created_at":"2014-04-23T10:18:01Z","updated_at":"2014-06-28T05:28:19Z","pushed_at":"2014-11-13T09:02:37Z","git_url":"git://github.com/bibich/thelia.git","ssh_url":"git@github.com:bibich/thelia.git","clone_url":"https://github.com/bibich/thelia.git","svn_url":"https://github.com/bibich/thelia","homepage":"http://thelia.net/v2","size":77024,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"thelia:master","ref":"master","sha":"5b76c6e01c5592c91602bcfe4aaa8f91f5bf1bb2","user":{"login":"thelia","id":2196919,"avatar_url":"https://avatars.githubusercontent.com/u/2196919?v=3","gravatar_id":"","url":"https://api.github.com/users/thelia","html_url":"https://github.com/thelia","followers_url":"https://api.github.com/users/thelia/followers","following_url":"https://api.github.com/users/thelia/following{/other_user}","gists_url":"https://api.github.com/users/thelia/gists{/gist_id}","starred_url":"https://api.github.com/users/thelia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thelia/subscriptions","organizations_url":"https://api.github.com/users/thelia/orgs","repos_url":"https://api.github.com/users/thelia/repos","events_url":"https://api.github.com/users/thelia/events{/privacy}","received_events_url":"https://api.github.com/users/thelia/received_events","type":"Organization","site_admin":false},"repo":{"id":8863081,"name":"thelia","full_name":"thelia/thelia","owner":{"login":"thelia","id":2196919,"avatar_url":"https://avatars.githubusercontent.com/u/2196919?v=3","gravatar_id":"","url":"https://api.github.com/users/thelia","html_url":"https://github.com/thelia","followers_url":"https://api.github.com/users/thelia/followers","following_url":"https://api.github.com/users/thelia/following{/other_user}","gists_url":"https://api.github.com/users/thelia/gists{/gist_id}","starred_url":"https://api.github.com/users/thelia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thelia/subscriptions","organizations_url":"https://api.github.com/users/thelia/orgs","repos_url":"https://api.github.com/users/thelia/repos","events_url":"https://api.github.com/users/thelia/events{/privacy}","received_events_url":"https://api.github.com/users/thelia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thelia/thelia","description":"Thelia is an open source tool for creating e-business websites and managing online content. Repo containing the new major version (v2)","fork":false,"url":"https://api.github.com/repos/thelia/thelia","forks_url":"https://api.github.com/repos/thelia/thelia/forks","keys_url":"https://api.github.com/repos/thelia/thelia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thelia/thelia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thelia/thelia/teams","hooks_url":"https://api.github.com/repos/thelia/thelia/hooks","issue_events_url":"https://api.github.com/repos/thelia/thelia/issues/events{/number}","events_url":"https://api.github.com/repos/thelia/thelia/events","assignees_url":"https://api.github.com/repos/thelia/thelia/assignees{/user}","branches_url":"https://api.github.com/repos/thelia/thelia/branches{/branch}","tags_url":"https://api.github.com/repos/thelia/thelia/tags","blobs_url":"https://api.github.com/repos/thelia/thelia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thelia/thelia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thelia/thelia/git/refs{/sha}","trees_url":"https://api.github.com/repos/thelia/thelia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thelia/thelia/statuses/{sha}","languages_url":"https://api.github.com/repos/thelia/thelia/languages","stargazers_url":"https://api.github.com/repos/thelia/thelia/stargazers","contributors_url":"https://api.github.com/repos/thelia/thelia/contributors","subscribers_url":"https://api.github.com/repos/thelia/thelia/subscribers","subscription_url":"https://api.github.com/repos/thelia/thelia/subscription","commits_url":"https://api.github.com/repos/thelia/thelia/commits{/sha}","git_commits_url":"https://api.github.com/repos/thelia/thelia/git/commits{/sha}","comments_url":"https://api.github.com/repos/thelia/thelia/comments{/number}","issue_comment_url":"https://api.github.com/repos/thelia/thelia/issues/comments/{number}","contents_url":"https://api.github.com/repos/thelia/thelia/contents/{+path}","compare_url":"https://api.github.com/repos/thelia/thelia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thelia/thelia/merges","archive_url":"https://api.github.com/repos/thelia/thelia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thelia/thelia/downloads","issues_url":"https://api.github.com/repos/thelia/thelia/issues{/number}","pulls_url":"https://api.github.com/repos/thelia/thelia/pulls{/number}","milestones_url":"https://api.github.com/repos/thelia/thelia/milestones{/number}","notifications_url":"https://api.github.com/repos/thelia/thelia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thelia/thelia/labels{/name}","releases_url":"https://api.github.com/repos/thelia/thelia/releases{/id}","created_at":"2013-03-18T20:10:36Z","updated_at":"2014-11-12T16:35:32Z","pushed_at":"2014-11-13T09:51:24Z","git_url":"git://github.com/thelia/thelia.git","ssh_url":"git@github.com:thelia/thelia.git","clone_url":"https://github.com/thelia/thelia.git","svn_url":"https://github.com/thelia/thelia","homepage":"http://thelia.net","size":96362,"stargazers_count":311,"watchers_count":311,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":90,"mirror_url":null,"open_issues_count":69,"forks":90,"open_issues":69,"watchers":311,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thelia/thelia/pulls/847"},"html":{"href":"https://github.com/thelia/thelia/pull/847"},"issue":{"href":"https://api.github.com/repos/thelia/thelia/issues/847"},"comments":{"href":"https://api.github.com/repos/thelia/thelia/issues/847/comments"},"review_comments":{"href":"https://api.github.com/repos/thelia/thelia/pulls/847/comments"},"review_comment":{"href":"https://api.github.com/repos/thelia/thelia/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/thelia/thelia/pulls/847/commits"},"statuses":{"href":"https://api.github.com/repos/thelia/thelia/statuses/e5d9e2b69e3318dfccf3819bd918495b7f5d243a"}}}}