summaryrefslogtreecommitdiffstats
path: root/bin/migrate_config.inc
blob: ee1316be2cfa15f0686190560efd926731a3ac67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
/**
 *
 * LICENSE: GNU General Public License, version 2 (GPLv2)
 * Copyright 2001 - 2013 Ampache.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License v2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

define('NO_SESSION','1'); 

$unmigratable = array('auth_methods'=>'mysql',
    'tag_order'=>'id3v2,id3v1,vorbiscomment,quicktime,ape,asf',
    'album_art_order'=>'db,id3,folder,lastfm,amazon',
    'amazon_base_urls'=>'http://webservices.amazon.com'); 

$translate = array('local_host'=>'database_hostname',
    'local_db'=>'database_name',
    'local_username'=>'database_username',
    'local_pass'=>'database_password',
    'local_length'=>'session_length',
    'stream_cmd_flac'=>'transcode_cmd_flac',
    'stream_cmd_mp3'=>'transcode_cmd_mp3',
    'stream_cmd_m4a'=>'transcode_cmd_m4a',
    'stream_cmd_ogg'=>'transcode_cmd_ogg',
    'stream_cmd_mpc'=>'transcode_cmd_mpc',
    'sess_name'=>'session_name',
    'sess_cookielife'=>'session_cookielife',
    'sess_cookiesecure'=>'session_cookiesecure'); 

$path = dirname(__FILE__);
$prefix = realpath($path . '/../');
$old_config = file_get_contents($prefix . '/config/ampache.cfg.php');

$data = explode("\n",$old_config);

echo T_("Parsing old config file...");
echo "\n";

foreach ($data as $line) {

    // Replace a # with ;
    if ($line['0'] == '#') {
        $line = substr_replace($line,";",0,1);
    }

    foreach ($unmigratable as $option=>$default) {
        if (strstr($line,$option) AND !$migrated[$option]) {
            $line = $option . " = \"$default\"";
            $migrated[$option] = true;
        }
        elseif (strstr($line,$option)) {
            $line = ';' . $line;
        }
    }

    foreach ($translate as $old=>$new) {
        if (strstr($line,$old)) {
            $line = str_replace($old,$new,$line);
        }
    }

    $new_config .= $line . "\n";

} // end foreach lines

echo T_("Parse complete, writing");
echo "\n";

$handle = fopen($prefix . '/config/ampache.cfg.php','w');

$worked = fwrite($handle,$new_config);

if ($worked) {
    echo T_("Write success, config migrated");
    echo "\n";
}
else {
    echo T_("Access Denied, config migration failed");
    echo "\n";
}

?>