From 4fefbdb4f0ac181d0a59d406e70b86bf785ebde5 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 9 Apr 2016 18:51:08 +0200 Subject: try to run migration for mysql and postgres --- appinfo/preupdate.php | 17 +++++++++++++++++ tests/unit/upgrade/UpgradeTest.php | 11 ++++++++++- upgrade/upgrade.php | 24 +++++++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 appinfo/preupdate.php 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 @@ + + * @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(); + } + } + } -- cgit v1.2.3