summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2016-04-09 18:51:08 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2016-04-09 18:51:08 +0200
commit4fefbdb4f0ac181d0a59d406e70b86bf785ebde5 (patch)
tree1e3ed03a487dfec19e55c5662b8c0d8ee109c8f7
parent2d17054d766746456faf769c920c8674b5afc4e5 (diff)
try to run migration for mysql and postgres
-rw-r--r--appinfo/preupdate.php17
-rw-r--r--tests/unit/upgrade/UpgradeTest.php11
-rw-r--r--upgrade/upgrade.php24
3 files changed, 50 insertions, 2 deletions
diff --git a/appinfo/preupdate.php b/appinfo/preupdate.php
new file mode 100644
index 000000000..f356ae0ce
--- /dev/null
+++ b/appinfo/preupdate.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * ownCloud - News
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Bernhard Posselt 2015
+ */
+
+namespace OCA\News\AppInfo;
+
+use OCA\News\Upgrade\Upgrade;
+
+$app = new Application();
+$app->getContainer()->query(Upgrade::class)->preUpgrade();
diff --git a/tests/unit/upgrade/UpgradeTest.php b/tests/unit/upgrade/UpgradeTest.php
index 936c329ca..d33cf9aff 100644
--- a/tests/unit/upgrade/UpgradeTest.php
+++ b/tests/unit/upgrade/UpgradeTest.php
@@ -22,18 +22,27 @@ class UpgradeTest extends \PHPUnit_Framework_TestCase {
/** @var IConfig */
private $config;
+ /** @var IDBConnection */
+ private $db;
+
public function setUp() {
$this->config = $this->getMockBuilder(
'\OCP\IConfig')
->disableOriginalConstructor()
->getMock();
+ $this->db = $this->getMockBuilder(
+ '\OCP\IDBConnection')
+ ->disableOriginalConstructor()
+ ->getMock();
+
$this->service = $this->getMockBuilder(
'\OCA\News\Service\ItemService')
->disableOriginalConstructor()
->getMock();
- $this->upgrade = new Upgrade($this->config, $this->service, 'news');
+ $this->upgrade = new Upgrade($this->config, $this->service,
+ $this->db, 'news');
}
public function testUpgrade() {
diff --git a/upgrade/upgrade.php b/upgrade/upgrade.php
index 45fcadfad..c6350aa60 100644
--- a/upgrade/upgrade.php
+++ b/upgrade/upgrade.php
@@ -13,6 +13,7 @@ namespace OCA\News\Upgrade;
use OCP\IConfig;
use OCA\News\Service\ItemService;
+use OCP\IDBConnection;
class Upgrade {
@@ -23,6 +24,10 @@ class Upgrade {
private $itemService;
private $appName;
+ /**
+ * @var IDBConnection
+ */
+ private $db;
/**
* Upgrade constructor.
@@ -30,10 +35,11 @@ class Upgrade {
* @param $appName
*/
public function __construct(IConfig $config, ItemService $itemService,
- $appName) {
+ IDBConnection $db, $appName) {
$this->config = $config;
$this->appName = $appName;
$this->itemService = $itemService;
+ $this->db = $db;
}
public function upgrade() {
@@ -46,4 +52,20 @@ class Upgrade {
}
}
+ public function preUpgrade() {
+ $previousVersion = $this->config->getAppValue(
+ $this->appName, 'installed_version'
+ );
+
+ $dbType = $this->config->getSystemValue('dbtype');
+ if (version_compare($previousVersion, '8.2.2', '<') &&
+ $dbType !== 'sqlite3'
+ ) {
+ $sql = 'ALTER TABLE `*PREFIX*news_feeds` DROP COLUMN
+ `last_modified`';
+ $query = $this->db->prepare($sql);
+ $query->execute();
+ }
+ }
+
}