From 25cd9b49838cb6e3d2643b27ae1aa2a63a7a0e58 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 6 Mar 2020 09:50:53 +0000 Subject: provide tool to transform channels to zot6. WARNING: transformed channels will not yet be functional without additional patches. --- Zotlabs/Module/Z6trans.php | 200 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 Zotlabs/Module/Z6trans.php (limited to 'Zotlabs/Module/Z6trans.php') diff --git a/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php new file mode 100644 index 000000000..ac8c67c79 --- /dev/null +++ b/Zotlabs/Module/Z6trans.php @@ -0,0 +1,200 @@ + $cols) { + foreach($cols as $col) { + logger("Transforming $table - $col"); + q("UPDATE %s SET %s = replace(%s, '%s', '%s')", + dbesc($table), + dbesc($col), + dbesc($col), + dbesc($zot_xchan), + dbesc($zot6_xchan) + ); + } + logger("$table done."); + } + logger("Transformation completed."); + + + + } + + function get() { + if(!is_site_admin()) + return 'Not Allowed'; + + $path = 'store/z6upgrade.sql'; + + $r = q("SELECT channel.channel_name, channel.channel_hash, xchan.xchan_network FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE xchan.xchan_network = 'zot' AND channel.channel_removed = 0"); + + foreach($r as $rr) { + + $zot_xchan = $rr['channel_hash']; + + $r = q("SELECT xchan_guid FROM xchan WHERE xchan_hash = '%s' AND xchan_network = 'zot'", + dbesc($zot_xchan) + ); + + if(!$r) { + notice(t('Zot xchan not found. Aborting.') . EOL); + return; + } + + $guid = $r[0]['xchan_guid']; + $r = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", + dbesc($guid) + ); + + if(!$r) { + notice(t('No zot6 xchan found. Aborting.') . EOL); + return; + } + + $zot6_xchan = $r[0]['xchan_hash']; + $zot6_xchan_guid_sig = $r[0]['xchan_guid_sig']; + + //this should probably happen in a db_update during upgrading + $q .= sprintf("UPDATE channel SET channel_hash = '%s', channel_portable_id = '%s', channel_guid_sig = '%s' WHERE channel_hash = '%s';\r\n", + dbesc($zot6_xchan), + dbesc($zot_xchan), + dbesc($zot6_xchan_guid_sig), + dbesc($zot_xchan) + ); + + $core = self::get_core_cols(); + + foreach($core as $table => $cols) { + + foreach($cols as $col) { + + $q .= sprintf("UPDATE %s SET %s = replace(%s, '%s', '%s');\r\n", + dbesc($table), + dbesc($col), + dbesc($col), + dbesc($zot_xchan), + dbesc($zot6_xchan) + ); + + } + + } + + file_put_contents($path, $q); + + } + + + $o = '

' . t('Transform a single channel') . '

'; + $o .= '
'; + $o .= t('Enter zot xchan to transform: ') . '
'; + $o .= '
'; + $o .= '
'; + $o .= '


'; + + + $o .= '

' . t('To transform all channels') . '

'; + if(ACTIVE_DBTYPE == DBTYPE_MYSQL) + $o .= 'Run source ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the mysql console to complete the upgrade.'; + else + $o .= 'Run \i ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the postgresql console to complete the upgrade.'; + + return $o; + + } + + function get_core_cols() { + + $core = [ + 'abconfig' => ['xchan'], + 'abook' => ['abook_xchan'], + 'app' => ['app_author'], + 'attach' => ['creator', 'allow_cid', 'deny_cid'], + 'channel' => ['channel_allow_cid', 'channel_deny_cid'], + 'chat' => ['chat_xchan'], + 'chatpresence' => ['cp_xchan'], + 'chatroom' => ['allow_cid', 'deny_cid'], + 'config' => ['v'], + 'dreport' => ['dreport_recip', 'dreport_xchan'], + 'event' => ['event_xchan', 'allow_cid', 'deny_cid'], + 'iconfig' => ['v'], + 'item' => ['owner_xchan', 'author_xchan', 'source_xchan', 'route', 'allow_cid', 'deny_cid'], + 'mail' => ['from_xchan', 'to_xchan'], + 'menu_item' => ['allow_cid', 'deny_cid'], + 'obj' => ['allow_cid', 'deny_cid'], + 'pconfig' => ['v'], + 'pgrp_member' => ['xchan'], + 'photo' => ['xchan', 'allow_cid', 'deny_cid'], + 'source' => ['src_channel_xchan', 'src_xchan'], + 'updates' => ['ud_hash'], + 'xchat' => ['xchat_xchan'], + 'xconfig' => ['xchan', 'v'], + 'xign' => ['xchan'], + 'xlink' => ['xlink_xchan', 'xlink_link'], + 'xprof' => ['xprof_hash'], + 'xtag' => ['xtag_hash'], + ]; + + return $core; + + } + +} -- cgit v1.2.3 From 720d3dcedc96c7aaf6c4444c8b45acd46b8718b0 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 11 Mar 2020 10:34:25 +0000 Subject: z6trans preparation for db update 1236 --- Zotlabs/Module/Z6trans.php | 118 +++++++++------------------------------------ 1 file changed, 24 insertions(+), 94 deletions(-) (limited to 'Zotlabs/Module/Z6trans.php') diff --git a/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php index ac8c67c79..98832ad98 100644 --- a/Zotlabs/Module/Z6trans.php +++ b/Zotlabs/Module/Z6trans.php @@ -12,116 +12,50 @@ use Zotlabs\Web\Controller; class Z6trans extends Controller { - function post() { - if(!is_site_admin()) - return; - - $zot_xchan = trim($_POST['zot_xchan']); - - $r = q("SELECT xchan_guid FROM xchan WHERE xchan_hash = '%s' AND xchan_network = 'zot'", - dbesc($zot_xchan) - ); - - if(!$r) { - notice(t('Zot xchan not found. Aborting.') . EOL); - return; - } - - $guid = $r[0]['xchan_guid']; - $r = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", - dbesc($guid) - ); - - if(!$r) { - notice(t('No zot6 xchan found. Aborting.') . EOL); - return; - } - - $zot6_xchan = $r[0]['xchan_hash']; - $zot6_xchan_guid_sig = $r[0]['xchan_guid_sig']; - - - $r = q("SELECT * FROM channel WHERE channel_hash = '%s'", - dbesc($zot_xchan) - ); - - // We got everything we need - start transforming. - - if($r) { - logger("Transforming channel $zot_xchan"); - q("UPDATE channel SET channel_hash = '%s', channel_portable_id = '%s', channel_guid_sig = '%s' WHERE channel_hash = '%s'", - dbesc($zot6_xchan), - dbesc($zot_xchan), - dbesc($zot6_xchan_guid_sig), - dbesc($zot_xchan) - ); - } - - $core = self::get_core_cols(); - - foreach($core as $table => $cols) { - foreach($cols as $col) { - logger("Transforming $table - $col"); - q("UPDATE %s SET %s = replace(%s, '%s', '%s')", - dbesc($table), - dbesc($col), - dbesc($col), - dbesc($zot_xchan), - dbesc($zot6_xchan) - ); - } - logger("$table done."); - } - logger("Transformation completed."); - - - - } - function get() { if(!is_site_admin()) return 'Not Allowed'; - $path = 'store/z6upgrade.sql'; + $path = 'store/z6trans.sql'; - $r = q("SELECT channel.channel_name, channel.channel_hash, xchan.xchan_network FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE xchan.xchan_network = 'zot' AND channel.channel_removed = 0"); + $r = q("SELECT channel.channel_name, channel.channel_portable_id, xchan.xchan_network FROM channel + LEFT JOIN xchan ON channel_portable_id = xchan_hash + WHERE xchan.xchan_network = 'zot' + AND channel.channel_removed = 0" + ); + + $q = ''; foreach($r as $rr) { - $zot_xchan = $rr['channel_hash']; + $zot_xchan = $rr['channel_portable_id']; $r = q("SELECT xchan_guid FROM xchan WHERE xchan_hash = '%s' AND xchan_network = 'zot'", dbesc($zot_xchan) ); if(!$r) { - notice(t('Zot xchan not found. Aborting.') . EOL); - return; + $q .= '-- ' . $zot_xchan . 'failed: zot xchan not found' . "\r\n"; + continue; } $guid = $r[0]['xchan_guid']; + $r = q("SELECT xchan_hash, xchan_guid_sig FROM xchan WHERE xchan_guid = '%s' AND xchan_network = 'zot6'", dbesc($guid) ); if(!$r) { - notice(t('No zot6 xchan found. Aborting.') . EOL); - return; + $q .= '-- ' . $zot_xchan . 'failed: zot6 xchan not found' . "\r\n"; + continue; } $zot6_xchan = $r[0]['xchan_hash']; - $zot6_xchan_guid_sig = $r[0]['xchan_guid_sig']; - - //this should probably happen in a db_update during upgrading - $q .= sprintf("UPDATE channel SET channel_hash = '%s', channel_portable_id = '%s', channel_guid_sig = '%s' WHERE channel_hash = '%s';\r\n", - dbesc($zot6_xchan), - dbesc($zot_xchan), - dbesc($zot6_xchan_guid_sig), - dbesc($zot_xchan) - ); $core = self::get_core_cols(); + $q .= '-- Transforming ' . $rr['channel_name'] . "\r\n"; + foreach($core as $table => $cols) { foreach($cols as $col) { @@ -138,24 +72,20 @@ class Z6trans extends Controller { } - file_put_contents($path, $q); - } + if($q) + file_put_contents($path, $q); - $o = '

' . t('Transform a single channel') . '

'; - $o .= '
'; - $o .= t('Enter zot xchan to transform: ') . '
'; - $o .= '
'; - $o .= '
'; - $o .= '


'; - + $o = '

' . t('Update to Hubzilla 5.0 setp 2') . '


'; - $o .= '

' . t('To transform all channels') . '

'; + $o .= '

' . t('To complete the update please run') . '

'; if(ACTIVE_DBTYPE == DBTYPE_MYSQL) - $o .= 'Run source ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the mysql console to complete the upgrade.'; + $o .= 'source ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . '

from the mysql console.

'; else - $o .= 'Run \i ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . ' from the postgresql console to complete the upgrade.'; + $o .= '\i ' . $_SERVER["DOCUMENT_ROOT"] . '/' . $path . '

from the postgresql console.

'; + + $o .= '

' . t('INFO: this command can take a very long time depending on your DB size.') . '

'; return $o; -- cgit v1.2.3 From c0735a5ca20ea5612d475f50eb802cb1cd92cab5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 12 Jul 2020 19:16:37 -0700 Subject: z6trans: don't swap xprof xchans on directory servers because it will fail with duplicate primary key in many cases and the migration will fail on each channel. What this means is that directory servers may take time to pick up zot6 entries if they haven't received them prior to the upgrade. I don't see an easier solution unless we check for existence of the zot6 xchan_hash in the xprof table before converting it. --- Zotlabs/Module/Z6trans.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Module/Z6trans.php') diff --git a/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php index 98832ad98..58dc09a51 100644 --- a/Zotlabs/Module/Z6trans.php +++ b/Zotlabs/Module/Z6trans.php @@ -119,7 +119,7 @@ class Z6trans extends Controller { 'xconfig' => ['xchan', 'v'], 'xign' => ['xchan'], 'xlink' => ['xlink_xchan', 'xlink_link'], - 'xprof' => ['xprof_hash'], +// 'xprof' => ['xprof_hash'], 'xtag' => ['xtag_hash'], ]; -- cgit v1.2.3 From de306cd7b8e00dde34ae537f763b3dc3dc28fb00 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 17 Sep 2020 17:49:30 +0000 Subject: Missprint (cherry picked from commit b223b71d0d8c866da4c713d68459fccc7c269b03) --- Zotlabs/Module/Z6trans.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Module/Z6trans.php') diff --git a/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php index 58dc09a51..0caf096c9 100644 --- a/Zotlabs/Module/Z6trans.php +++ b/Zotlabs/Module/Z6trans.php @@ -77,7 +77,7 @@ class Z6trans extends Controller { if($q) file_put_contents($path, $q); - $o = '

' . t('Update to Hubzilla 5.0 setp 2') . '


'; + $o = '

' . t('Update to Hubzilla 5.0 step 2') . '


'; $o .= '

' . t('To complete the update please run') . '

'; if(ACTIVE_DBTYPE == DBTYPE_MYSQL) -- cgit v1.2.3 From d945789e1bcfd21530e7d1667b217e3596b447ce Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 17 Sep 2020 21:25:55 +0000 Subject: Boost DB conversion speed to Z6 (cherry picked from commit a9377d6a3f8156ed686f122f791a813caef2e93f) --- Zotlabs/Module/Z6trans.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Module/Z6trans.php') diff --git a/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php index 0caf096c9..31132bbe3 100644 --- a/Zotlabs/Module/Z6trans.php +++ b/Zotlabs/Module/Z6trans.php @@ -71,7 +71,25 @@ class Z6trans extends Controller { } } + + $zot = dbesc($zot_xchan); + $zot6 = dbesc($zot6_xchan); + + // Item table + foreach(['owner_xchan', 'author_xchan'] as $x) { + $q .= sprintf("UPDATE item SET $x = '%s' WHERE $x = '%s';\r\n", + $zot6, + $zot + ); + } + $q .= "UPDATE item SET source_xchan = replace(source_xchan, '$zot', '$zot6'), route = replace(route, '$zot', '$zot6'), allow_cid = replace(allow_cid, '$zot', '$zot6'), deny_cid = replace(deny_cid, '$zot', '$zot6');\r\n"; + + // photo table + $q .= "UPDATE photo SET xchan = replace(xchan, '$zot', '$zot6'), allow_cid = replace(allow_cid, '$zot', '$zot6'), deny_cid = replace(deny_cid, '$zot', '$zot6');\r\n"; + // dreport table + $q .= "UPDATE dreport SET dreport_recip = '$zot6' WHERE dreport_recip = '$zot';\r\n"; + $q .= "UPDATE dreport SET dreport_xchan = '$zot6' WHERE dreport_xchan = '$zot';\r\n"; } if($q) @@ -103,16 +121,16 @@ class Z6trans extends Controller { 'chatpresence' => ['cp_xchan'], 'chatroom' => ['allow_cid', 'deny_cid'], 'config' => ['v'], - 'dreport' => ['dreport_recip', 'dreport_xchan'], +// 'dreport' => ['dreport_recip', 'dreport_xchan'], 'event' => ['event_xchan', 'allow_cid', 'deny_cid'], 'iconfig' => ['v'], - 'item' => ['owner_xchan', 'author_xchan', 'source_xchan', 'route', 'allow_cid', 'deny_cid'], +// 'item' => ['owner_xchan', 'author_xchan', 'source_xchan', 'route', 'allow_cid', 'deny_cid'], 'mail' => ['from_xchan', 'to_xchan'], 'menu_item' => ['allow_cid', 'deny_cid'], 'obj' => ['allow_cid', 'deny_cid'], 'pconfig' => ['v'], 'pgrp_member' => ['xchan'], - 'photo' => ['xchan', 'allow_cid', 'deny_cid'], +// 'photo' => ['xchan', 'allow_cid', 'deny_cid'], 'source' => ['src_channel_xchan', 'src_xchan'], 'updates' => ['ud_hash'], 'xchat' => ['xchat_xchan'], -- cgit v1.2.3 From a86fd554a393a74f86a821756b8d02b34cb7cb20 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 20 Sep 2020 14:49:36 +0000 Subject: adapt mod z6trans to point to util/z6convert.php in case anyone stumbles over outdated doco. (cherry picked from commit c38fc0b9067382b91dcd26b4da9742fd9d650f6c) --- Zotlabs/Module/Z6trans.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Module/Z6trans.php') diff --git a/Zotlabs/Module/Z6trans.php b/Zotlabs/Module/Z6trans.php index 31132bbe3..72667316f 100644 --- a/Zotlabs/Module/Z6trans.php +++ b/Zotlabs/Module/Z6trans.php @@ -14,7 +14,19 @@ class Z6trans extends Controller { function get() { if(!is_site_admin()) - return 'Not Allowed'; + return '

Not Allowed

'; + + $o = '

' . t('Update to Hubzilla 5.0 step 2') . '


'; + + $o .= '

' . t('To complete the update please run') . '

'; + + $o .= '' . t('php util/z6convert.php') . ''; + + $o .= '

' . t('from the terminal.') . '

'; + + return $o; + +/* this code is outdated use util/z6convert.php instead $path = 'store/z6trans.sql'; @@ -106,6 +118,7 @@ class Z6trans extends Controller { $o .= '

' . t('INFO: this command can take a very long time depending on your DB size.') . '

'; return $o; +*/ } -- cgit v1.2.3