summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarl Vollmer <karl.vollmer@dal.ca>2011-11-23 10:45:43 -0400
committerKarl Vollmer <karl.vollmer@dal.ca>2011-11-23 10:45:43 -0400
commitd7c65985289d61ba1ef87d55f8df5485b73e5a48 (patch)
treeb784db229e01ed9acb0d4688190d163b7c642c74 /lib
parent806b0c0b85f99a27cc169e9f99f88b6911687f4a (diff)
downloadampache-d7c65985289d61ba1ef87d55f8df5485b73e5a48.tar.gz
ampache-d7c65985289d61ba1ef87d55f8df5485b73e5a48.tar.bz2
ampache-d7c65985289d61ba1ef87d55f8df5485b73e5a48.zip
Fix DB updates so catalog remote_username and remote_password are added correctly, also fix catalog creation so they are stored in the database
Diffstat (limited to 'lib')
-rw-r--r--lib/class/catalog.class.php27
-rw-r--r--lib/class/update.class.php40
2 files changed, 58 insertions, 9 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 96e81e94..5095181f 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -294,10 +294,19 @@ class Catalog extends database_object {
$rename_pattern = Dba::escape($data['rename_pattern']);
$sort_pattern = Dba::escape($data['sort_pattern']);
$gather_types = 'NULL';
+ $remote_username = 'NULL';
+ $remote_password = 'NULL';
+
+ // Don't save these if it isn't a remote catalog
+ if ($catalog_type == 'remote') {
+ $remote_username = "'" . Dba::escape($data['remote_username']) . "'";
+ $remote_password = "'" . Dba::escape($data['remote_password']) . "'";
+ }
+
// Ok we're good to go ahead and insert this record
- $sql = "INSERT INTO `catalog` (`name`,`path`,`catalog_type`,`rename_pattern`,`sort_pattern`,`gather_types`) " .
- "VALUES ('$name','$path','$catalog_type','$rename_pattern','$sort_pattern',$gather_types)";
+ $sql = "INSERT INTO `catalog` (`name`,`path`,`catalog_type`,`remote_username`,`remote_password`,`rename_pattern`,`sort_pattern`,`gather_types`) " .
+ "VALUES ('$name','$path','$catalog_type',$remote_username,$remote_password,'$rename_pattern','$sort_pattern',$gather_types)";
$db_results = Dba::write($sql);
$insert_id = Dba::insert_id();
@@ -1275,15 +1284,17 @@ class Catalog extends database_object {
/**
* get_remote_catalog
* get a remote catalog and runs update if needed this requires
- * the XML RPC stuff and a key to be passed
+ * this uses the AmpacheAPI library provided, replaces legacy XMLRPC
*/
public function get_remote_catalog($type=0) {
- if (!class_exists('XML_RPC_Client')) {
- debug_event('xmlrpc',"Unable to load pear XMLRPC library",'1');
- echo "<span class=\"error\"><b>" . _("Error") . "</b>: " . _('Unable to load pear XMLRPC library, make sure XML-RPC is enabled') . "</span><br />\n";
- return false;
- }
+ $remote_handle = new AmpacheApi(array('username'=>'','password'=>'','server'=>''));
+
+ if ($remote_handle->state() != 'READY') {
+ debug_event('APICLIENT','Error Unable to make API client ready','1');
+ Error::add('general',_('Error Connecting to Remote Server'));
+ return false;
+ }
// Handshake and get our token for this little conversation
$token = xmlRpcClient::ampache_handshake($this->path,$this->key);
diff --git a/lib/class/update.class.php b/lib/class/update.class.php
index beb0a6c9..a03cb6d1 100644
--- a/lib/class/update.class.php
+++ b/lib/class/update.class.php
@@ -368,6 +368,9 @@ class Update {
$update_string = '- Add local auth method to session.type.<br />';
$version[] = array('version' => '360007','description' => $update_string);
+ $update_string = '- Verify remote_username and remote_password were added correctly to catalog table.<br />';
+ $version[] = array('version' => '360008','description' => $update_string);
+
return $version;
} // populate_version
@@ -1854,7 +1857,7 @@ class Update {
$db_results = Dba::write($sql);
// Add in Username / Password for catalog - to be used for remote catalogs
- $sql = "ALTER TABLE `catalog` ADD `remote_username` VARCHAR ( 255 ) AFTER `user`";
+ $sql = "ALTER TABLE `catalog` ADD `remote_username` VARCHAR ( 255 ) AFTER `catalog_type`";
$db_results = Dba::write($sql);
$sql = "ALTER TABLE `catalog` ADD `remote_password` VARCHAR ( 255 ) AFTER `remote_username`";
@@ -2005,5 +2008,40 @@ class Update {
self::set_version('db_version','360007');
}
+ /**
+ * update_360008
+ * Fix bug that caused the remote_username/password fields to not be created
+ */
+ public static function update_360008() {
+
+ $remote_username = false;
+ $remote_password = false;
+
+ $sql = "DESCRIBE `catalog`";
+ $db_results = Dba::read($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ if ($row['Field'] == 'remote_username') {
+ $remote_username = true;
+ }
+ if ($row['Field'] == 'remote_password') {
+ $remote_password = true;
+ }
+ } // end while
+
+ if (!$remote_username) {
+ // Add in Username / Password for catalog - to be used for remote catalogs
+ $sql = "ALTER TABLE `catalog` ADD `remote_username` VARCHAR ( 255 ) AFTER `catalog_type`";
+ $db_results = Dba::write($sql);
+ }
+ if (!$remote_password) {
+ $sql = "ALTER TABLE `catalog` ADD `remote_password` VARCHAR ( 255 ) AFTER `remote_username`";
+ $db_results = Dba::write($sql);
+ }
+
+ self::set_version('db_version','360008');
+
+ } // update_360008
+
} // end update class
?>