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') 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