Migration   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 55
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 2 1
A __construct() 0 8 1
A run() 0 13 4
1
<?php
2
/**
3
 * Audio Player
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @copyright 2016-2019 Marcel Scherello
10
 */
11
12
namespace OCA\audioplayer\Migration;
13
14
use OCP\IConfig;
15
use OCP\IDBConnection;
16
use OCP\Migration\IOutput;
17
use OCP\Migration\IRepairStep;
18
use OCP\ILogger;
19
20
class Migration implements IRepairStep {
21
22
	/** @var IDBConnection */
23
	protected $connection;
24
25
	/** @var IConfig */
26
	protected $config;
27
    private $logger;
28
29
    /**
30
     * @param IDBConnection $connection
31
     * @param IConfig $config
32
     * @param ILogger $logger
33
     */
34
	public function __construct(
35
	        IDBConnection $connection,
36
            IConfig $config,
37
            ILogger $logger
38
    ) {
39
		$this->connection = $connection;
40
		$this->config = $config;
41
        $this->logger = $logger;
42
	}
43
44
	/**
45
	 * Returns the step's name
46
	 *
47
	 * @return string
48
	 * @since 9.1.0
49
	 */
50
	public function getName() {
51
		return 'Cleanup of old Audio Player tables';
52
	}
53
54
	/**
55
	 * Run repair step.
56
	 * Must throw exception on error.
57
	 *
58
	 * @since 9.1.0
59
	 * @param IOutput $output
60
	 * @throws \Exception in case of failure
61
	 */
62
	public function run(IOutput $output) {
63
		$version = $this->config->getAppValue('audioplayer', 'installed_version', '0.0.0');
64
		if (version_compare($version, '2.1.0', '>')) {
65
            $this->logger->info('Migration of Audio Player started', array('app' => 'audioplayer'));
66
            if ($this->connection->tableExists('audioplayer_statistics')) {
67
				$this->connection->dropTable('audioplayer_statistics');
68
                $this->logger->info('Table -audioplayer_statistics- deleted', array('app' => 'audioplayer'));
69
			}
70
			if ($this->connection->tableExists('audioplayer_album_artists')) {
71
				$this->connection->dropTable('audioplayer_album_artists');
72
                $this->logger->info('Table -audioplayer_album_artists- deleted', array('app' => 'audioplayer'));
73
			}
74
			$output->finishProgress();
75
		}
76
	}
77
}
78