diff --git a/core/src/core/classes/class.AJXP_Utils.php b/core/src/core/classes/class.AJXP_Utils.php index f7f7c8f812..4282d16313 100644 --- a/core/src/core/classes/class.AJXP_Utils.php +++ b/core/src/core/classes/class.AJXP_Utils.php @@ -1690,19 +1690,31 @@ public static function runCreateTablesQuery($p, $file) $result = array(); $file = dirname($file) ."/". str_replace(".sql", $ext, basename($file) ); $sql = file_get_contents($file); - $parts = explode(";", $sql); - $remove = array(); - for ($i = 0 ; $i < count($parts); $i++) { - $part = $parts[$i]; - if (strpos($part, "BEGIN") && isSet($parts[$i+1])) { - $parts[$i] .= ';'.$parts[$i+1]; - $remove[] = $i+1; + $separators = explode("/** SEPARATOR **/", $sql); + + $allParts = array(); + + foreach($separators as $sep){ + $firstLine = array_shift(explode("\n", trim($sep))); + if($firstLine == "/** BLOCK **/"){ + $allParts[] = $sep; + }else{ + $parts = explode(";", $sep); + $remove = array(); + for ($i = 0 ; $i < count($parts); $i++) { + $part = $parts[$i]; + if (strpos($part, "BEGIN") && isSet($parts[$i+1])) { + $parts[$i] .= ';'.$parts[$i+1]; + $remove[] = $i+1; + } + } + foreach($remove as $rk) unset($parts[$rk]); + $allParts = array_merge($allParts, $parts); } } - foreach($remove as $rk) unset($parts[$rk]); dibi::connect($p); dibi::begin(); - foreach ($parts as $createPart) { + foreach ($allParts as $createPart) { $sqlPart = trim($createPart); if (empty($sqlPart)) continue; try { diff --git a/core/src/plugins/conf.sql/class.sqlConfDriver.php b/core/src/plugins/conf.sql/class.sqlConfDriver.php index 875fab38c6..56b752cbaa 100644 --- a/core/src/plugins/conf.sql/class.sqlConfDriver.php +++ b/core/src/plugins/conf.sql/class.sqlConfDriver.php @@ -313,6 +313,9 @@ public function getRepositoryById($repositoryId) $repo_row = $res->fetchAll(); if (count($repo_row) > 0) { $repo_row = $repo_row[0]; + if($this->sqlDriver["driver"] == "postgre"){ + dibi::nativeQuery("SET bytea_output=escape"); + } $res_opts = dibi::query('SELECT * FROM [ajxp_repo_options] WHERE [uuid] = %s', $repo_row['uuid']); $opts = $res_opts->fetchPairs('name', 'val'); $repository = $this->repoFromDb($repo_row, $opts); @@ -335,6 +338,9 @@ public function getRepositoryByAlias($repositorySlug) $repo_row = $res->fetchAll(); if (count($repo_row) > 0) { $repo_row = $repo_row[0]; + if($this->sqlDriver["driver"] == "postgre"){ + dibi::nativeQuery("SET bytea_output=escape"); + } $res_opts = dibi::query('SELECT * FROM [ajxp_repo_options] WHERE [uuid] = %s', $repo_row['uuid']); $opts = $res_opts->fetchPairs('name', 'val'); $repository = $this->repoFromDb($repo_row, $opts); @@ -439,7 +445,7 @@ public function deleteRepository($repositoryId) case "sqlite": case "sqlite3": case "postgre": - dibi::query("SET bytea_output=escape"); + dibi::nativeQuery("SET bytea_output=escape"); $children_results = dibi::query('SELECT * FROM [ajxp_roles] WHERE [searchable_repositories] LIKE %~like~ GROUP BY [role_id]', '"'.$repositoryId.'";s:'); break; case "mysql": @@ -608,7 +614,7 @@ public function listRoles($roleIds = array(), $excludeReserved = false) $wClauses[] = array('[role_id] NOT LIKE %like~', 'AJXP_'); } if($this->sqlDriver["driver"] == "postgre"){ - dibi::query("SET bytea_output=escape"); + dibi::nativeQuery("SET bytea_output=escape"); } $res = dibi::query('SELECT * FROM [ajxp_roles] %if', count($wClauses), 'WHERE %and', $wClauses); $all = $res->fetchAll(); @@ -818,7 +824,7 @@ public function simpleStoreClear($storeID, $dataID) public function simpleStoreGet($storeID, $dataID, $dataType, &$data) { if($this->sqlDriver["driver"] == "postgre"){ - dibi::query("SET bytea_output=escape"); + dibi::nativeQuery("SET bytea_output=escape"); } $children_results = dibi::query("SELECT * FROM [ajxp_simple_store] WHERE [store_id]=%s AND [object_id]=%s", $storeID, $dataID); $value = $children_results->fetchAll(); diff --git a/core/src/plugins/meta.syncable/create.pgsql b/core/src/plugins/meta.syncable/create.pgsql index 99860769b9..319cfc16c0 100644 --- a/core/src/plugins/meta.syncable/create.pgsql +++ b/core/src/plugins/meta.syncable/create.pgsql @@ -27,6 +27,8 @@ CREATE TABLE ajxp_index ( CREATE INDEX ajxp_index_repo_id ON ajxp_index (repository_identifier); CREATE INDEX ajxp_index_md5 ON ajxp_index (md5); +/** SEPARATOR **/ +/** BLOCK **/ CREATE FUNCTION ajxp_index_delete() RETURNS trigger AS $ajxp_index_delete$ BEGIN INSERT INTO ajxp_changes (repository_identifier, node_id,source,target,type) @@ -35,6 +37,8 @@ CREATE FUNCTION ajxp_index_delete() RETURNS trigger AS $ajxp_index_delete$ END; $ajxp_index_delete$ LANGUAGE plpgsql; +/** SEPARATOR **/ +/** BLOCK **/ CREATE FUNCTION ajxp_index_insert() RETURNS trigger AS $ajxp_index_insert$ BEGIN INSERT INTO ajxp_changes (repository_identifier, node_id,source,target,type) @@ -43,6 +47,8 @@ CREATE FUNCTION ajxp_index_insert() RETURNS trigger AS $ajxp_index_insert$ END; $ajxp_index_insert$ LANGUAGE plpgsql; +/** SEPARATOR **/ +/** BLOCK **/ CREATE FUNCTION ajxp_index_update() RETURNS trigger AS $ajxp_index_update$ BEGIN IF OLD.node_path = NEW.node_path THEN @@ -55,6 +61,7 @@ CREATE FUNCTION ajxp_index_update() RETURNS trigger AS $ajxp_index_update$ RETURN NEW; END; $ajxp_index_update$ LANGUAGE plpgsql; +/** SEPARATOR **/ CREATE TRIGGER LOG_DELETE AFTER DELETE ON ajxp_index FOR EACH ROW EXECUTE PROCEDURE ajxp_index_delete();