root/modules/branches/2.6/daynight/install.php

Revision 6819, 1.9 kB (checked in by p_lindheimer, 5 years ago)

fixes #3222 various sqlite3 related bugs in install scripts

Line 
1 <?php
2
3 require_once dirname(__FILE__)."/functions.inc.php";
4
5 global $db;
6 global $amp_conf;
7
8 if (! function_exists("out")) {
9     function out($text) {
10         echo $text."<br />";
11     }
12 }
13
14 if (! function_exists("outn")) {
15     function outn($text) {
16         echo $text;
17     }
18 }
19
20 $sql = "CREATE TABLE IF NOT EXISTS daynight
21         (
22                 ext varchar(10) NOT NULL default '',
23                 dmode varchar(40) NOT NULL default '',
24               dest varchar(255) NOT NULL default '',
25                 PRIMARY KEY (ext, dmode, dest)
26               );
27              ";
28 $check = $db->query($sql);
29 if(DB::IsError($check)) {
30     die_freepbx("Can not create daynight table");
31 }
32
33 // Get the old feature code if it existed to determine
34 // if it had been changed and if it was enabled
35 //
36 $delete_old = false;
37 $fcc = new featurecode('daynight', 'toggle-mode');
38 $code = $fcc->getCode();
39 if ($code != '') {
40     $delete_old = true;
41     $enabled = $fcc->isEnabled();
42     $fcc->delete();
43 }
44 unset($fcc);   
45
46 // If we found the old one then we must create all the new ones
47 //
48 if ($delete_old) {
49     $list = daynight_list();
50     foreach ($list as $item) {
51         $id = $item['ext'];
52         $fc_description = $item['dest'];
53         $fcc = new featurecode('daynight', 'toggle-mode-'.$id);
54         if ($fc_description) {
55             $fcc->setDescription("$id: $fc_description");
56         } else {
57             $fcc->setDescription("$id: Day Night Control");
58         }
59         $fcc->setDefault('*28'.$id);
60         if ($code != '*28' && $code != '') {
61             $fcc->setCode($code.$id);
62         }
63         if (!$enabled) {
64             $fcc->setEnabled(false);
65         }
66         $fcc->update();
67         unset($fcc);   
68     }
69 }
70
71 // Sqlite3 does not like this syntax, but no migration needed since it started in 2.5
72 //
73 if($amp_conf["AMPDBENGINE"] != "sqlite3")  {
74     outn(_("changing primary keys to all fields.."));
75     $sql = 'ALTER TABLE `daynight` DROP PRIMARY KEY , ADD PRIMARY KEY ( `ext` , `dmode` , `dest` )';
76     $results = $db->query($sql);
77     if(DB::IsError($results)) {
78         out(_("ERROR: failed to alter primary keys ").$results->getMessage());
79     } else {
80         out(_("OK"));
81     }
82 }
83
84 ?>
85
Note: See TracBrowser for help on using the browser.