public function runSqlScript($scriptlocation)
{
$script = file_get_contents($scriptlocation);
if ($script) {
$errors = array();
// Remove MySQL '-- ' and '# ' style comments
$script = preg_replace('/^(?:--|#) .*$/m', '', $script);
// Statements must end with ; and a newline
$sql_statements = preg_split('/;[\\n\\r]+/', "{$script}\n");
foreach ($sql_statements as $statement) {
$statement = trim($statement);
$statement = str_replace("prefix_", $this->table_prefix, $statement);
if (!empty($statement)) {
try {
$this->updateData($statement);
} catch (\DatabaseException $e) {
$errors[] = $e->getMessage();
}
}
}
if (!empty($errors)) {
$errortxt = "";
foreach ($errors as $error) {
$errortxt .= " {$error};";
}
$msg = "There were a number of issues: " . $errortxt;
throw new \DatabaseException($msg);
}
} else {
$msg = "Elgg couldn't find the requested database script at " . $scriptlocation . ".";
throw new \DatabaseException($msg);
}
}