2011-03-10 Miguel de Dios <miguel.dedios@artica.es>

* extensions/update_manager.php,
	extensions/update_manager/sql/update_manager.postgreSQL.sql,
	extensions/update_manager/lib/libupdate_manager_client.php,
	extensions/update_manager/lib/libupdate_manager.php,
	extensions/update_manager/lib/libupdate_manager_components.php,
	extensions/update_manager/lib/libupdate_manager_updates.php: some changes
	for the PostgreSQL.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4084 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2011-03-10 18:44:37 +00:00
parent 5ea5e7d489
commit 2b4c044e6d
7 changed files with 264 additions and 32 deletions

View File

@ -1,3 +1,13 @@
2011-03-10 Miguel de Dios <miguel.dedios@artica.es>
* extensions/update_manager.php,
extensions/update_manager/sql/update_manager.postgreSQL.sql,
extensions/update_manager/lib/libupdate_manager_client.php,
extensions/update_manager/lib/libupdate_manager.php,
extensions/update_manager/lib/libupdate_manager_components.php,
extensions/update_manager/lib/libupdate_manager_updates.php: some changes
for the PostgreSQL.
2011-03-10 Miguel de Dios <miguel.dedios@artica.es>
* include/db/postgresql.php, include/db/mysql.php, include/functions_db.php:

View File

