public function updateSchema($withDrop = false)
{
$sql = self::getSqlDiff($withDrop);
if (is_array($sql)) {
throw new \Exception("Propel updateSchema failed: \n" . $sql[0]);
}
if (!$sql) {
return "Schema up 2 date.";
}
$sql = explode(";\n", $sql);
$this->loadConfig();
$con = Propel::getWriteConnection('default');
$tablePrefix = $this->getJarves()->getSystemConfig()->getDatabase()->getPrefix();
$con->beginTransaction();
try {
foreach ($sql as $query) {
if ($tablePrefix && 0 === strpos($query, 'DROP')) {
preg_match('/DROP ([^\\s]*) /', $query, $match);
if (isset($match[1]) && $match[1]) {
$tableName = preg_replace('/[^a-zA-Z0-9_]\\.\\$/', '', $match[1]);
if (false !== ($pos = strpos($tableName, '.'))) {
$tableName = substr($tableName, $pos + 1);
}
if (0 === strpos($tableName, $tablePrefix)) {
//tablePrefix is in this table name at the beginning, so jump over
continue;
}
}
}
$con->exec($query);
}
} catch (\PDOException $e) {
$con->rollBack();
throw new \PDOException($e->getMessage() . ' in SQL: ' . $query);
}
$con->commit();
return 'ok';
}