Completed
Push — master ( 2d1705...4fefbd )
by
unknown
04:00
created

Upgrade::preUpgrade()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 0
cp 0
rs 9.4285
cc 3
eloc 9
nc 2
nop 0
crap 12
1
<?php
2
/**
3
 * ownCloud - News
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Bernhard Posselt <[email protected]>
9
 * @copyright Bernhard Posselt 2015
10
 */
11
12
namespace OCA\News\Upgrade;
13
14
use OCP\IConfig;
15
use OCA\News\Service\ItemService;
16
use OCP\IDBConnection;
17
18
class Upgrade {
19
20
    /** @var IConfig */
21
    private $config;
22
23
    /** @var ItemService */
24
    private $itemService;
25
26
    private $appName;
27
    /**
28
     * @var IDBConnection
29
     */
30
    private $db;
31
32 2
    /**
33
     * Upgrade constructor.
34 2
     * @param IConfig $config
35 2
     * @param $appName
36 2
     */
37 2
    public function __construct(IConfig $config, ItemService $itemService,
38
                                IDBConnection $db, $appName) {
39 2
        $this->config = $config;
40 2
        $this->appName = $appName;
41 2
        $this->itemService = $itemService;
42 2
        $this->db = $db;
43
    }
44 2
45 1
    public function upgrade() {
46 1
        $previousVersion = $this->config->getAppValue(
47 2
            $this->appName, 'installed_version'
48
        );
49
50
        if (version_compare($previousVersion, '7', '<')) {
51
            $this->itemService->generateSearchIndices();
52
        }
53
    }
54
55
    public function preUpgrade() {
56
        $previousVersion = $this->config->getAppValue(
57
            $this->appName, 'installed_version'
58
        );
59
60
        $dbType = $this->config->getSystemValue('dbtype');
61
        if (version_compare($previousVersion, '8.2.2', '<') &&
62
            $dbType !== 'sqlite3'
63
        ) {
64
            $sql = 'ALTER TABLE `*PREFIX*news_feeds` DROP COLUMN 
65
                      `last_modified`';
66
            $query = $this->db->prepare($sql);
67
            $query->execute();
68
        }
69
    }
70
71
}
72