@ -47,6 +47,7 @@ function pandora_update_manager_install () {
$sql = 'INSERT INTO `tconfig` (`token`, `value`)
VALUES ("update_manager_installed", 1)';
process_sql ($sql);
$values = array("token" => "update_manager_installed", "value" => 1);
um_db_connect ('mysql', $config['dbhost'], $config['dbuser'],
$config['dbpass'], $config['dbname']);
@ -56,11 +57,24 @@ function pandora_update_manager_install () {
}
function pandora_update_manager_uninstall () {
process_sql ('DELETE FROM `tconfig` WHERE `token` = "update_manager_installed"');
process_sql ('DROP TABLE `tupdate_settings`');
process_sql ('DROP TABLE `tupdate_journal`');
process_sql ('DROP TABLE `tupdate`');
process_sql ('DROP TABLE `tupdate_package`');
global $config;
switch ($config["dbtype"]) {
case "mysql":
process_sql ('DELETE FROM `tconfig` WHERE `token` = "update_manager_installed"');
process_sql ('DROP TABLE `tupdate_settings`');
process_sql ('DROP TABLE `tupdate_journal`');
process_sql ('DROP TABLE `tupdate`');
process_sql ('DROP TABLE `tupdate_package`');
break;
case "postgresql":
process_sql ('DELETE FROM "tconfig" WHERE "token" = \'update_manager_installed\'');
process_sql ('DROP TABLE "tupdate_settings"');
process_sql ('DROP TABLE "tupdate_journal"');
process_sql ('DROP TABLE "tupdate"');
process_sql ('DROP TABLE "tupdate_package"');
break;
}
}
function pandora_update_manager_main () {

View File

@ -39,7 +39,16 @@ function um_db_load_settings () {
}
function um_db_update_setting ($key, $value = '') {
$result = get_db_value('COUNT(*)', DB_PREFIX.'tupdate_settings', '`key`', $key);
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = get_db_value('COUNT(*)', DB_PREFIX.'tupdate_settings', '`key`', $key);
break;
case "postgresql":
$result = get_db_value('COUNT(*)', DB_PREFIX.'tupdate_settings', '"key"', $key);
break;
}
if ($result === false) {
echo '<strong>Error reading settings</strong> <br />';
@ -47,14 +56,29 @@ function um_db_update_setting ($key, $value = '') {
}
if($result > 0) {
$result = process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('`key`' => $key));
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('`key`' => $key));
break;
case "postgresql":
$result = process_sql_update(DB_PREFIX.'tupdate_settings', array('value' => $value), array('"key"' => $key));
break;
}
if ($result === false) {
echo '<strong>Error updating settings</strong> <br />';
return false;
}
} else {
$result = process_sql_insert(DB_PREFIX.'tupdate_settings', array('`key`' => $key, '`value`' => $value));
}
else {
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql_insert(DB_PREFIX.'tupdate_settings', array('`key`' => $key, '`value`' => $value));
break;
case "postgresql":
$result = process_sql_insert(DB_PREFIX.'tupdate_settings', array('"key"' => $key, '"value"' => $value));
break;
}
if ($result === false) {
echo '<strong>Error creating settings</strong> <br />';
@ -242,18 +266,39 @@ function um_db_get_total_package_logs ($ip = '') {
}
function um_db_get_all_package_logs ($ip = '', $order_by = 'timestamp', $limit = 30, $offset = 0) {
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE "%'.$ip.'%" ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE "%'.$ip.'%" ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
break;
case "postgresql":
$result = process_sql('SELECT COUNT(*)
FROM '.DB_PREFIX.'tupdate_package_log
WHERE ip_address LIKE \'%'.$ip.'%\' ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
break;
}
if ($result === false) {
echo '<strong>Error reading all package logs</strong> <br />';
return array();
}
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE "%'.$ip.'%" ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_package_log WHERE ip_address LIKE "%'.$ip.'%" ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
break;
case "postgresql":
$result = process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate_package_log
WHERE ip_address LIKE \'%'.$ip.'%\' ORDER BY '.$order_by.' DESC LIMIT '.$limit.' OFFSET '.$offset);
break;
}
$cont = 0;
$logs = array();
while(true) {
while (true) {
$log = um_std_from_result($result, $cont);
if($log === false) {
break;
@ -319,14 +364,30 @@ function um_db_delete_component ($name) {
}
function um_db_get_component ($name) {
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component WHERE name = "'.$name.'" LIMIT 1');
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component WHERE name = "'.$name.'" LIMIT 1');
break;
case "postgresql":
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' LIMIT 1');
break;
}
if ($result === false) {
echo '<strong>Error getting component</strong> <br />';
return array();
}
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE name = "'.$name.'" LIMIT 1');
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE name = "'.$name.'" LIMIT 1');
break;
case "postgresql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE name = \''.$name.'\' LIMIT 1');
break;
}
$component = um_std_from_result($result);
@ -342,7 +403,8 @@ function um_db_get_component ($name) {
function um_db_get_all_components ($type = '') {
if ($type != '') {
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component WHERE type = '.$type);
} else {
}
else {
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component');
}
@ -371,6 +433,7 @@ function um_db_create_component_db ($table_name, $field_name, $order, $component
if ($result === false) {
echo '<strong>Error creating database component</strong> <br />';
return false;
}
@ -385,6 +448,7 @@ function um_db_update_component_db ($id, $table_name = '', $field_name = '', $or
if($result === false) {
echo '<strong>Error updating database component</strong><br />';
return false;
}
@ -396,6 +460,7 @@ function um_delete_directory($dirname) {
$dir_handle = opendir($dirname);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname."/".$file))
@ -406,6 +471,7 @@ function um_delete_directory($dirname) {
}
closedir($dir_handle);
rmdir($dirname);
return true;
}
@ -421,14 +487,30 @@ function um_db_delete_component_db ($id) {
}
function um_db_get_component_db ($id_component_db) {
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE id = "'.$id_component_db.'" LIMIT 1');
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE id = "'.$id_component_db.'" LIMIT 1');
break;
case "postgresql":
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' LIMIT 1');
break;
}
if ($result === false) {
echo '<strong>Error getting database component</strong> <br />';
return NULL;
}
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE id = "'.$id_component_db.'" LIMIT 1');
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE id = "'.$id_component_db.'" LIMIT 1');
break;
case "postgresql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE id = \''.$id_component_db.'\' LIMIT 1');
break;
}
$component = um_std_from_result($result);
@ -436,14 +518,30 @@ function um_db_get_component_db ($id_component_db) {
}
function um_db_get_database_components ($component_name) {
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
break;
case "postgresql":
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate_component_db WHERE component = \''. $component_name.'\' ORDER BY "order" ASC');
break;
}
if ($result === false) {
echo '<strong>Error getting database components </strong> <br />';
return array();
}
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE component = "'. $component_name.'" ORDER BY `order` ASC');
break;
case "postgresql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_component_db WHERE component = \''. $component_name.'\' ORDER BY "order" ASC');
break;
}
$cont = 0;
$components = array();
@ -512,7 +610,16 @@ function um_db_delete_auth ($id_auth) {
}
function um_db_get_auth ($id_auth) {
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = "'.$id_auth.'" LIMIT 1');
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = "'.$id_auth.'" LIMIT 1');
break;
case "postgresql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE id = \''.$id_auth.'\' LIMIT 1');
break;
}
if ($result === false) {
echo '<strong>Error getting authorization</strong> <br />';
@ -549,7 +656,16 @@ function um_db_get_all_auths () {
}
function um_db_check_auth ($client_key, $subscription_limit) {
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE client_key = "'.$client_key.'" LIMIT 1');
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE client_key = "'.$client_key.'" LIMIT 1');
break;
case "postgresql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate_auth WHERE client_key = \''.$client_key.'\' LIMIT 1');
break;
}
if ($result === false) {
echo '<strong>Error checking authorization</strong> <br />';

View File

@ -384,12 +384,22 @@ function um_package_info_from_paths ($tmpDir) {
}
function um_client_update_from_paths ($file_paths, $tmpDir, $num_package, $type) {
global $config;
$update = array();
$i = 0;
// The number of the prefixs names is to keep alphabetic order to appliyng priority
$sql_schema_file = '01_package_'.$num_package.'_schema.sql';
$sql_data_file = '02_package_'.$num_package.'_data.sql';
switch ($config["dbtype"]) {
case "mysql":
$sql_schema_file = '01_package_'.$num_package.'_schema.sql';
$sql_data_file = '02_package_'.$num_package.'_data.sql';
break;
case "postgresql":
$sql_schema_file = '01_package_'.$num_package.'_schema.postgreSQL.sql';
$sql_data_file = '02_package_'.$num_package.'_data.postgreSQL.sql';
break;
}
foreach($file_paths as $file_name => $paths) {
if($file_name == $sql_data_file && $type == 'sql') {

View File

@ -52,13 +52,22 @@ function um_component_database_get_data ($component_db) {
}
function um_component_database_get_all_tables () {
global $config;
$db = um_component_db_connect ();
if ($db === false) {
return array ();
}
$result = process_sql('SHOW TABLES');
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SHOW TABLES');
break;
case "postgresql":
$result = process_sql('SELECT table_name FROM information_schema.tables WHERE table_schema = \'public\';');
break;
}
if ($result === false) {
echo '<strong>Error getting tables</strong> <br />';
@ -86,13 +95,22 @@ function um_component_database_get_available_tables ($component_name) {
}
function um_component_database_get_table_fields ($table_name) {
global $config;
$db = um_component_db_connect ();
if ($db === false) {
return array ();
}
$result = process_sql('SHOW COLUMNS FROM '.$table_name.' WHERE `Key` != "PRI"');
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SHOW COLUMNS FROM '.$table_name.' WHERE `Key` != "PRI"');
break;
case "postgresql":
$result = process_sql("SELECT * FROM pg_indexes WHERE tablename = '" . $table_name . "'");
break;
}
if ($result === false) {
echo '<strong>Error getting table fields</strong> <br />';
@ -154,14 +172,34 @@ function um_component_directory_get_modified_files ($component, $binary = false)
}
function um_component_get_all_blacklisted ($component) {
$result = process_sql('SELECT COUNT(name) FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"');
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT COUNT(name) FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"');
break;
case "postgresql":
$result = process_sql('SELECT COUNT(name)
FROM '.DB_PREFIX.'tupdate_component_blacklist
WHERE component = \''.$component->name.'\'');
break;
}
if ($result === false) {
echo '<strong>Error getting all blacklisted items</strong> <br />';
return array();
}
$result = process_sql('SELECT name FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"');
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT name FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'"');
break;
case "postgresql":
$result = process_sql('SELECT name
FROM '.DB_PREFIX.'tupdate_component_blacklist
WHERE component = \''.$component->name.'\'');
break;
}
$cont = 0;
$list = array();
@ -178,7 +216,18 @@ function um_component_get_all_blacklisted ($component) {
}
function um_component_is_blacklisted ($component, $name) {
$result = process_sql('SELECT COUNT(*) AS blacklisted FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'" AND name = "'.$name.'"');
global $config;
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT COUNT(*) AS blacklisted FROM '.DB_PREFIX.'tupdate_component_blacklist WHERE component = "'.$component->name.'" AND name = "'.$name.'"');
break;
case "postgresql":
$result = process_sql('SELECT COUNT(*) AS blacklisted
FROM '.DB_PREFIX.'tupdate_component_blacklist
WHERE component = \''.$component->name.'\' AND name = \''.$name.'\'');
break;
}
if ($result === false) {
echo '<strong>Error getting blacklist item</strong> <br />';

View File

@ -15,18 +15,38 @@
function um_update_get_last_from_filename ($component_name, $filename) {
global $config;
$component = um_db_get_component ($component_name);
if (! $component)
return;
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND filename = "'.$component->relative_path.$filename.'" ORDER BY id DESC LIMIT 1');
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND filename = "'.$component->relative_path.$filename.'" ORDER BY id DESC LIMIT 1');
break;
case "postgresql":
$result = process_sql('SELECT COUNT(*) FROM '.DB_PREFIX.'tupdate WHERE component = \''.$component_name.'\' AND filename = \''.$component->relative_path.$filename.'\' ORDER BY id DESC LIMIT 1');
break;
}
if ($result === false) {
echo '<strong>Error getting update from filename</strong> <br />';
return NULL;
}
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND filename = "'.$component->relative_path.$filename.'" ORDER BY id DESC LIMIT 1');
switch ($config["dbtype"]) {
case "mysql":
$result = process_sql('SELECT * FROM '.DB_PREFIX.'tupdate WHERE component = "'.$component_name.'" AND filename = "'.$component->relative_path.$filename.'" ORDER BY id DESC LIMIT 1');
break;
case "postgresql":
$result = process_sql('SELECT *
FROM '.DB_PREFIX.'tupdate
WHERE component = \''.$component_name.'\'
AND filename = \''.$component->relative_path.$filename.'\' ORDER BY id DESC LIMIT 1');
break;
}
$update = um_std_from_result($result);
@ -104,6 +124,7 @@ function um_db_delete_update ($id_update) {
function um_db_create_update ($type, $component_name, $id_package, $update, $db_data = NULL) {
global $db;
global $config;
if ($id_package == 0)
return false;
@ -143,8 +164,14 @@ function um_db_create_update ($type, $component_name, $id_package, $update, $db_
$field = $component_db->field_name;
$values['db_field_value'] = $db_data->$field;
$values['id_component_db'] = $update->id_component_db;
$values['data'] = um_data_encode('INSERT INTO `'.$component_db->table_name.'` (`'.implode('`,`', array_keys (get_object_vars ($db_data))).'`) VALUES (\''.implode('\',\'', get_object_vars ($db_data)).'\')');
switch ($config["dbtype"]) {
case "mysql":
$values['data'] = um_data_encode('INSERT INTO `'.$component_db->table_name.'` (`'.implode('`,`', array_keys (get_object_vars ($db_data))).'`) VALUES (\''.implode('\',\'', get_object_vars ($db_data)).'\')');
break;
case "postgresql":
$values['data'] = um_data_encode('INSERT INTO "'.$component_db->table_name.'" ("'.implode('", "', array_keys (get_object_vars ($db_data))).'") VALUES (\''.implode('\',\'', get_object_vars ($db_data)).'\')');
break;
}
break;
case 'db_schema':
$values['data'] = um_data_encode($update->data);

View File

@ -0,0 +1,6 @@
CREATE TABLE "tupdate_settings" ( "key" varchar(255) default '' PRIMARY KEY, "value" varchar(255) default '');
INSERT INTO "tupdate_settings" VALUES ('current_update', '0'), ('customer_key', 'PANDORA-FREE'), ('keygen_path', '/usr/share/pandora/util/keygen'), ('update_server_host', 'www.artica.es'), ('update_server_port', '80'), ('update_server_path', '/pandoraupdate321/server.php'), ('updating_binary_path', 'Path where the updated binary files will be stored'), ('updating_code_path', 'Path where the updated code is stored'), ('dbname', ''), ('dbhost', ''), ('dbpass', ''), ('dbuser', ''), ('proxy', ''), ('proxy_port', ''), ('proxy_user', ''), ('proxy_pass', '');
CREATE TABLE "tupdate_package"( "id" SERIAL NOT NULL PRIMARY KEY, "timestamp" TIMESTAMP without time zone default NULL, "description" varchar(255) default '');
CREATE TYPE type_tupdate_type AS ENUM ('code', 'db_data', 'db_schema', 'binary');
CREATE TABLE "tupdate" ( "id" SERIAL NOT NULL PRIMARY KEY, "type" type_tupdate_type, "id_update_package" INTEGER default 0 REFERENCES "tupdate_package"("id") ON UPDATE CASCADE ON DELETE CASCADE, "filename" varchar(250) default '', "checksum" varchar(250) default '', "previous_checksum" varchar(250) default '', "svn_version" INTEGER default 0, "data" TEXT default '', "data_rollback" TEXT default '', "description" TEXT default '', "db_table_name" varchar(140) default '', "db_field_name" varchar(140) default '', "db_field_value" varchar(1024) default '');
CREATE TABLE "tupdate_journal" ( "id" SERIAL NOT NULL PRIMARY KEY, "id_update" INTEGER default 0 REFERENCES "tupdate"("id") ON UPDATE CASCADE ON DELETE CASCADE);