mirror of
https://github.com/chylex/Nextcloud-News.git
synced 2025-04-09 19:15:42 +02:00
try to run migration for mysql and postgres
This commit is contained in:
parent
2d17054d76
commit
4fefbdb4f0
17
appinfo/preupdate.php
Normal file
17
appinfo/preupdate.php
Normal file
@ -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();
|
@ -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() {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user