-
Notifications
You must be signed in to change notification settings - Fork 4
/
class.trello_install.php
84 lines (75 loc) · 2.3 KB
/
class.trello_install.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require_once 'class.setup.php';
class TrelloInstaller extends SetupWizard {
/**
* Loads, checks and installs SQL file.
*
* @return boolean
*/
function install() {
$schemaFile = TRELLO_PLUGIN_ROOT . 'install/sql/install_trello.sql'; // DB dump.
return $this->runJob ( $schemaFile );
}
private function runJob($schemaFile, $show_sql_errors = true) {
// Last minute checks.
if (! file_exists ( $schemaFile )) {
echo '<br />';
var_dump ( $schemaFile );
echo '<br />';
echo 'File Access Error - please make sure your download is the latest (#1)';
echo '<br />';
$this->error = 'File Access Error!';
return false;
} elseif (! $this->load_sql_file ( $schemaFile, TABLE_PREFIX, true, true )) {
if ($show_sql_errors) {
echo '<br />';
echo 'Error parsing SQL schema! Get help from developers (#4)';
echo '<br />';
return false;
}
return true;
}
return true;
}
function remove() {
$schemaFile = TRELLO_PLUGIN_ROOT . 'install/sql/remove_trello.sql'; // DB dump.
return $this->runJob ( $schemaFile );
}
function purgeData() {
$schemaFile = TRELLO_PLUGIN_ROOT . 'install/sql/purge_trello_data.sql'; // DB dump.
return $this->runJob ( $schemaFile );
}
/**
* Overriding split, we need semicolons in procedures and triggers, so
* the dollar sign is used instead.
*
* @param type $schema
* @param type $prefix
* @param type $abort
* @param type $debug
* @return boolean
*/
function load_sql($schema, $prefix, $abort = true, $debug = false) {
// Strip comments and remarks
$schema = preg_replace ( '%^\s*(#|--).*$%m', '', $schema );
// Replace table prefix
$schema = str_replace ( '%TABLE_PREFIX%', $prefix, $schema );
// Split by dollar signs - and cleanup
if (! ($statements = array_filter ( array_map ( 'trim',
// Thanks, http://stackoverflow.com/a/3147901
preg_split ( "/\\$(?=(?:[^']*'[^']*')*[^']*$)/", $schema ) ) )))
return $this->abort ( 'Error parsing SQL schema', $debug );
db_query ( 'SET SESSION SQL_MODE =""', false );
foreach ( $statements as $k => $sql ) {
if (db_query ( $sql, false ))
continue;
if (db_error () != null) {
$error = "[$sql] " . db_error ();
if ($abort)
return $this->abort ( $error, $debug );
}
}
return true;
}
}
?>