initial commit of file from CVS for smeserver-horde on Sat Mar 23 16:05:15 AEDT 2024
This commit is contained in:
2
root/usr/share/horde/smeserver/horde_mysql_create_db.sql
Normal file
2
root/usr/share/horde/smeserver/horde_mysql_create_db.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
CREATE DATABASE IF NOT EXISTS horde;
|
||||
|
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* This script migrates Ingo's share data from the datatree Horde_Share
|
||||
* driver to the SQL Horde_Share driver.
|
||||
*/
|
||||
|
||||
$baseFile = dirname(__FILE__) . '/../../ingo/lib/Application.php';
|
||||
if (file_exists($baseFile)) {
|
||||
require_once $baseFile;
|
||||
} else {
|
||||
require_once 'PEAR/Config.php';
|
||||
require_once PEAR_Config::singleton()
|
||||
->get('horde_dir', null, 'pear.horde.org') . '/ingo/lib/Application.php';
|
||||
}
|
||||
Horde_Registry::appInit('ingo', array('cli' => true));
|
||||
|
||||
$db = $injector->getInstance('Horde_Db_Adapter');
|
||||
|
||||
$error_cnt = 0;
|
||||
$delete_dt_data = true;
|
||||
|
||||
/* Get the share entries */
|
||||
$shares_result = $db->selectAssoc('SELECT datatree_id, datatree_name FROM horde_datatree WHERE group_uid = ' . $db->quoteString('horde.shares.ingo'));
|
||||
|
||||
$query = 'SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?';
|
||||
foreach ($shares_result as $share_id => $share_name) {
|
||||
/* Build an array to hold the new row data */
|
||||
$nextId = null;
|
||||
$data = array('share_name' => $share_name);
|
||||
$rows = $db->selectAll($query, array($share_id));
|
||||
$users = array();
|
||||
$groups = array();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if ($row['attribute_name'] == 'perm_groups') {
|
||||
/* Group table entry */
|
||||
$groups[] = array('group_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} elseif ($row['attribute_name'] == 'perm_users') {
|
||||
/* User table entry */
|
||||
$users[] = array('user_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} else {
|
||||
/* Everything else goes in the main share table */
|
||||
switch ($row['attribute_name']) {
|
||||
case 'perm_creator':
|
||||
case 'perm_default':
|
||||
case 'perm_guest':
|
||||
$data[$row['attribute_name']] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'owner':
|
||||
$data['share_owner'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'name':
|
||||
// Note the key to the $data array is not related to
|
||||
// the attribute_name field in the dt_attributes table.
|
||||
$data['attribute_name'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'desc':
|
||||
$data['attribute_desc'] = $row['attribute_value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set flags */
|
||||
$data['share_flags'] = 0;
|
||||
if (count($users)) {
|
||||
$data['share_flags'] |= 1;
|
||||
}
|
||||
if (count($groups)) {
|
||||
$data['share_flags'] |= 2;
|
||||
}
|
||||
|
||||
/* Insert the new data */
|
||||
$cli->message('Migrating share data for share_id: ' . $share_id, 'cli.message');
|
||||
$error = false;
|
||||
$db->beginDbTransaction();
|
||||
try {
|
||||
$nextId = insertData('ingo_shares', $data, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
if (count($groups)) {
|
||||
foreach ($groups as $group) {
|
||||
$group['share_id'] = $nextId;
|
||||
try {
|
||||
insertData('ingo_shares_groups', $group, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($users)) {
|
||||
foreach ($users as $user) {
|
||||
$user['share_id'] = $nextId;
|
||||
try {
|
||||
insertData('ingo_shares_users', $user, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the datatree data, but ONLY if it was requested */
|
||||
if ($delete_dt_data && !$error) {
|
||||
$cli->message('DELETING datatree data for share_id: ' . $share_id, 'cli.message');
|
||||
try {
|
||||
$db->delete('DELETE FROM horde_datatree_attributes WHERE datatree_id = ?', array($share_id));
|
||||
$db->delete('DELETE FROM horde_datatree WHERE datatree_id = ?', array($share_id));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
unset($row, $rows, $data, $groups, $users);
|
||||
if ($error) {
|
||||
$db->rollbackDbTransaction();
|
||||
$cli->message('Rollback for share data for share_id: ' . $share_id, 'cli.message');
|
||||
++$error_cnt;
|
||||
} else {
|
||||
$db->commitDbTransaction();
|
||||
$cli->message('Commit for share data for share_id: ' . $share_id, 'cli.message');
|
||||
}
|
||||
}
|
||||
if ($error_cnt) {
|
||||
$cli->message(sprintf("Encountered %u errors.", $error_cnt));
|
||||
}
|
||||
echo "\nDone.\n";
|
||||
|
||||
/**
|
||||
* Helper function
|
||||
*/
|
||||
function insertData($table, $data, $db)
|
||||
{
|
||||
$fields = array_keys($data);
|
||||
$values = array_values($data);
|
||||
$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (' . str_repeat('?, ', count($values) - 1);
|
||||
return $db->insert($sql, $values);
|
||||
}
|
||||
|
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* This script migrates Kronolith's share data from the datatree Horde_Share
|
||||
* driver to the SQL Horde_Share driver.
|
||||
*/
|
||||
if (file_exists(__DIR__ . '/../../kronolith/lib/Application.php')) {
|
||||
$baseDir = __DIR__ . '/../';
|
||||
} else {
|
||||
require_once 'PEAR/Config.php';
|
||||
$baseDir = PEAR_Config::singleton()
|
||||
->get('horde_dir', null, 'pear.horde.org') . '/kronolith/';
|
||||
}
|
||||
require_once $baseDir . 'lib/Application.php';
|
||||
Horde_Registry::appInit('kronolith', array('cli' => true));
|
||||
|
||||
$db = $injector->getInstance('Horde_Db_Adapter');
|
||||
$error_cnt = 0;
|
||||
$delete_dt_data = true;
|
||||
|
||||
/**
|
||||
*** Remarked by John H. Bennett III <bennettj@johnbennettservices> for automated SME Server install
|
||||
$delete_dt_data = false;
|
||||
$answer = $cli->prompt('Do you want to keep your old datatree data or delete it?', array('Keep', 'Delete'));
|
||||
if ($answer == 1) {
|
||||
$delete_dt_data = true;
|
||||
}
|
||||
$answer = $cli->prompt(sprintf("Data will be copied into the new tables, and %s be deleted from the datatree.\n Is this what you want?", (($delete_dt_data) ? 'WILL' : 'WILL NOT')), array('y' => 'Yes', 'n' => 'No'));
|
||||
if ($answer != 'y') {
|
||||
exit;
|
||||
}
|
||||
*** End of remark
|
||||
*/
|
||||
|
||||
/* Get the share entries */
|
||||
try {
|
||||
$shares_result = $db->selectAssoc('SELECT datatree_id, datatree_name FROM horde_datatree WHERE group_uid = ' . $db->quoteString('horde.shares.kronolith'));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
$query = 'SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?';
|
||||
foreach ($shares_result as $share_id => $share_name) {
|
||||
$data = array('share_name' => $share_name);
|
||||
$rows = $db->selectAll($query, array($share_id));
|
||||
$users = array();
|
||||
$groups = array();
|
||||
foreach ($rows as $row) {
|
||||
if ($row['attribute_name'] == 'perm_groups') {
|
||||
/* Group table entry */
|
||||
$groups[] = array('group_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} elseif ($row['attribute_name'] == 'perm_users') {
|
||||
/* User table entry */
|
||||
$users[] = array('user_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} else {
|
||||
/* Everything else goes in the main share table */
|
||||
switch ($row['attribute_name']) {
|
||||
case 'perm_creator':
|
||||
case 'perm_default':
|
||||
case 'perm_guest':
|
||||
$data[$row['attribute_name']] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'owner':
|
||||
$data['share_owner'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'name':
|
||||
// Note the key to the $data array is not related to
|
||||
// the attribute_name field in the dt_attributes table.
|
||||
$data['attribute_name'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'desc':
|
||||
$data['attribute_desc'] = $row['attribute_value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set flags */
|
||||
$data['share_flags'] = 0;
|
||||
if (count($users)) {
|
||||
$data['share_flags'] |= 1;
|
||||
}
|
||||
if (count($groups)) {
|
||||
$data['share_flags'] |= 2;
|
||||
}
|
||||
|
||||
/* Insert the new data */
|
||||
$cli->message('Migrating share data for share_id: ' . $share_id, 'cli.message');
|
||||
$error = false;
|
||||
$db->beginDbTransaction();
|
||||
try {
|
||||
$newId = insertData('kronolith_shares', $data, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error=true;
|
||||
}
|
||||
if (count($groups)) {
|
||||
foreach ($groups as $group) {
|
||||
try {
|
||||
$group['share_id'] = $newId;
|
||||
insertData('kronolith_shares_groups', $group, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($users)) {
|
||||
foreach ($users as $user) {
|
||||
try {
|
||||
$user['share_id'] = $newId;
|
||||
insertData('kronolith_shares_users', $user, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the datatree data, but ONLY if it was requested */
|
||||
if ($delete_dt_data && !$error) {
|
||||
$cli->message('DELETING datatree data for share_id: ' . $share_id, 'cli.message');
|
||||
try {
|
||||
$db->delete('DELETE FROM horde_datatree_attributes WHERE datatree_id = ?', array($share_id));
|
||||
$db->delete('DELETE FROM horde_datatree WHERE datatree_id = ?', array($share_id));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
unset($row, $rows, $data, $groups, $users);
|
||||
if ($error) {
|
||||
$db->rollbackDbTransaction();
|
||||
$cli->message('Rollback for share data for share_id: ' . $share_id, 'cli.message');
|
||||
++$error_cnt;
|
||||
} else {
|
||||
$db->commitDbTransaction();
|
||||
$cli->message('Commit for share data for share_id: ' . $share_id, 'cli.message');
|
||||
}
|
||||
}
|
||||
|
||||
if ($error_cnt) {
|
||||
$cli->message(sprintf("Encountered %u errors.", $error_cnt));
|
||||
}
|
||||
echo "\nDone.\n";
|
||||
|
||||
/**
|
||||
* Helper function
|
||||
*/
|
||||
function insertData($table, $data, $db)
|
||||
{
|
||||
$fields = array_keys($data);
|
||||
$values = array_values($data);
|
||||
$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (' . str_repeat('?, ', count($values) - 1) . '?)';
|
||||
return $db->insert($sql, $values);
|
||||
}
|
@@ -0,0 +1,166 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* This script migrates Mnemo's share data from the datatree Horde_Share
|
||||
* driver to the new SQL Horde_Share driver. You should run the 2.1_to_2.2.sql
|
||||
* upgrade script before executing this script.
|
||||
*/
|
||||
|
||||
if (file_exists(__DIR__ . '/../../mnemo/lib/Application.php')) {
|
||||
$baseDir = __DIR__ . '/../';
|
||||
} else {
|
||||
require_once 'PEAR/Config.php';
|
||||
$baseDir = PEAR_Config::singleton()
|
||||
->get('horde_dir', null, 'pear.horde.org') . '/mnemo/';
|
||||
}
|
||||
require_once $baseDir . 'lib/Application.php';
|
||||
Horde_Registry::appInit('mnemo', array('cli' => true));
|
||||
|
||||
$db = $injector->getInstance('Horde_Db_Adapter');
|
||||
|
||||
$error_cnt = 0;
|
||||
$delete_dt_data = true;
|
||||
|
||||
/**
|
||||
*** Remarked by John H. Bennett III <bennettj@johnbennettservices> for automated SME Server install
|
||||
$delete_dt_data = false;
|
||||
$answer = $cli->prompt('Do you want to keep your old datatree data or delete it?', array('Keep', 'Delete'));
|
||||
if ($answer == 1) {
|
||||
$delete_dt_data = true;
|
||||
}
|
||||
$answer = $cli->prompt(sprintf("Data will be copied into the new tables, and %s be deleted from the datatree.\n Is this what you want?", (($delete_dt_data) ? 'WILL' : 'WILL NOT')), array('y' => 'Yes', 'n' => 'No'));
|
||||
if ($answer != 'y') {
|
||||
exit;
|
||||
}
|
||||
*** End of remark
|
||||
*/
|
||||
|
||||
/* Get the share entries */
|
||||
try {
|
||||
$shares_result = $db->selectAssoc('SELECT datatree_id, datatree_name FROM horde_datatree WHERE group_uid = ' . $db->quoteString('horde.shares.mnemo'));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
$query = 'SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?';
|
||||
foreach ($shares_result as $share_id => $share_name) {
|
||||
$data = array('share_name' => $share_name);
|
||||
$rows = $db->selectAll($query, array($share_id));
|
||||
$users = array();
|
||||
$groups = array();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if ($row['attribute_name'] == 'perm_groups') {
|
||||
/* Group table entry */
|
||||
$groups[] = array('group_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} elseif ($row['attribute_name'] == 'perm_users') {
|
||||
/* User table entry */
|
||||
$users[] = array('user_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} else {
|
||||
/* Everything else goes in the main share table */
|
||||
switch ($row['attribute_name']) {
|
||||
case 'perm_creator':
|
||||
case 'perm_default':
|
||||
case 'perm_guest':
|
||||
$data[$row['attribute_name']] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'owner':
|
||||
$data['share_owner'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'name':
|
||||
// Note the key to the $data array is not related to
|
||||
// the attribute_name field in the dt_attributes table.
|
||||
$data['attribute_name'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'desc':
|
||||
$data['attribute_desc'] = $row['attribute_value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set flags */
|
||||
$data['share_flags'] = 0;
|
||||
if (count($users)) {
|
||||
$data['share_flags'] |= 1;
|
||||
}
|
||||
if (count($groups)) {
|
||||
$data['share_flags'] |= 2;
|
||||
}
|
||||
|
||||
/* Insert the new data */
|
||||
$cli->message('Migrating share data for share_id: ' . $share_id, 'cli.message');
|
||||
$error = false;
|
||||
$db->beginDbTransaction();
|
||||
try {
|
||||
$nextId = insertData('mnemo_shares', $data, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
if (count($groups)) {
|
||||
foreach ($groups as $group) {
|
||||
$group['share_id'] = $nextId;
|
||||
try {
|
||||
insertData('mnemo_shares_groups', $group, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($users)) {
|
||||
foreach ($users as $user) {
|
||||
$user['share_id'] = $nextId;
|
||||
try {
|
||||
insertData('mnemo_shares_users', $user, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the datatree data, but ONLY if it was requested */
|
||||
if ($delete_dt_data && !$error) {
|
||||
$cli->message('DELETING datatree data for share_id: ' . $share_id, 'cli.message');
|
||||
try {
|
||||
$db->delete('DELETE FROM horde_datatree_attributes WHERE datatree_id = ?',array($share_id));
|
||||
$db->delete('DELETE FROM horde_datatree WHERE datatree_id = ?', array($share_id));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
unset($row, $rows, $data, $groups, $users);
|
||||
if ($error) {
|
||||
$db->rollbackDbTransaction();
|
||||
$cli->message('Rollback for share data for share_id: ' . $share_id, 'cli.message');
|
||||
++$error_cnt;
|
||||
} else {
|
||||
$db->commitDbTransaction();
|
||||
$cli->message('Commit for share data for share_id: ' . $share_id, 'cli.message');
|
||||
}
|
||||
}
|
||||
if ($error_cnt) {
|
||||
$cli->message(sprintf("Encountered %u errors.", $error_cnt));
|
||||
}
|
||||
echo "\nDone.\n";
|
||||
|
||||
/**
|
||||
* Helper function
|
||||
*/
|
||||
function insertData($table, $data, $db)
|
||||
{
|
||||
$fields = array_keys($data);
|
||||
$values = array_values($data);
|
||||
$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (' . str_repeat('?, ', count($values) - 1) . '?)';
|
||||
return $db->insert($sql, $values);
|
||||
}
|
6
root/usr/share/horde/smeserver/mysql_migrate_horde.sql
Normal file
6
root/usr/share/horde/smeserver/mysql_migrate_horde.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CONNECT mysql;
|
||||
|
||||
DELETE FROM user WHERE user = 'horde' and host = '%';
|
||||
DELETE FROM tables_priv WHERE user = 'horde' and host = '%';
|
||||
|
||||
FLUSH PRIVILEGES;
|
16
root/usr/share/horde/smeserver/mysql_update_horde_privs.sql
Normal file
16
root/usr/share/horde/smeserver/mysql_update_horde_privs.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
CONNECT mysql;
|
||||
|
||||
REPLACE INTO db (host, db, user, select_priv, insert_priv, update_priv,
|
||||
delete_priv, create_priv, drop_priv, alter_priv, index_priv,
|
||||
references_priv)
|
||||
VALUES (
|
||||
'localhost',
|
||||
'horde',
|
||||
'horde',
|
||||
'Y', 'Y', 'Y', 'Y',
|
||||
'Y', 'Y', 'Y', 'Y',
|
||||
'Y'
|
||||
);
|
||||
|
||||
FLUSH PRIVILEGES;
|
||||
|
@@ -0,0 +1,169 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* This script migrates Nag's share data from the datatree Horde_Share
|
||||
* driver to the SQL Horde_Share driver.
|
||||
*/
|
||||
|
||||
$baseFile = __DIR__ . '/../../nag/lib/Application.php';
|
||||
if (file_exists($baseFile)) {
|
||||
require_once $baseFile;
|
||||
} else {
|
||||
require_once 'PEAR/Config.php';
|
||||
require_once PEAR_Config::singleton()
|
||||
->get('horde_dir', null, 'pear.horde.org') . '/nag/lib/Application.php';
|
||||
}
|
||||
Horde_Registry::appInit('nag', array('cli' => true));
|
||||
|
||||
$db = $injector->getInstance('Horde_Db_Adapter');
|
||||
|
||||
$error_cnt = 0;
|
||||
$delete_dt_data = true;
|
||||
|
||||
/**
|
||||
*** Remarked by John H. Bennett III <bennettj@johnbennettservices> for automated SME Server install
|
||||
$delete_dt_data = false;
|
||||
$answer = $cli->prompt('Do you want to keep your old datatree data or delete it?', array('Keep', 'Delete'));
|
||||
if ($answer == 1) {
|
||||
$delete_dt_data = true;
|
||||
}
|
||||
$answer = $cli->prompt(sprintf("Data will be copied into the new tables, and %s be deleted from the datatree.\n Is this what you want?", (($delete_dt_data) ? 'WILL' : 'WILL NOT')), array('y' => 'Yes', 'n' => 'No'));
|
||||
if ($answer != 'y') {
|
||||
exit;
|
||||
}
|
||||
*** End of remark
|
||||
*/
|
||||
|
||||
/* Get the share entries */
|
||||
try {
|
||||
$shares_result = $db->selectAssoc('SELECT datatree_id, datatree_name FROM horde_datatree WHERE group_uid = ' . $db->quoteString('horde.shares.nag'));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
exit;
|
||||
}
|
||||
$query = 'SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?';
|
||||
foreach ($shares_result as $share_id => $share_name) {
|
||||
$data = array('share_name' => $share_name);
|
||||
try {
|
||||
$rows = $db->select($query, array($share_id));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
exit;
|
||||
}
|
||||
$users = array();
|
||||
$groups = array();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if ($row['attribute_name'] == 'perm_groups') {
|
||||
/* Group table entry */
|
||||
$groups[] = array('group_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} elseif ($row['attribute_name'] == 'perm_users') {
|
||||
/* User table entry */
|
||||
$users[] = array('user_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} else {
|
||||
/* Everything else goes in the main share table */
|
||||
switch ($row['attribute_name']) {
|
||||
case 'perm_creator':
|
||||
case 'perm_default':
|
||||
case 'perm_guest':
|
||||
$data[$row['attribute_name']] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'owner':
|
||||
$data['share_owner'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'name':
|
||||
// Note the key to the $data array is not related to
|
||||
// the attribute_name field in the dt_attributes table.
|
||||
$data['attribute_name'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'desc':
|
||||
$data['attribute_desc'] = $row['attribute_value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set flags */
|
||||
$data['share_flags'] = 0;
|
||||
if (count($users)) {
|
||||
$data['share_flags'] |= 1;
|
||||
}
|
||||
if (count($groups)) {
|
||||
$data['share_flags'] |= 2;
|
||||
}
|
||||
|
||||
/* Insert the new data */
|
||||
$cli->message('Migrating share data for share_id: ' . $share_id, 'cli.message');
|
||||
$error = false;
|
||||
$db->beginDbTransaction();
|
||||
try {
|
||||
$nextId = insertData('nag_shares', $data, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
if (count($groups)) {
|
||||
foreach ($groups as $group) {
|
||||
$group['share_id'] = $nextId;
|
||||
try {
|
||||
insertData('nag_shares_groups', $group, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($users)) {
|
||||
foreach ($users as $user) {
|
||||
$user['share_id'] = $nextId;
|
||||
try {
|
||||
$result = insertData('nag_shares_users', $user, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($result->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the datatree data, but ONLY if it was requested */
|
||||
if ($delete_dt_data && !$error) {
|
||||
$cli->message('DELETING datatree data for share_id: ' . $share_id, 'cli.message');
|
||||
try {
|
||||
$db->delete('DELETE FROM horde_datatree_attributes WHERE datatree_id = ?', array($share_id));
|
||||
$db->delete('DELETE FROM horde_datatree WHERE datatree_id = ?', array($share_id));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
unset($row, $rows, $data, $groups, $users);
|
||||
if ($error) {
|
||||
$db->rollbackDbTransaction();
|
||||
$cli->message('Rollback for share data for share_id: ' . $share_id, 'cli.message');
|
||||
++$error_cnt;
|
||||
} else {
|
||||
$db->commitDbTransaction();
|
||||
$cli->message('Commit for share data for share_id: ' . $share_id, 'cli.message');
|
||||
}
|
||||
}
|
||||
if ($error_cnt) {
|
||||
$cli->message(sprintf("Encountered %u errors.", $error_cnt));
|
||||
}
|
||||
echo "\nDone.\n";
|
||||
|
||||
/**
|
||||
* Helper function
|
||||
*/
|
||||
function insertData($table, $data, $db)
|
||||
{
|
||||
$fields = array_keys($data);
|
||||
$values = array_values($data);
|
||||
$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (' . str_repeat('?, ', count($values) - 1) . '?)';
|
||||
return $db->insert($sql, $values);
|
||||
}
|
@@ -0,0 +1,168 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* This script migrates Turba's share data from the datatree Horde_Share
|
||||
* driver to the SQL Horde_Share driver.
|
||||
*/
|
||||
|
||||
if (file_exists(__DIR__ . '/../../turba/lib/Application.php')) {
|
||||
$baseDir = __DIR__ . '/../';
|
||||
} else {
|
||||
require_once 'PEAR/Config.php';
|
||||
$baseDir = PEAR_Config::singleton()
|
||||
->get('horde_dir', null, 'pear.horde.org') . '/turba/';
|
||||
}
|
||||
require_once $baseDir . 'lib/Application.php';
|
||||
Horde_Registry::appInit('turba', array('cli' => true));
|
||||
|
||||
$db = $injector->getInstance('Horde_Db_Adapter');
|
||||
|
||||
$error_cnt = 0;
|
||||
$delete_dt_data = true;
|
||||
|
||||
/**
|
||||
*** Remarked by John H. Bennett III <bennettj@johnbennettservices> for automated SME Server install
|
||||
$delete_dt_data = false;
|
||||
$answer = $cli->prompt('Do you want to keep your old datatree data or delete it?', array('Keep', 'Delete'));
|
||||
if ($answer == 1) {
|
||||
$delete_dt_data = true;
|
||||
}
|
||||
$answer = $cli->prompt(sprintf("Data will be copied into the new tables, and %s be deleted from the datatree.\n Is this what you want?", (($delete_dt_data) ? 'WILL' : 'WILL NOT')), array('y' => 'Yes', 'n' => 'No'));
|
||||
if ($answer != 'y') {
|
||||
exit;
|
||||
}
|
||||
*** End of remark
|
||||
*/
|
||||
|
||||
/* Get the share entries */
|
||||
try {
|
||||
$shares_result = $db->selectAssoc('SELECT datatree_id, datatree_name FROM horde_datatree WHERE group_uid = ' . $db->quoteString('horde.shares.turba'));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
$query = 'SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?';
|
||||
foreach ($shares_result as $share_id => $share_name) {
|
||||
$data = array('share_name' => $share_name);
|
||||
$rows = $db->selectAll($query, array($share_id));
|
||||
$users = array();
|
||||
$groups = array();
|
||||
foreach ($rows as $row) {
|
||||
if ($row['attribute_name'] == 'perm_groups') {
|
||||
/* Group table entry */
|
||||
$groups[] = array('group_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} elseif ($row['attribute_name'] == 'perm_users') {
|
||||
/* User table entry */
|
||||
$users[] = array('user_uid' => $row['attribute_key'],
|
||||
'perm' => $row['attribute_value']);
|
||||
} else {
|
||||
/* Everything else goes in the main share table */
|
||||
switch ($row['attribute_name']) {
|
||||
case 'perm_creator':
|
||||
case 'perm_default':
|
||||
case 'perm_guest':
|
||||
$data[$row['attribute_name']] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'owner':
|
||||
$data['share_owner'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'name':
|
||||
// Note the key to the $data array is not related to
|
||||
// the attribute_name field in the dt_attributes table.
|
||||
$data['attribute_name'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'desc':
|
||||
$data['attribute_desc'] = $row['attribute_value'];
|
||||
break;
|
||||
|
||||
case 'params':
|
||||
$data['attribute_params'] = $row['attribute_value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set flags */
|
||||
$data['share_flags'] = 0;
|
||||
if (count($users)) {
|
||||
$data['share_flags'] |= 1;
|
||||
}
|
||||
if (count($groups)) {
|
||||
$data['share_flags'] |= 2;
|
||||
}
|
||||
|
||||
/* Insert the new data */
|
||||
$cli->message('Migrating share data for share_id: ' . $share_id, 'cli.message');
|
||||
$error = false;
|
||||
$db->beginDbTransaction();
|
||||
try {
|
||||
$nextId = insertData('turba_shares', $data, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
if (count($groups)) {
|
||||
foreach ($groups as $group) {
|
||||
$group['share_id'] = $nextId;
|
||||
try {
|
||||
insertData('turba_shares_groups', $group, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($users)) {
|
||||
foreach ($users as $user) {
|
||||
$user['share_id'] = $nextId;
|
||||
try {
|
||||
insertData('turba_shares_users', $user, $db);
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the datatree data, but ONLY if it was requested */
|
||||
if ($delete_dt_data && !$error) {
|
||||
$cli->message('DELETING datatree data for share_id: ' . $share_id, 'cli.message');
|
||||
try {
|
||||
$db->delete('DELETE FROM horde_datatree_attributes WHERE datatree_id = ?', array($share_id));
|
||||
$db->delete('DELETE FROM horde_datatree WHERE datatree_id = ?', array($share_id));
|
||||
} catch (Horde_Db_Exception $e) {
|
||||
$cli->message($e->getMessage(), 'cli.error');
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
unset($row, $rows, $data, $groups, $users);
|
||||
if ($error) {
|
||||
$db->rollbackDbTransaction();
|
||||
$cli->message('Rollback for share data for share_id: ' . $share_id, 'cli.message');
|
||||
++$error_cnt;
|
||||
} else {
|
||||
$db->commitDbTransaction();
|
||||
$cli->message('Commit for share data for share_id: ' . $share_id, 'cli.message');
|
||||
}
|
||||
}
|
||||
if ($error_cnt) {
|
||||
$cli->message(sprintf("Encountered %u errors.", $error_cnt));
|
||||
}
|
||||
echo "\nDone.\n";
|
||||
|
||||
/**
|
||||
* Helper function
|
||||
*/
|
||||
function insertData($table, $data, $db)
|
||||
{
|
||||
$fields = array_keys($data);
|
||||
$values = array_values($data);
|
||||
$sql = 'INSERT INTO ' . $table . ' (' . implode(', ', $fields) . ') VALUES (' . str_repeat('?, ', count($values) - 1) . '?)';
|
||||
return $db->insert($sql, $values);
|
||||
}
|
57
root/usr/share/horde/smeserver/turba_create_objects.pl
Normal file
57
root/usr/share/horde/smeserver/turba_create_objects.pl
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/perl -w
|
||||
#----------------------------------------------------------------------
|
||||
# copyright (C) 2002-2005 Mitel Networks Corporation
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Technical support for this program is available from Mitel Networks
|
||||
# Please visit our web site www.mitel.com/sme/ for details.
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use DBI;
|
||||
use esmith::ConfigDB;
|
||||
use esmith::util;
|
||||
|
||||
# Exit early if there is nothing to do
|
||||
die("horde db must exist") unless ( -d "/var/lib/mysql/horde/");
|
||||
die("turba db must exist") unless ( -f "/var/lib/mysql/horde/turba_objects.frm");
|
||||
|
||||
my $conf = esmith::ConfigDB->open_ro
|
||||
or die "Can't open configuration database: $!\n";
|
||||
our $username = 'root';
|
||||
our $password = esmith::util::LdapPassword();
|
||||
our $TURBA_DATABASE = 'horde';
|
||||
our $dbi_options = {RaiseError => 1, ChopBlanks => 1, AutoCommit => 1};
|
||||
|
||||
my $db_turbahandle = DBI->connect
|
||||
("DBI:mysql:$TURBA_DATABASE",
|
||||
$username, $password, $dbi_options )
|
||||
|| die ("Connection error: $DBI::errstr");
|
||||
|
||||
my $sth = $db_turbahandle->prepare("show columns from turba_objects");
|
||||
$sth->execute;
|
||||
my $turba_objects = $sth->fetchall_hashref('Field');
|
||||
|
||||
|
||||
unless (defined $turba_objects->{object_children})
|
||||
{
|
||||
my $statement =
|
||||
"ALTER TABLE turba_objects ADD COLUMN object_children ".
|
||||
"VARCHAR(255)";
|
||||
$statement = $db_turbahandle->prepare($statement) or
|
||||
die "prepare: $$statement: $DBI::errstr";
|
||||
$statement->execute or die "execute: $$statement: $DBI::errstr";
|
||||
}
|
Reference in New Issue
Block a user