Completed
Push — master ( 150a3d...219536 )
by
unknown
04:07
created

Upgrade::preUpgrade()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 9
nc 2
nop 0
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
    /**
33
     * Upgrade constructor.
34
     * @param IConfig $config
35
     * @param $appName
36
     */
37
    public function __construct(IConfig $config, ItemService $itemService,
38
                                IDBConnection $db, $appName) {
39
        $this->config = $config;
40
        $this->appName = $appName;
41
        $this->itemService = $itemService;
42
        $this->db = $db;
43
    }
44
45
    public function upgrade() {
46
        $previousVersion = $this->config->getAppValue(
47
            $this->appName, 'installed_version'
48
        );
49
50
        if (version_compare($previousVersion, '8.9.0', '<=')) {
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