Skip to content

Commit d651d9f

Browse files
committed
Ajout du Support_update.php
1 parent b6a1996 commit d651d9f

2 files changed

Lines changed: 111 additions & 1 deletion

File tree

Support_update.php

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
// 0.3.0
3+
function switch_table_name($old_table, $new_table) {
4+
5+
global $db;
6+
7+
$execute = true;
8+
9+
try {
10+
$verif = $db->query('SHOW COLUMNS FROM '.$old_table.';');
11+
} catch(Exception $e) {
12+
$execute = false;
13+
}
14+
if(isset($verif) || empty($verif)) {
15+
$execute = false;
16+
}
17+
18+
if($execute) {
19+
20+
@$db->query('RENAME TABLE `'.$old_table.'` TO `'.$new_table.'`;');
21+
22+
}
23+
24+
}
25+
function add_column($table, $name, $sql) {
26+
27+
global $db;
28+
29+
$verif = $db->query('SHOW COLUMNS FROM '.$table.';');
30+
$execute = true;
31+
foreach ($verif as $k => $v) {
32+
if($v['COLUMNS']['Field'] == $name) {
33+
$execute = false;
34+
break;
35+
}
36+
}
37+
if($execute) {
38+
@$query = $db->query('ALTER TABLE `'.$table.'` ADD `'.$name.'` '.$sql.';');
39+
}
40+
}
41+
function remove_column($table, $name) {
42+
43+
global $db;
44+
45+
$verif = $db->query('SHOW COLUMNS FROM '.$table.';');
46+
$execute = false;
47+
foreach ($verif as $k => $v) {
48+
if($v['COLUMNS']['Field'] == $name) {
49+
$execute = true;
50+
break;
51+
}
52+
}
53+
if($execute) {
54+
@$query = $db->query('ALTER TABLE `'.$table.'` DROP COLUMN `'.$name.'`;');
55+
}
56+
}
57+
$users = array();
58+
function author_to_userid($table, $column = 'author') {
59+
60+
global $db;
61+
global $users;
62+
$verif = $db->query('SHOW COLUMNS FROM '.$table.';');
63+
$execute = false;
64+
foreach ($verif as $k => $v) {
65+
if($v['COLUMNS']['Field'] == $column) {
66+
$execute = true;
67+
break;
68+
}
69+
}
70+
if($execute) {
71+
72+
$data = $db->query('SELECT * FROM '.$table);
73+
foreach ($data as $key => $value) {
74+
75+
$table_author_id = $value[$table]['id'];
76+
$author_name = $value[$table][$column];
77+
78+
if(isset($users[$author_name])) {
79+
$author_id = $users[$author_name];
80+
} else {
81+
// on le cherche
82+
$search_author = $db->query('SELECT id FROM users WHERE pseudo=\''.$author_name.'\'');
83+
if(!empty($search_author)) {
84+
$author_id = $users[$author_name] = $search_author[0]['users']['id'];
85+
} else {
86+
$author_id = $users[$author_name] = 0;
87+
}
88+
}
89+
90+
// On leur met l'id
91+
$db->query('UPDATE '.$table.' SET user_id='.$author_id.' WHERE id='.$table_author_id);
92+
93+
unset($table_author_id);
94+
unset($author_name);
95+
unset($author_id);
96+
unset($search_author);
97+
98+
}
99+
unset($data);
100+
101+
remove_column($table, $column);
102+
103+
}
104+
}
105+
106+
// support__reply_tickets
107+
switch_table_name('reply_tickets', 'support__reply_tickets');
108+
109+
// support__tickets
110+
switch_table_name('tickets', 'support__tickets');

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"nav":true,
55
"admin":false,
66
"author":"Eywek",
7-
"version":"0.2.0",
7+
"version":"0.3.0",
88
"apiID":2,
99
"useEvents":false,
1010
"permissions" : {

0 commit comments

Comments
 (0)