-
Notifications
You must be signed in to change notification settings - Fork 2
/
sql2mage_installer.php
68 lines (55 loc) · 1.73 KB
/
sql2mage_installer.php
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
<?php
define('ROOT_DIR', __DIR__);
include_once ROOT_DIR . '/src/StatementConvertor.php';
if (6 > count($argv)) {
echo "Usage: php -f {$argv[0]} [host] [user] [password] [database] [tables]\n";
return;
}
$host = $argv[1];
$username = $argv[2];
$password = $argv[3];
$database = $argv[4];
$tableNames = $argv[5];
// $magentoVersion = 2;//isset($argv[6]) ? $argv[6] : 2;
$connection = mysqli_connect($host, $username, $password);
mysqli_select_db($connection, $database);
$tableNames = explode(',', $tableNames);
$convertor = new \Swissup\StatementConvertor();
$convertor->setReplacements([
'vendorName' => [
'Tm' => 'Swissup'
],
'moduleName' => [
'Helpmate' => 'Helpdesk'
],
'tableName' => [
'tm_helpmate_department' => 'swissup_helpdesk_department',
'tm_helpmate_department_user' => 'swissup_helpdesk_department_user',
'tm_helpmate_status' => 'swissup_helpdesk_status',
'tm_helpmate_theard' => 'swissup_helpdesk_message',
'tm_helpmate_ticket' => 'swissup_helpdesk_ticket'
],
'modelName' => [
'Theard' => 'Message'
]
]);
$delimiter = "***************************";
$delimiter .= $delimiter . $delimiter;
$delimiter = "\n{$delimiter}\n";
foreach ($tableNames as $tableName) {
$query = "SHOW CREATE TABLE {$tableName}";
$result = mysqli_query($connection, $query);
$_sql = array();
$sql = '';
while ($line = mysqli_fetch_array($result)) {
foreach ($line as $value) {
$_sql[] = $value;
}
}
$sql = $_sql[2];
echo "{$delimiter}" . $sql . "{$delimiter}";
$convertor->parse($sql);
echo $convertor;
echo "{$delimiter}";
}
mysqli_close($connection);